-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (70 loc) · 2.52 KB
/
Copy pathpublish.yml
File metadata and controls
78 lines (70 loc) · 2.52 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
name: Publish to PyPI
on:
release:
types: [published]
jobs:
sync-assets:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: main
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Sync version to banner SVG
run: |
VERSION="${GITHUB_REF_NAME#v}"
sed -i "s|>v[0-9]\+\.[0-9]\+\.[0-9]\+<|>v${VERSION}<|" docs/cli-banner.svg
- name: Count tests and sync to assets
run: |
pip install -e ".[dev]" --quiet 2>/dev/null
COUNT=$(python -m pytest tests/ -q --co 2>&1 | tail -1 | grep -oP '^\d+')
if [ -n "$COUNT" ]; then
python -c "
import re, pathlib
# Landing page: update the number before 'Tests passing'
html = pathlib.Path('docs/index.html').read_text()
html = re.sub(
r'(<span class=\"val\">)\d+(</span>\s*<span class=\"label\">Tests passing)',
rf'\g<1>${COUNT}\2', html)
pathlib.Path('docs/index.html').write_text(html)
"
sed -i "s|Tests-[0-9]\+%20passing|Tests-${COUNT}%20passing|g" README.md README.es.md
sed -i "s|Tests: [0-9]\+ passing|Tests: ${COUNT} passing|g" README.md README.es.md
sed -i "s|^[0-9]\+ tests\. |${COUNT} tests. |" README.md README.es.md
sed -i "s|contains [0-9]\+ tests|contains ${COUNT} tests|g" CONTRIBUTING.md
echo "Updated test count to ${COUNT}"
fi
- name: Commit updated assets
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git diff --quiet || (git add docs/cli-banner.svg docs/index.html README.md README.es.md CONTRIBUTING.md && git commit -m "chore: sync version, test count to ${GITHUB_REF_NAME} [skip ci]" && git push origin main)
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- run: pip install build
- run: python -m build
- 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