-
-
Notifications
You must be signed in to change notification settings - Fork 4
54 lines (47 loc) · 1.69 KB
/
auto-tag.yml
File metadata and controls
54 lines (47 loc) · 1.69 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
name: Auto-Tag on Release Merge
on:
pull_request:
types: [closed]
branches:
- master
- main
permissions:
contents: write
jobs:
create-tag:
# Only run when a release/* branch was actually merged (not just closed)
if: >
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
- name: Extract version from branch name
id: version
run: |
BRANCH="${{ github.event.pull_request.head.ref }}"
VERSION="${BRANCH#release/}"
VERSION="${VERSION#v}"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "TAG=v${VERSION}" >> "$GITHUB_OUTPUT"
echo "Detected version: $VERSION (tag: v${VERSION})"
- name: Check if tag already exists
id: check
run: |
if git rev-parse "refs/tags/${{ steps.version.outputs.TAG }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Tag ${{ steps.version.outputs.TAG }} already exists, skipping."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create and push tag
if: steps.check.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.TAG }}" -m "Release ${{ steps.version.outputs.VERSION }}"
git push origin "${{ steps.version.outputs.TAG }}"