Skip to content

Commit d2fba32

Browse files
Enhance release workflow with version extraction
1 parent 93dcca3 commit d2fba32

1 file changed

Lines changed: 52 additions & 7 deletions

File tree

.github/workflows/release-binaries.yml

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,57 @@ name: Build & Release Bangen
33
on:
44
workflow_dispatch:
55
push:
6-
tags:
7-
- "*.*.*"
6+
paths:
7+
- "pyproject.toml"
88

99
concurrency:
1010
group: release-${{ github.ref }}
1111
cancel-in-progress: true
1212

1313
jobs:
14+
tag:
15+
name: Extract version & create tag
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
outputs:
20+
version: ${{ steps.extract.outputs.version }}
21+
tag: ${{ steps.extract.outputs.tag }}
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Extract version from pyproject.toml
29+
id: extract
30+
run: |
31+
VERSION=$(python - <<'EOF'
32+
import tomllib
33+
with open("pyproject.toml", "rb") as f:
34+
print(tomllib.load(f)["project"]["version"])
35+
EOF
36+
)
37+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
38+
echo "tag=$VERSION" >> "$GITHUB_OUTPUT"
39+
40+
- name: Abort if tag already exists
41+
run: |
42+
if git rev-parse "refs/tags/${{ steps.extract.outputs.tag }}" &>/dev/null; then
43+
echo "Tag ${{ steps.extract.outputs.tag }} already exists — skipping release."
44+
exit 1
45+
fi
46+
47+
- name: Create and push tag
48+
run: |
49+
git config user.name "github-actions[bot]"
50+
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
git tag "${{ steps.extract.outputs.tag }}"
52+
git push origin "${{ steps.extract.outputs.tag }}"
53+
1454
build:
1555
name: Build (${{ matrix.name }})
56+
needs: tag
1657
runs-on: ${{ matrix.os }}
1758

1859
strategy:
@@ -65,6 +106,8 @@ jobs:
65106
66107
- name: Build with Nuitka
67108
shell: bash
109+
env:
110+
VERSION: ${{ needs.tag.outputs.version }}
68111
run: |
69112
printf 'from bangen.app import main\nif __name__ == "__main__":\n main()\n' > _entry.py
70113
python -m nuitka \
@@ -74,14 +117,16 @@ jobs:
74117
--output-filename=bangen \
75118
--nofollow-import-to=tkinter,unittest,test,distutils,setuptools,pkg_resources \
76119
--python-flag=no_asserts,no_docstrings,isolated \
77-
--onefile-tempdir-spec="{CACHE_DIR}/bangen/${{ github.ref_name }}" \
120+
--onefile-tempdir-spec="{CACHE_DIR}/bangen/$VERSION" \
78121
_entry.py
79122
80123
- name: Package artifact
81124
shell: bash
125+
env:
126+
VERSION: ${{ needs.tag.outputs.version }}
82127
run: |
83128
mkdir -p dist
84-
NAME="bangen-${{ matrix.name }}-${{ github.ref_name }}"
129+
NAME="bangen-${{ matrix.name }}-$VERSION"
85130
if [[ "$RUNNER_OS" == "Windows" ]]; then
86131
mv build/bangen.exe dist/"$NAME.exe"
87132
powershell -Command "Compress-Archive -Path dist\\$NAME.exe -DestinationPath dist\\$NAME.zip"
@@ -99,7 +144,7 @@ jobs:
99144

100145
release:
101146
name: Publish Release
102-
needs: build
147+
needs: [tag, build]
103148
runs-on: ubuntu-latest
104149
permissions:
105150
contents: write
@@ -117,6 +162,6 @@ jobs:
117162
118163
- uses: softprops/action-gh-release@v2
119164
with:
120-
tag_name: ${{ github.ref_name }}
121-
name: Bangen ${{ github.ref_name }}
165+
tag_name: ${{ needs.tag.outputs.tag }}
166+
name: Bangen ${{ needs.tag.outputs.version }}
122167
files: artifacts/*

0 commit comments

Comments
 (0)