-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (94 loc) · 3.18 KB
/
Copy pathpublish-pypi.yml
File metadata and controls
108 lines (94 loc) · 3.18 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
name: Publish
on:
release:
types: [published]
workflow_dispatch:
inputs:
expected_version:
description: Required for manual PyPI publish (e.g. 0.1.0)
required: false
default: ""
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.13"
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install dependencies
run: uv sync --extra dev --extra diff
- name: Build distributions
run: uv build --out-dir dist
- name: Check distributions
run: uv run python -m twine check dist/*
- name: Smoke test wheel install
run: |
set -euo pipefail
uv venv .venv-smoke
uv pip install --python .venv-smoke/bin/python dist/*.whl
.venv-smoke/bin/pgpkg --help
- name: Smoke test generated wrapper
run: |
set -euo pipefail
smoke_python="$PWD/.venv-smoke/bin/python"
smoke_wrapper="$PWD/.venv-smoke/bin/sampleext-migrator"
tmpdir="$(mktemp -d)"
cp -R tests/fixtures/sample_project/. "$tmpdir/"
uv run pgpkg stageversion 0.1.0 --project-root "$tmpdir"
uv run pgpkg wheel --project-root "$tmpdir" --output-dir "$tmpdir/wrapper"
pushd "$tmpdir/wrapper"
uv build --out-dir dist
uv pip install --python "$smoke_python" dist/*.whl
"$smoke_wrapper" info
popd
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/*
if-no-files-found: error
publish-pypi:
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
environment:
name: pypi
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist
- name: Verify expected version matches built version
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
expected_version="${GITHUB_REF_NAME#v}"
else
expected_version="${{ inputs.expected_version }}"
if [[ -z "$expected_version" ]]; then
echo "inputs.expected_version is required for workflow_dispatch PyPI publish."
exit 1
fi
fi
built_wheel="$(ls dist/pgpkg-*.whl | head -n1)"
built_version="$(basename "$built_wheel" | sed -E 's/^pgpkg-([0-9][^-]*)-.*/\1/')"
echo "Expected version: $expected_version"
echo "Built wheel version: $built_version"
if [[ "$built_version" != "$expected_version" ]]; then
echo "Release tag and built package version do not match."
exit 1
fi
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1