Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/scripts/update-major-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @ts-check

/** @param {import('@actions/github-script').AsyncFunctionArguments} args */
export default async function updateMajorTag({ github, context }) {
const tag = context.payload.release?.tag_name;
if (!tag) {
throw new Error("No release tag found in event payload");
}

const match = tag.match(/^(v\d+)\.\d+\.\d+/);
if (!match) {
throw new Error(`Tag "${tag}" does not match semver pattern vX.Y.Z`);
}

const majorTag = match[1];
const sha = context.sha;

const tagsToUpdate = [majorTag, "latest"];

for (const tagName of tagsToUpdate) {
const ref = `tags/${tagName}`;
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
sha,
force: true,
});
console.log(`Updated ${ref} to ${sha}`);
} catch (error) {
if (error?.status === 404 || error?.status === 422) {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/${ref}`,
sha,
});
console.log(`Created ${ref} at ${sha}`);
} else {
throw error;
}
}
}
}
8 changes: 5 additions & 3 deletions .github/workflows/versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ jobs:
actions-tagger:
runs-on: ubuntu-latest
steps:
- uses: Actions-R-Us/actions-tagger@148653c6179832f8392d083de6b46ad3dcc54de3
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
publish_latest_tag: true
token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { default: updateMajorTag } = await import('${{ github.workspace }}/.github/scripts/update-major-tag.js');
await updateMajorTag({ github, context });
Loading