-
Notifications
You must be signed in to change notification settings - Fork 9
65 lines (55 loc) · 1.81 KB
/
create-tag.yml
File metadata and controls
65 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Create Tag
on:
workflow_dispatch:
inputs:
version:
description: "Version to tag (e.g. 0.10.0). Leave empty to auto-bump minor."
required: false
type: string
permissions:
contents: write
jobs:
create-tag:
name: Create Tag
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Verify branch
run: |
if [ "${{ github.ref_name }}" != "main" ]; then
echo "::error::Tags can only be created from main. Current branch: ${{ github.ref_name }}"
exit 1
fi
- name: Determine version
id: version
run: |
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
# Strip leading 'v' if provided
VERSION="${VERSION#v}"
else
# Get latest tag, strip 'v' prefix, bump minor
LATEST=$(git tag --sort=-v:refname | head -1)
LATEST="${LATEST#v}"
MAJOR=$(echo "$LATEST" | cut -d. -f1)
MINOR=$(echo "$LATEST" | cut -d. -f2)
PATCH=$(echo "$LATEST" | cut -d. -f3)
MINOR=$((MINOR + 1))
VERSION="${MAJOR}.${MINOR}.0"
fi
TAG="v${VERSION}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "::error::Tag $TAG already exists"
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create and push tag
run: |
git tag "${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
- name: Summary
run: echo "### Created tag \`${{ steps.version.outputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY"