Merge pull request #153 from JupiterOne/SRE-1276_promote_docker_image… #140
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: | |
- main | |
tags-ignore: | |
- '**' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
persist-credentials: true | |
fetch-depth: 0 | |
token: ${{ secrets.AUTO_GITHUB_PAT_TOKEN }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18.15.0 | |
cache: 'npm' | |
registry-url: 'https://registry.npmjs.org' | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
- name: pr_labels | |
id: pr_labels | |
uses: joerick/[email protected] | |
- name: package_json | |
id: package_json | |
run: | | |
echo "version=$(jq -r .version < package.json)" >> $GITHUB_OUTPUT | |
- name: semver_versions | |
id: semver_versions | |
uses: "WyriHaximus/github-action-next-semvers@v1" | |
with: | |
version: ${{ steps.package_json.outputs.version }} | |
- name: patch_version | |
run: | | |
echo "NEW_VERSION=${{ steps.semver_versions.outputs.patch }}" >> $GITHUB_ENV | |
- name: minor_version | |
if: contains(steps.pr_labels.outputs.labels, 'minor') | |
run: | | |
echo "NEW_VERSION=${{ steps.semver_versions.outputs.minor }}" >> $GITHUB_ENV | |
# Parse the major version so we can extract only the major part of the semver (1 from 1.0.0) | |
- name: new_semver_parser | |
id: new_semver_parser | |
if: contains(steps.pr_labels.outputs.labels, 'major') | |
uses: booxmedialtd/ws-action-parse-semver@v1 | |
with: | |
input_string: ${{ steps.semver_versions.outputs.major }} | |
- name: major_version | |
if: contains(steps.pr_labels.outputs.labels, 'major') | |
run: | | |
echo "NEW_VERSION=${{ steps.new_semver_parser.outputs.major }}" >> $GITHUB_ENV | |
- name: echo_version_info | |
run: | | |
echo "current version is ${{ steps.package_json.outputs.version }}" | |
echo "new version will be ${{ env.NEW_VERSION }}" | |
- name: update_composite_tags | |
run: | | |
npm run update-composite-tags ${{ env.NEW_VERSION }} | |
- name: update_package_json_version | |
run: | | |
echo "`jq '.version="${{ env.NEW_VERSION }}"' package.json`" > package.json | |
- name: commit_updates | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Automation" | |
git add . | |
git commit -m "Updating composite tags and package.json version for v${{ env.NEW_VERSION }} [skip ci]" | |
- name: new_tags | |
run: | | |
git tag -a v${{ env.NEW_VERSION }} -m "New tag for ${{ env.NEW_VERSION }}" | |
git push --follow-tags --set-upstream origin main | |
# Parse the current version so we can extract only the major part of the semver (1 from 1.0.0) | |
- name: current_semver_parser | |
id: current_semver_parser | |
uses: booxmedialtd/ws-action-parse-semver@v1 | |
with: | |
input_string: ${{ steps.package_json.outputs.version }} | |
# We reset the major tag so workflow consumers automatically receive these changes | |
- name: reset_major_tag | |
if: ${{ env.NEW_VERSION != steps.current_semver_parser.outputs.major }} | |
run: | | |
echo "Major tag v${{ steps.current_semver_parser.outputs.major }} is being reset to the latest" | |
git tag -af v${{ steps.current_semver_parser.outputs.major }} -m "Resetting v${{ steps.current_semver_parser.outputs.major }} tag" | |
git push origin v${{ steps.current_semver_parser.outputs.major }} --force | |