Skip to content

Commit

Permalink
Add workflow to update tag pointer (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Dec 9, 2021
1 parent ccc7806 commit 5090ecb
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 'tag'

on:
push:
tags:
# match vx.y and v x.y.z.w... but not vx
- 'v[0-9]+.*'

jobs:
# pointer parses the incoming tag value and updates the "vX" pointer to the
# same SHA as this tag.
pointer:
name: 'pointer'
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/github-script@v5'
with:
script: |-
const tag = process.env.GITHUB_REF_NAME;
if(!tag) {
core.setFailed(`Missing tag!`)
return
}
core.info(`Using tag "${tag}"`)
const matches = tag.match(/(v[0-9]+).*/)
if(!matches || matches.length < 2) {
core.setFailed(`Invalid tag "${tag}"`)
return
}
const major = matches[1];
core.info(`Matched to major tag "${major}"`)
// Try to update the ref first. If that fails, it probably does not
// exist yet, and we should create it.
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${major}`,
sha: context.sha,
force: true,
})
core.info(`Updated "${major}" to "${tag}" (${context.sha})`)
} catch {
core.warning(`Failed to update "${major}" tag (it may not `+
`exist). Trying to create "${major}" now.`)
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${major}`,
sha: context.sha,
})
core.info(`Created "${major}" at "${tag}" (${context.sha})`)
}

0 comments on commit 5090ecb

Please sign in to comment.