-
-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (42 loc) · 1.44 KB
/
release.yml
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
name: Release on Version Change
on:
push:
branches:
- main
workflow_dispatch: # Allows manual triggering of the workflow
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-tags: true
- name: Install Hatch
uses: pypa/hatch@install
- name: Extract current version
run: |
version=$(hatch version)
echo "version=$version" >> $GITHUB_ENV
- name: Get latest tag
run: |
latest_tag=$(git describe --tags --abbrev=0 || echo "0.0.0")
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
- name: Compare versions
run: |
if [ "${{ env.version }}" != "${{ env.latest_tag }}" ]; then
echo "new_version=true" >> $GITHUB_ENV
else
echo "new_version=false" >> $GITHUB_ENV
fi
- name: Create a new tag and release
if: env.new_version == 'true'
env:
VERSION: ${{ env.version }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
gh release create "$VERSION" --title "Release $VERSION" --notes "Automated release for version $VERSION"