Skip to content

0.1.8

0.1.8 #11

# Automatically moves the major tag vX when vX.Y.Z is created
name: Update release tag
on:
push:
tags:
- v*
jobs:
update-release-tag:
runs-on: ubuntu-latest
steps:
- name: Get repo HEAD ref
id: new-tag
uses: actions/github-script@v6
with:
script: |
const parsed = context.ref.match(/^refs\/tags\/(?<minor>(?<major>v\d+)\.\d+)\.\d+$/)
if (!parsed) {
console.log(`Ignoring tag ${context.ref} - not a semver release tag.`);
return;
}
const response = await github.rest.git.getRef({
ref: `heads/${context.payload.repository.default_branch}`,
owner: context.repo.owner,
repo: context.repo.repo
});
const repoHeadSha = response.data.object.sha;
if (repoHeadSha !== context.sha) {
console.log(`Ignoring tag at ${context.sha}, because repo HEAD is at ${repoHeadSha}.`);
return;
}
console.log(`Parsed major: ${parsed.groups.major}`);
core.setOutput('major', parsed.groups.major);
console.log(`Parsed minor: ${parsed.groups.minor}`);
core.setOutput('minor', parsed.groups.minor);
- name: Move major tag ${{ steps.new-tag.outputs.major }}
if: ${{ steps.new-tag.outputs.major }}
uses: actions/github-script@v6
with:
script: |
try {
await github.rest.git.deleteRef({
ref: `tags/${{ steps.new-tag.outputs.major }}`,
owner: context.repo.owner,
repo: context.repo.repo
});
console.log(`Deleted tags/${{ steps.new-tag.outputs.major }}.`);
}
catch (e) {
console.log(`IGNORED ERROR: failed to delete tags/${{ steps.new-tag.outputs.major }} - assuming it never existed: ${e}`);
}
await github.rest.git.createRef({
ref: `refs/tags/${{ steps.new-tag.outputs.major }}`,
sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo
});
console.log(`Created tags/${{ steps.new-tag.outputs.major }} at ${context.sha}.`);
- name: Move minor tag ${{ steps.new-tag.outputs.minor }}
if: ${{ steps.new-tag.outputs.minor }}
uses: actions/github-script@v6
with:
script: |
try {
await github.rest.git.deleteRef({
ref: `tags/${{ steps.new-tag.outputs.minor }}`,
owner: context.repo.owner,
repo: context.repo.repo
});
}
catch (e) {
console.log(`IGNORED ERROR: failed to delete tags/${{ steps.new-tag.outputs.minor }} - assuming it never existed: ${e}`);
}
await github.rest.git.createRef({
ref: `refs/tags/${{ steps.new-tag.outputs.minor }}`,
sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo
});
console.log(`Created tags/${{ steps.new-tag.outputs.minor }} at ${context.sha}.`);