Skip to content

Commit 32ea644

Browse files
committed
automate version tag creation
1 parent ae0069f commit 32ea644

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.github/workflows/version_tag.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Create version tag
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'pyproject.toml'
9+
10+
jobs:
11+
create-version-tag:
12+
name: Check version and create tag
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Extract version from pyproject.toml
23+
id: get_version
24+
run: |
25+
VERSION=$(grep -m 1 '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
26+
echo "version=$VERSION" >> $GITHUB_OUTPUT
27+
echo "Extracted version: $VERSION"
28+
29+
- name: Check if tag exists
30+
id: check_tag
31+
run: |
32+
if git rev-parse "${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
33+
echo "exists=true" >> $GITHUB_OUTPUT
34+
echo "Tag '${{ steps.get_version.outputs.version }}' already exists"
35+
else
36+
echo "exists=false" >> $GITHUB_OUTPUT
37+
echo "Tag '${{ steps.get_version.outputs.version }}' does not exist"
38+
fi
39+
40+
- name: Create and push tag
41+
if: steps.check_tag.outputs.exists == 'false'
42+
run: |
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
git tag -a "${{ steps.get_version.outputs.version }}"
46+
git push origin "${{ steps.get_version.outputs.version }}"

0 commit comments

Comments
 (0)