Skip to content

Commit

Permalink
Create semver-branches.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
jashan-lco authored Feb 12, 2025
1 parent 1888569 commit 50fae69
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/semver-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create SemVer Branches

on:
release:
types:
- published

permissions:
contents: write

jobs:
semver-branches:
name: Create SemVer Branches
runs-on: ubuntu-latest
if:
github.event_name == 'release' &&
startsWith(github.event.release.tag_name, 'v')

steps:
- name: Update semver major & minor branches
uses: actions/github-script@v7
with:
script: |-
const tagName = context.payload.release.tag_name;
if (!(new RegExp(/^v\d+[.]\d+[.]\d+$/)).test(tagName)) {
core.setFailed("Tag is not semver");
return
}
const [x, y, z] = tagName.slice(1).split(".");
for (const elm of [`${x}`, `${x}.${y}`]) {
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/heads/v${elm}`,
sha: context.sha,
});
} catch (error) {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/v${elm}`,
sha: context.sha,
force: true,
});
}
}

0 comments on commit 50fae69

Please sign in to comment.