Skip to content

Commit c8363ee

Browse files
authored
Auto-tag commits on master (#192)
1 parent cb11860 commit c8363ee

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/tag-release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tag patch release
2+
3+
on:
4+
push:
5+
branches:
6+
- master # Adjust to match the name of your main branch
7+
paths-ignore:
8+
- .github/**
9+
- README.md
10+
- LICENSE
11+
12+
jobs:
13+
tag:
14+
runs-on: ubuntu-latest
15+
steps:
16+
# Checkout the repository
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Important to fetch all tags and history
21+
22+
# Determine the new version number
23+
- name: Get latest tag and increment
24+
id: versioning
25+
run: |
26+
# Fetch all tags
27+
git fetch --tags
28+
29+
# Get the highest tag number, and add 1 to the patch
30+
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
31+
echo "Current highest tag is $TAG"
32+
33+
# Increment the patch version
34+
NEW_TAG="${TAG%.*}.$((${TAG##*.}+1))"
35+
echo "New tag will be $NEW_TAG"
36+
37+
# Set NEW_TAG as an output variable
38+
echo "NEW_VERSION=$NEW_TAG" >> $GITHUB_ENV
39+
40+
# Create a new tag
41+
- name: Create Git tag for PR
42+
uses: actions/github-script@v7
43+
with:
44+
script: |
45+
github.rest.git.createRef({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
ref: "refs/tags/${{env.NEW_VERSION}}",
49+
sha: context.sha
50+
})

0 commit comments

Comments
 (0)