-
Notifications
You must be signed in to change notification settings - Fork 1
133 lines (117 loc) · 4.08 KB
/
Copy pathrelease.yml
File metadata and controls
133 lines (117 loc) · 4.08 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Release to PyPI.
#
# Trigger: GitHub Release published.
# Flow you'll follow manually:
# 1. Bump `version` in pyproject.toml, commit, push.
# 2. Create a GitHub Release (UI or `gh release create`) from the
# tag of your choice (e.g. v0.1.2). Set release notes.
# 3. Click "Publish release".
# 4. This workflow fires: builds the wheel, publishes to PyPI,
# uploads the wheel + sdist as assets on the release itself.
#
# The release tag must match `project.version` in pyproject.toml; the
# build fails loudly otherwise so mismatched metadata never ships.
# Pre-release versions (0.1.2.dev1, 0.1.2rc1, ...) are rejected here —
# use the Release (TestPyPI) workflow for those.
#
# One-time setup on PyPI
# ----------------------
# 1. pypi.org → Manage → Publishing → Add a pending publisher:
# Owner: <your-gh-username-or-org>
# Repo: <your-repo-name>
# Workflow: release.yml
# Env: pypi
# 2. GitHub repo → Settings → Environments → create `pypi`
# (optionally require a manual approval here for prod releases).
#
# After setup, no secrets are needed — OIDC handles the auth.
name: Release (PyPI)
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
cache-dependency-path: frontend/package-lock.json
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build tools
run: python -m pip install --upgrade pip build twine
- name: Build frontend bundle
working-directory: frontend
run: |
npm ci
npm run build
- name: Copy bundle into Python package
run: |
rm -rf backend/app/static
mkdir -p backend/app/static
cp -R frontend/dist/. backend/app/static/
- name: Build wheel + sdist
run: python -m build
- name: Check artifacts
run: twine check dist/*
- name: Read version from pyproject.toml
id: version
run: |
v=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
echo "version=$v" >> "$GITHUB_OUTPUT"
- name: Verify release tag matches pyproject version
run: |
tag="${{ github.event.release.tag_name }}"
# Strip a leading "v" if present (v0.1.2 → 0.1.2)
tag="${tag#v}"
pyv="${{ steps.version.outputs.version }}"
if [ "$tag" != "$pyv" ]; then
echo "::error::Release tag ${{ github.event.release.tag_name }} doesn't match pyproject.toml version $pyv"
exit 1
fi
- name: Reject pre-release versions (use TestPyPI workflow instead)
run: |
v="${{ steps.version.outputs.version }}"
if echo "$v" | grep -Eq '(a|b|rc|\.dev)[0-9]+$'; then
echo "::error::Real PyPI releases must be clean versions (0.1.2). Got pre-release: $v"
echo "::error::Use the Release (TestPyPI) workflow for dry-runs; drop the suffix before publishing."
exit 1
fi
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish:
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
attach-assets:
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Upload wheel + sdist to the GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "${{ github.event.release.tag_name }}" dist/* --clobber