Skip to content

Commit a66652c

Browse files
authored
chore: Replace broken actions-tagger with github-script for version tagging (#881)
## Summary Replace the broken `Actions-R-Us/actions-tagger` action (pinned commit no longer has `lib/index.js`) with `actions/github-script@v8` calling an external script that updates major version tags and the `latest` tag on release.
1 parent 60c6761 commit a66652c

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// @ts-check
2+
3+
/** @param {import('@actions/github-script').AsyncFunctionArguments} args */
4+
export default async function updateMajorTag({ github, context }) {
5+
const tag = context.payload.release?.tag_name;
6+
if (!tag) {
7+
throw new Error("No release tag found in event payload");
8+
}
9+
10+
const match = tag.match(/^(v\d+)\.\d+\.\d+/);
11+
if (!match) {
12+
throw new Error(`Tag "${tag}" does not match semver pattern vX.Y.Z`);
13+
}
14+
15+
const majorTag = match[1];
16+
const sha = context.sha;
17+
18+
const tagsToUpdate = [majorTag, "latest"];
19+
20+
for (const tagName of tagsToUpdate) {
21+
const ref = `tags/${tagName}`;
22+
try {
23+
await github.rest.git.updateRef({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
ref,
27+
sha,
28+
force: true,
29+
});
30+
console.log(`Updated ${ref} to ${sha}`);
31+
} catch (error) {
32+
if (error?.status === 404 || error?.status === 422) {
33+
await github.rest.git.createRef({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
ref: `refs/${ref}`,
37+
sha,
38+
});
39+
console.log(`Created ${ref} at ${sha}`);
40+
} else {
41+
throw error;
42+
}
43+
}
44+
}
45+
}

.github/workflows/versioning.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ jobs:
1111
actions-tagger:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: Actions-R-Us/actions-tagger@148653c6179832f8392d083de6b46ad3dcc54de3
14+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
15+
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
1516
with:
16-
publish_latest_tag: true
17-
token: ${{ secrets.GITHUB_TOKEN }}
17+
script: |
18+
const { default: updateMajorTag } = await import('${{ github.workspace }}/.github/scripts/update-major-tag.js');
19+
await updateMajorTag({ github, context });

0 commit comments

Comments
 (0)