Skip to content

Commit 9f845d6

Browse files
committed
feat: add new release workflow
1 parent 87bdc34 commit 9f845d6

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# .github/workflows/release-dispatch.yml
2+
name: Release (manual, from pyproject)
3+
4+
on:
5+
workflow_dispatch: {}
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write # needed to push tags & create releases
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # required to create/push tags
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Read version from pyproject.toml
24+
id: version
25+
shell: bash
26+
run: |
27+
python - <<'PY'
28+
import sys, pathlib
29+
try:
30+
import tomllib # Python 3.11+
31+
except Exception:
32+
print("::error::tomllib not available; require Python 3.11+")
33+
sys.exit(1)
34+
35+
p = pathlib.Path("pyproject.toml")
36+
if not p.exists():
37+
print("::error::pyproject.toml not found")
38+
sys.exit(1)
39+
40+
data = tomllib.loads(p.read_text())
41+
version = None
42+
43+
# PEP 621
44+
project = data.get("project") or {}
45+
version = project.get("version")
46+
47+
# Poetry fallback
48+
if not version:
49+
tool = data.get("tool") or {}
50+
poetry = tool.get("poetry") or {}
51+
version = poetry.get("version")
52+
53+
if not version:
54+
print("::error::Version not found in pyproject.toml (project.version or tool.poetry.version).")
55+
sys.exit(1)
56+
57+
with open("$GITHUB_OUTPUT", "a") as fh:
58+
fh.write(f"value={version}\n")
59+
PY
60+
echo "Detected version: ${{ steps.version.outputs.value }}"
61+
62+
- name: Create and push tag
63+
env:
64+
VERSION: ${{ steps.version.outputs.value }}
65+
shell: bash
66+
run: |
67+
set -euo pipefail
68+
TAG="v${VERSION}"
69+
70+
# Fail if tag already exists remote or locally
71+
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
72+
echo "::error::Tag $TAG already exists locally."; exit 1
73+
fi
74+
if git ls-remote --exit-code --tags origin "$TAG" >/dev/null 2>&1; then
75+
echo "::error::Tag $TAG already exists on origin."; exit 1
76+
fi
77+
78+
# Configure bot identity
79+
git config user.name "github-actions[bot]"
80+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
81+
82+
# Tag current HEAD of the checked-out branch
83+
git tag -a "$TAG" -m "$TAG"
84+
git push origin "$TAG"
85+
86+
# ---- Optional: build Python artifacts (wheel/sdist) and attach to release
87+
# - name: Build package
88+
# run: |
89+
# python -m pip install --upgrade pip
90+
# python -m pip install build
91+
# python -m build
92+
#
93+
- name: Create GitHub Release
94+
uses: softprops/action-gh-release@v2
95+
with:
96+
tag_name: v${{ steps.version.outputs.value }}
97+
generate_release_notes: true
98+
# files: |
99+
# dist/*.whl
100+
# dist/*.tar.gz
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)