Skip to content

Commit

Permalink
+semver:breaking
Browse files Browse the repository at this point in the history
ARCH-1911 - Transfer to Infra-Purple

- Remove deprecated create-ref input & associated github-token input
- Update CODEOWNERS
- Add tests to build-and-review-pr.yml
  • Loading branch information
danielle-casella-adams committed Sep 21, 2023
1 parent 8ddd14b commit fc7ec48
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @im-open/swat
* @im-open/infra-purple
37 changes: 37 additions & 0 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:
- name: The next action version will be - ${{ steps.version.outputs.NEXT_VERSION || 'N/A'}}
if: steps.source-code.outputs.HAS_CHANGES == 'true'
run: echo "The next action version will be - ${{ steps.version.outputs.NEXT_VERSION }}"

- run: echo "payload sha - ${{github.event.pull_request.head.sha}}"
- run: echo "sha - ${{github.sha}}"

build-and-review-pr:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -201,3 +204,37 @@ jobs:
.addRaw(instructionsWithLinks)
.write();
core.setFailed(instructions);
test:
runs-on: ubuntu-latest

env:
PRODUCTION_READY_TAG: 'v1.1.3'
PRE_RELEASE_TAG: 'v1.0.2'
DRAFT_RELEASE_TAG: 'v1.0.1'
NONEXISTENT_RELEASE_TAG: 'v304.973.444'

steps:
- uses: actions/checkout@v3

#--------------------------------------
# RELEASE IS PRODUCTION READY RELEASE
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When validating a prod ready release (${{ env.PRODUCTION_READY_TAG}})
uses: ./
if: always()
id: production-release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-tag: ${{ env.PRODUCTION_READY_TAG }}
fail-for-prerelease: false

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.production-release.outcome }}"

- name: And the output should be true
if: always()
run: ./test/assert-values-match.sh --name "PRODUCTION_READY" --expected "true" --actual "${{ steps.production-release.outputs.PRODUCTION_READY }}"
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ This template can be used to calculate a release or pre-release version.
- [Pre-requisites](#pre-requisites)
- [Release vs Pre-release](#release-vs-pre-release)
- [Incrementing Strategy](#incrementing-strategy)
- [Creating a Ref](#creating-a-ref)
- [Inputs](#inputs)
- [Outputs](#outputs)
- [Usage Examples](#usage-examples)
Expand Down Expand Up @@ -55,10 +54,6 @@ The action will increment the minor version if it identifies any of the followin

If none of the previous patterns match, the action will increment the patch version.

## Creating a Ref

The action has a `create-ref` flag and when set to true it uses the GitHub rest API to [create a ref]. This API call results in a release and a tag being created. This may be desirable in some workflows where you are incrementing on merge but may not work well for others like a CI build where you want to hold off pushing the ref until some steps have completed.

## Inputs

| Parameter | Is Required | Default | Description |
Expand All @@ -67,8 +62,6 @@ The action has a `create-ref` flag and when set to true it uses the GitHub rest
| `fallback-to-no-prefix-search` | false | `true` | Flag indicating whether it should fallback to a prefix-less search if no tags are found with the current prefix. Helpful when starting to use prefixes with tags. Accepted values: true\|false. |
| `calculate-prerelease-version` | false | `false` | Flag indicating whether to calculate a pre-release version rather than a release version. Accepts: `true\|false`. |
| `branch-name` | Required when<br/>`calculate-prerelease-version: true` | N/A | The name of the branch the next pre-release version is being generated for. Required when calculating the pre-release version. |
| `create-ref` | false | `false` | Flag indicating whether the action should [create a ref] (a release and tag) on the repository. Accepted values: `true\|false`. |
| `github-token` | Required when<br/>`create-ref: true` | N/A | Token with permissions to create a ref on the repository. |
| `default-release-type` | false | `major` | The default release type that should be used when no tags are detected. Defaults to major. Accepted values: `major\|minor\|patch`. |

## Outputs
Expand Down Expand Up @@ -107,16 +100,14 @@ jobs:

- id: get-version
# You may also reference just the major version.
uses: im-open/git-version-lite@v2.3.2
uses: im-open/git-version-lite@v3.0.0
with:
calculate-prerelease-version: true
branch-name: ${{ github.head_ref }} # github.head_ref works when the trigger is pull_request
tag-prefix: v # Prepend a v to any calculated release/pre-release version
fallback-to-no-prefix-search: true # Set to true can be helpful when starting to add tag prefixes
default-release-type: major # If no tags are found, default to doing a major increment
create-ref: true # Will create a release/tag on the repo
github-token: ${{ secrets.GITHUB_TOKEN }} # Required when creating a ref


- run: |
echo "The next version is ${{ env.NEXT_VERSION }}"
echo "The next version without the prefix is ${{ steps.get-version.outputs.NEXT_VERSION_NO_PREFIX }}"
Expand Down
10 changes: 0 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ inputs:
description: 'The default release type that should be used when no tags are detected. Defaults to major. Accepted values: major|minor|patch'
required: true
default: 'major'

# Deprecated input. Instead create a release with the im-open/create-release action
create-ref:
description: 'Flag indicating whether the action should create a ref (a release and tag) on the repository. Accepted values: true|false'
required: true
default: 'false'

github-token:
description: Token with permissions to push a ref to the repository
required: false

outputs:
NEXT_VERSION:
Expand Down
22 changes: 0 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19886,27 +19886,8 @@ var requiredArgOptions = {
};
var calculatePrereleaseVersion = core.getBooleanInput('calculate-prerelease-version');
var defaultReleaseType = core.getInput('default-release-type', requiredArgOptions).toLowerCase();
var createRef = core.getBooleanInput('create-ref');
var fallbackToNoPrefixSearch = core.getBooleanInput('fallback-to-no-prefix-search');
var tagPrefix = core.getInput('tag-prefix');
async function createRefOnGitHub(versionToBuild, sha) {
core.info('Creating the ref on GitHub...');
const token = core.getInput('github-token', requiredArgOptions);
const octokit = github.getOctokit(token);
await octokit.rest.git
.createRef({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
ref: `refs/tags/${versionToBuild}`,
sha
})
.then(() => {
core.info('Finished creating the ref on GitHub.');
})
.catch(error => {
core.setFailed(`An error occurred creating the ref on GitHub: ${error.message}`);
});
}
async function run() {
try {
const expectedReleaseTypes = ['major', 'minor', 'patch'];
Expand Down Expand Up @@ -19938,9 +19919,6 @@ async function run() {
? github.context.payload.pull_request.head.sha
: github.context.sha;
const { nextVersion, priorVersion } = versionToBuild;
if (createRef) {
await createRefOnGitHub(`${tagPrefix}${nextVersion.toString()}`, sha);
}
const outputVersionEntries = Object.entries({
NEXT_VERSION: nextVersion.toString(),
NEXT_MINOR_VERSION: `${nextVersion.major}.${nextVersion.minor}`,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"semver": "^7.5.2"
"semver": "^7.3.5"
},
"devDependencies": {
"esbuild": "^0.12.8",
Expand Down
29 changes: 1 addition & 28 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,9 @@ const requiredArgOptions = {

const calculatePrereleaseVersion = core.getBooleanInput('calculate-prerelease-version');
const defaultReleaseType = core.getInput('default-release-type', requiredArgOptions).toLowerCase();
const createRef = core.getBooleanInput('create-ref');
const fallbackToNoPrefixSearch = core.getBooleanInput('fallback-to-no-prefix-search');
let tagPrefix = core.getInput('tag-prefix');

async function createRefOnGitHub(versionToBuild, sha) {
core.info('Creating the ref on GitHub...');

// This arg is only required when creating a ref, so get the input here.
const token = core.getInput('github-token', requiredArgOptions);
const octokit = github.getOctokit(token);

await octokit.rest.git
.createRef({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
ref: `refs/tags/${versionToBuild}`,
sha
})
.then(() => {
core.info('Finished creating the ref on GitHub.');
})
.catch(error => {
core.setFailed(`An error occurred creating the ref on GitHub: ${error.message}`);
});
}
const branchName = core.getInput('branch-name', requiredArgOptions);

async function run() {
try {
Expand All @@ -54,7 +32,6 @@ async function run() {

let versionToBuild;
if (calculatePrereleaseVersion) {
const branchName = core.getInput('branch-name', requiredArgOptions);
core.info(`Calculating a pre-release version for ${branchName}...`);

//This regex will strip out anything that's not a-z, 0-9 or the - character
Expand All @@ -78,10 +55,6 @@ async function run() {

const { nextVersion, priorVersion } = versionToBuild;

if (createRef) {
await createRefOnGitHub(`${tagPrefix}${nextVersion.toString()}`, sha);
}

const outputVersionEntries = Object.entries({
NEXT_VERSION: nextVersion.toString(),
NEXT_MINOR_VERSION: `${nextVersion.major}.${nextVersion.minor}`,
Expand Down
37 changes: 37 additions & 0 deletions test/assert-values-match.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

name=''
expectedValue=''
actualValue=''

for arg in "$@"; do
case $arg in
--name)
name=$2
shift # Remove argument --name from `$@`
shift # Remove argument value from `$@`
;;
--expected)
expectedValue=$2
shift # Remove argument --expected from `$@`
shift # Remove argument value from `$@`
;;
--actual)
actualValue=$2
shift # Remove argument --actual from `$@`
shift # Remove argument value from `$@`
;;

esac
done

echo "
Expected $name: '$expectedValue'"
echo "Actual $name: '$actualValue'"

if [ "$expectedValue" != "$actualValue" ]; then
echo "The expected $name does not match the actual $name."
exit 1
else
echo "The expected and actual $name values match."
fi

0 comments on commit fc7ec48

Please sign in to comment.