Skip to content

Commit

Permalink
add major tag updater (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
figadore committed Feb 3, 2022
1 parent 1a33a46 commit 888a4a0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/UpdateFloatingTag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'Update major version tag'

on:
release:
types: [created, published]

jobs:
# updates the floating tag alias for the major version.
release:
runs-on: 'ubuntu-latest'
steps:
- name: Parse higher semantic versions
id: semver
shell: bash
run: |
TAG="${{ github.ref_name }}"
MINOR="${TAG%.*}"
MAJOR="${MINOR%.*}"
echo "::set-output name=major::$(echo $MAJOR)"
echo "::set-output name=minor::$(echo $MINOR)"
- name: 'Update major version tag'
uses: 'actions/github-script@v5'
with:
script: |-
const sha = '${{ github.sha }}'
const major = '${{ steps.semver.outputs.major }}';
// Try to update the ref first. If that fails, it probably does not
// exist yet, and we should create it.
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${major}`,
sha: sha,
force: true,
});
core.info(`Updated ${major} to ${sha}`);
} catch(err) {
core.warning(`Failed to create ${major}: ${err}`);
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${major}`,
sha: sha,
});
core.info(`Created ${major} at ${sha}`);
}

0 comments on commit 888a4a0

Please sign in to comment.