forked from vincentlaucsb/csv-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (127 loc) · 3.82 KB
/
Copy pathpython-publish.yml
File metadata and controls
151 lines (127 loc) · 3.82 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Publish Python Package
on:
release:
types: [published]
permissions:
contents: read
jobs:
validate-release:
name: Validate release metadata
runs-on: ubuntu-latest
outputs:
version: ${{ steps.metadata.outputs.version }}
steps:
- name: Checkout release tag
uses: actions/checkout@v5
with:
ref: ${{ github.event.release.tag_name }}
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Validate tag and Python package version
id: metadata
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
python - <<'PY'
import os
import re
import tomllib
from pathlib import Path
tag = os.environ["RELEASE_TAG"]
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", tag):
raise SystemExit(
f"PyPI publishing requires a numbered tag like 5.2.0; got {tag!r}"
)
project = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["project"]
version = project["version"]
if version != tag:
raise SystemExit(
f"pyproject.toml version {version!r} does not match release tag {tag!r}"
)
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out:
out.write(f"version={version}\n")
PY
build-wheels:
name: Build wheels (${{ matrix.os }})
needs: validate-release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout release tag
uses: actions/checkout@v5
with:
ref: ${{ github.event.release.tag_name }}
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install wheel tooling
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade cibuildwheel twine
- name: Build wheels
env:
CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-* cp313-* cp314-*"
run: python -m cibuildwheel --output-dir wheelhouse
- name: Check wheel metadata
run: python -m twine check wheelhouse/*
- name: Upload wheel artifacts
uses: actions/upload-artifact@v5
with:
name: fastpycsv-wheels-${{ matrix.os }}
path: wheelhouse/*
if-no-files-found: error
build-sdist:
name: Build source distribution
needs: validate-release
runs-on: ubuntu-latest
steps:
- name: Checkout release tag
uses: actions/checkout@v5
with:
ref: ${{ github.event.release.tag_name }}
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Build sdist
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build twine
python -m build --sdist
python -m twine check dist/*
- name: Upload source artifact
uses: actions/upload-artifact@v5
with:
name: fastpycsv-sdist
path: dist/*
if-no-files-found: error
publish-pypi:
name: Publish to PyPI
needs: [validate-release, build-wheels, build-sdist]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/fastpycsv
permissions:
contents: read
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v5
with:
pattern: fastpycsv-*
path: dist
merge-multiple: true
- name: Publish distributions to PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
with:
packages-dir: dist/