Skip to content

Commit f1586d4

Browse files
release workflow.
1 parent c30e882 commit f1586d4

2 files changed

Lines changed: 90 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
test:
11+
uses: ./.github/workflows/tests.yml
12+
13+
build_package:
14+
runs-on: ubuntu-latest
15+
needs: test
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
22+
with:
23+
python-version: '3.13'
24+
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
27+
28+
- name: Check tag matches version files
29+
run: |
30+
TAG_VERSION="${GITHUB_REF##*/}"
31+
TAG_VERSION_NO_PREFIX="${TAG_VERSION#v}"
32+
echo "Tag version: $TAG_VERSION (stripped: $TAG_VERSION_NO_PREFIX)"
33+
34+
PYPROJECT_VERSION=$(grep '^version =' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
35+
echo "pyproject.toml version: $PYPROJECT_VERSION"
36+
37+
INIT_VERSION=$(grep '^__version__ =' pythonanywhere/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
38+
echo "__init__.py version: $INIT_VERSION"
39+
40+
if [ "$TAG_VERSION_NO_PREFIX" != "$PYPROJECT_VERSION" ]; then
41+
echo "Tag version ($TAG_VERSION_NO_PREFIX) does not match pyproject.toml version ($PYPROJECT_VERSION)" >&2
42+
exit 1
43+
fi
44+
45+
if [ "$TAG_VERSION_NO_PREFIX" != "$INIT_VERSION" ]; then
46+
echo "Tag version ($TAG_VERSION_NO_PREFIX) does not match __init__.py version ($INIT_VERSION)" >&2
47+
exit 1
48+
fi
49+
50+
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
51+
echo "pyproject.toml version ($PYPROJECT_VERSION) does not match __init__.py version ($INIT_VERSION)" >&2
52+
exit 1
53+
fi
54+
shell: bash
55+
56+
- name: Build package
57+
run: uv build
58+
59+
- name: Publish to PyPI
60+
uses: pypa/gh-action-pypi-publish@106e0b0b7c337fa67ed433972f777c6357f78598 # v1.13.0
61+
with:
62+
user: __token__
63+
password: ${{ secrets.PYPI_API_TOKEN }}
64+
65+
- name: Upload artifacts
66+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
67+
with:
68+
name: python-dist
69+
path: dist/
70+
71+
create_release:
72+
runs-on: ubuntu-latest
73+
needs: build_package
74+
steps:
75+
- name: Download artifacts
76+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
77+
with:
78+
name: python-dist
79+
path: dist/
80+
81+
- name: Create Release
82+
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
83+
with:
84+
files: dist/*
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Tests
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
pull_request:
6+
workflow_call:
47

58
jobs:
69
build:

0 commit comments

Comments
 (0)