Skip to content

Commit 71ee615

Browse files
committed
Add CI workflow to cut semver release tags
1 parent afe684a commit 71ee615

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Cut Release Tag
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: SemVer bump type
8+
required: true
9+
default: patch
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
cut-tag:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Compute next version tag
30+
id: next_tag
31+
shell: bash
32+
run: |
33+
set -euo pipefail
34+
35+
LATEST_TAG="$(git tag --list 'v*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true)"
36+
if [[ -z "${LATEST_TAG}" ]]; then
37+
LATEST_TAG="v0.0.0"
38+
fi
39+
40+
VERSION="${LATEST_TAG#v}"
41+
IFS='.' read -r MAJOR MINOR PATCH <<<"${VERSION}"
42+
43+
BUMP="${{ github.event.inputs.bump }}"
44+
case "${BUMP}" in
45+
patch)
46+
PATCH=$((PATCH + 1))
47+
;;
48+
minor)
49+
MINOR=$((MINOR + 1))
50+
PATCH=0
51+
;;
52+
major)
53+
MAJOR=$((MAJOR + 1))
54+
MINOR=0
55+
PATCH=0
56+
;;
57+
*)
58+
echo "Unsupported bump type: ${BUMP}"
59+
exit 1
60+
;;
61+
esac
62+
63+
NEXT_TAG="v${MAJOR}.${MINOR}.${PATCH}"
64+
if git rev-parse "${NEXT_TAG}" >/dev/null 2>&1; then
65+
echo "Tag ${NEXT_TAG} already exists."
66+
exit 1
67+
fi
68+
69+
echo "latest_tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT"
70+
echo "tag=${NEXT_TAG}" >> "$GITHUB_OUTPUT"
71+
72+
- name: Create and push tag
73+
shell: bash
74+
run: |
75+
set -euo pipefail
76+
NEXT_TAG="${{ steps.next_tag.outputs.tag }}"
77+
git config user.name "github-actions[bot]"
78+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
79+
git tag -a "${NEXT_TAG}" -m "Release ${NEXT_TAG}"
80+
git push origin "${NEXT_TAG}"
81+
82+
- name: Summary
83+
run: |
84+
echo "Created tag: ${{ steps.next_tag.outputs.tag }}"
85+
echo "Previous tag: ${{ steps.next_tag.outputs.latest_tag }}"

0 commit comments

Comments
 (0)