v0.1.0 #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}); | |
} | |
} |