Skip to content

Commit 3d92945

Browse files
committed
Add AutoTag workflow for automatic version tagging
1 parent b216f95 commit 3d92945

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

.github/workflows/AutoTag.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: AutoTag
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- 'Project.toml'
8+
jobs:
9+
tag:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 2
15+
- name: Check version change and tag
16+
run: |
17+
VERSION=$(grep '^version' Project.toml | sed 's/version = "\(.*\)"/\1/')
18+
TAG="v$VERSION"
19+
20+
if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then
21+
echo "Tag $TAG already exists, skipping"
22+
exit 0
23+
fi
24+
25+
git show HEAD^:Project.toml > /tmp/old_project.toml 2>/dev/null || echo 'version = "0.0.0"' > /tmp/old_project.toml
26+
OLD_VERSION=$(grep '^version' /tmp/old_project.toml | sed 's/version = "\(.*\)"/\1/')
27+
28+
if [ "$VERSION" != "$OLD_VERSION" ]; then
29+
echo "Version changed from $OLD_VERSION to $VERSION, creating tag $TAG"
30+
git config user.name "github-actions[bot]"
31+
git config user.email "github-actions[bot]@users.noreply.github.com"
32+
git tag "$TAG"
33+
git push origin "$TAG"
34+
else
35+
echo "Version unchanged ($VERSION), skipping"
36+
fi

0 commit comments

Comments
 (0)