Skip to content

Commit

Permalink
Add a workflow to auto-increment the tag (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym-stripe authored Jun 6, 2022
1 parent 65fdafc commit 59d682c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create Tag and trigger release
on:
workflow_dispatch:
inputs:
tag:
description: "Tag name, defaults to minor increment."
required: false
sha:
description: "Commit SHA to tag. Defaults to latest."
required: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Set the commit SHA
id: sha
run: echo "::set-output name=commitSha::$(if [ -z "$SHA" ]; then echo $GITHUB_SHA; else echo $SHA; fi)"
env:
SHA: ${{ github.event.inputs.sha }}
- name: Set the tag
id: tag
run: |
last_tag="$(git describe --tags --abbrev=0)"
# Parse the version into parts, increment the minor version and reset the patch to 0
# Example:
# v1.2.3 is parsed into $1 = "v1.", $2 = "2", $3 = ".3"
# and concatenated back into v1.3.0
new_tag="$(echo "$last_tag" | perl -pe 's/^(v\d+\.)(\d+)(\.\d+)$/$1.($2+1).".0"/e')"
echo "::set-output name=newTag::$(if [ -z "$TAG" ]; then echo $new_tag; else echo $TAG; fi)"
env:
TAG: ${{ github.event.inputs.tag }}
- name: Create tag
uses: actions/github-script@v5
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.tag.outputs.newTag }}',
sha: '${{ steps.sha.outputs.commitSha }}'
})

0 comments on commit 59d682c

Please sign in to comment.