-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (125 loc) · 5.12 KB
/
Copy pathdev.yml
File metadata and controls
135 lines (125 loc) · 5.12 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
# Dev: the frequent dev-release button. Publishes the next dev version
# (X.Y.Z-devN) to PyPI as a pre-release. Manual trigger only.
on:
workflow_dispatch:
jobs:
test:
strategy:
matrix:
include:
- { python-version: '3.10', os: ubuntu-latest }
- { python-version: '3.11', os: ubuntu-latest }
- { python-version: '3.12', os: ubuntu-latest }
- { python-version: '3.13', os: ubuntu-latest }
- { python-version: '3.14', os: ubuntu-latest }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-cov
- name: Run tests
run: pytest tests
publish:
needs: test
runs-on: ubuntu-latest
permissions:
id-token: write # trusted publishing (OIDC) to PyPI
contents: write # push the version bump and cut the release
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install build tooling
run: |
python -m pip install --upgrade pip
pip install build
# Compute the next dev version from VERSION and expose it as
# VERSION_INFO in the environment for the steps below.
- name: Resolve next version
run: python version_get.py dev VERSION_INFO
# Write VERSION_INFO into pyproject.toml (the build reads its
# version from there) and into src/markwork/__init__.py (so
# 'markwork.__version__' matches the published version). docs/conf.py
# reads the version straight from the stamped pyproject.toml.
- name: Stamp version into pyproject and package
run: |
python - <<'PY'
import os
version = os.environ["VERSION_INFO"]
targets = [
("pyproject.toml", "version", 'version = "%s"'),
("src/markwork/__init__.py", "__version__",
"__version__ = \"%s\""),
]
for path, prefix, template in targets:
lines = open(path, encoding="utf-8").read().splitlines()
for i, line in enumerate(lines):
if line.lstrip().startswith(prefix) and "=" in line:
lines[i] = template % version
break
body = "\n".join(lines) + "\n"
open(path, "w", encoding="utf-8").write(body)
PY
- name: Build
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# PyPI can return success on upload while a backend or CDN incident
# quietly drops the file, so the workflow goes green but nothing is
# served. Poll until the version is actually live, and fail if it
# never appears, so the bump and tag below never run on a phantom
# publish.
- name: Verify the release is live on PyPI
run: |
python - <<'PY'
import json, os, sys, time
import urllib.error, urllib.request
version = os.environ["VERSION_INFO"]
want = "".join(c for c in version.lower() if c.isalnum())
url = "https://pypi.org/pypi/markwork/json"
headers = {"User-Agent": "markwork-release-check"}
deadline = time.time() + 600
# Any transient error (a 404 before the file is served, a 5xx
# during an incident, a timeout) just means "not yet": keep
# polling until the deadline, then fail.
while time.time() < deadline:
try:
request = urllib.request.Request(url, headers=headers)
data = json.load(urllib.request.urlopen(request, timeout=20))
keys = data.get("releases", {})
if any("".join(c for c in k.lower() if c.isalnum()) == want
for k in keys):
print("Confirmed %s is live on PyPI." % version)
sys.exit(0)
except (urllib.error.URLError, TimeoutError, ValueError):
pass
time.sleep(20)
sys.exit("%s never appeared on PyPI." % version)
PY
# Only reached once the release is confirmed live: advance the
# counters in VERSION, then commit VERSION + the stamped files.
- name: Bump version counters
run: python version_bump.py dev
- name: Commit version changes
run: |
git config user.name "Asger Jon Vistisen"
git config user.email "asgerjon2@gmail.com"
git add VERSION pyproject.toml src/markwork/__init__.py
git commit -m "dev ${{ env.VERSION_INFO }}"
git push origin HEAD:${{ github.ref }}
- name: GitHub pre-release
uses: ncipollo/release-action@v1.21.0
with:
tag: ${{ env.VERSION_INFO }}
name: dev ${{ env.VERSION_INFO }}
prerelease: true
generateReleaseNotes: true