Repository navigation
59 lines (49 loc) · 1.85 KB
/
Copy pathrelease.yml
File metadata and controls
59 lines (49 loc) · 1.85 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
name: Release
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+
jobs:
build:
if: ${{ github.repository == 'Netflix/spectator-py' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install pypa/build
run: |
python -m pip install --upgrade pip
python -m pip install build packaging --user
# PyPI accepts each version only once, so a tag on a commit with a different version
# fails at upload. Stop before building instead. Versions are compared under PEP 440,
# so the tag v1.3.0-rc.1 matches the version 1.3.0rc1.
- name: Check the tag matches the version in pyproject.toml
run: |
python - <<'EOF'
import os
import sys
import tomllib
from packaging.version import Version
tag = os.environ["GITHUB_REF_NAME"]
with open("pyproject.toml", "rb") as f:
version = tomllib.load(f)["project"]["version"]
if Version(tag.removeprefix("v")) != Version(version):
print(
f"::error::Tag {tag} does not match version {version} in pyproject.toml. "
"Merge the version bump first, then delete and recreate the release."
)
sys.exit(1)
print(f"Tag {tag} matches version {version} in pyproject.toml")
EOF
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/ .
- name: Publish Distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}