Skip to content

Commit 9db27bd

Browse files
Add release and manual publish workflows
1 parent e68119e commit 9db27bd

File tree

3 files changed

+124
-11
lines changed

3 files changed

+124
-11
lines changed

.github/workflows/publish.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
target:
7+
description: "Where to publish"
8+
type: choice
9+
options: ["pypi", "testpypi"]
10+
default: "pypi"
11+
ref:
12+
description: "Git ref to publish (tag or branch). Leave blank to use default branch."
13+
required: false
14+
default: ""
15+
16+
jobs:
17+
build-and-upload:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.event.inputs.ref || '' }}
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.12"
31+
32+
- name: Install build tools
33+
run: |
34+
python -m pip install -U pip
35+
python -m pip install -U build twine
36+
37+
- name: Build sdist and wheel
38+
run: python -m build
39+
40+
- name: Publish to TestPyPI
41+
if: ${{ inputs.target == 'testpypi' }}
42+
env:
43+
TWINE_USERNAME: __token__
44+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
45+
run: |
46+
python -m twine upload --repository-url https://test.pypi.org/legacy/ --non-interactive dist/*
47+
48+
- name: Publish to PyPI
49+
if: ${{ inputs.target == 'pypi' }}
50+
env:
51+
TWINE_USERNAME: __token__
52+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
53+
run: |
54+
python -m twine upload --non-interactive dist/*

.github/workflows/release.yml

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,66 @@
11
name: release
2+
23
on:
34
push:
45
tags:
56
- "v*"
67

7-
permissions:
8-
contents: read
9-
108
jobs:
11-
build-and-publish:
9+
build-attach:
10+
name: Build package, test, attach to GitHub Release
1211
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write # to create GitHub Release & upload assets
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Install build & dev deps
24+
run: |
25+
python -m pip install -U pip
26+
python -m pip install -U build
27+
python -m pip install -e ".[dev]"
28+
29+
- name: Run tests
30+
run: pytest -q
31+
32+
- name: Build sdist and wheel
33+
run: python -m build
34+
35+
- name: Upload artifacts
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: dist
39+
path: dist/*
40+
41+
- name: Create/Update GitHub Release with artifacts
42+
uses: softprops/action-gh-release@v2
43+
with:
44+
files: dist/*
45+
draft: false
46+
prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
50+
test-matrix:
51+
name: Test (3.10–3.12)
52+
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
python-version: ["3.10", "3.11", "3.12"]
1356
steps:
1457
- uses: actions/checkout@v4
1558
- uses: actions/setup-python@v5
1659
with:
17-
python-version: "3.11"
18-
- run: python -m pip install -U pip build
19-
- run: python -m build
20-
- name: Publish to PyPI
21-
uses: pypa/gh-action-pypi-publish@release/v1
22-
with:
23-
password: ${{ secrets.PYPI_API_TOKEN }}
60+
python-version: ${{ matrix.python-version }}
61+
- name: Install package (dev)
62+
run: |
63+
python -m pip install -U pip
64+
python -m pip install -e ".[dev]"
65+
- name: Run tests
66+
run: pytest -q

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,19 @@ To publish a new version on [PyPI](https://pypi.org/project/sudoku_dlx/):
130130

131131
The CI workflow already runs tests against multiple Python versions and uploads coverage
132132
reports to Codecov; the `pages` workflow deploys the static demo from the `web/` directory.
133+
134+
### Automated releases (no auto-PyPI)
135+
On pushing a tag like `v0.2.1`, GitHub Actions will:
136+
- run tests against 3.10–3.12,
137+
- build wheels/sdist, and
138+
- attach artifacts to the GitHub Release (no PyPI upload).
139+
140+
### Manual publish (when you’re ready)
141+
1. Create a token on PyPI (or TestPyPI).
142+
2. Add a repo secret:
143+
- **Settings → Secrets and variables → Actions**
144+
- New secrets: `PYPI_API_TOKEN` (and/or `TEST_PYPI_API_TOKEN`)
145+
3. From **Actions** tab, run **publish**:
146+
- Choose **pypi** or **testpypi**
147+
- Optionally set **ref** (leave blank to use default branch HEAD)
148+
4. The workflow builds and uploads the current code to the chosen index.

0 commit comments

Comments
 (0)