Skip to content

Commit 84249c7

Browse files
committed
chore(gh): use the release artifact for testing
Signed-off-by: Brian Harring <ferringb@gmail.com>
1 parent 617206d commit 84249c7

File tree

4 files changed

+164
-50
lines changed

4 files changed

+164
-50
lines changed

.github/workflows/release.yml

Lines changed: 91 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,26 @@ name: release
22

33
on:
44
push:
5-
branches: [deploy]
5+
branches: [release-test-pypi, release-test-github, release-test-full]
66
tags: [v*]
7+
workflow_dispatch:
8+
79

810
jobs:
9-
build-and-deploy:
11+
build:
1012
runs-on: ubuntu-latest
11-
environment: release
12-
13-
permissions:
14-
id-token: write # Used to authenticate to PyPI via OIDC
15-
16-
contents: write # Used to authenticate github release publish
13+
outputs:
14+
release-artifact-id: ${{ steps.upload-release.outputs.artifact-id }}
15+
wheel-artifact-id: ${{ steps.upload-wheel.outputs.artifact-id }}
16+
artifact-runner: ${{ github.job }}
1717

1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@v5
2121

2222
- name: Reject any VCS dependencies
23-
shell: python
24-
run: |
25-
import re, tomllib
26-
manifest = tomllib.load(open('pyproject.toml', 'rb'))
27-
deps = manifest['build-system']['requires']
28-
deps.extend(manifest['project']['dependencies'])
29-
if rejects := list(filter(re.compile(r'@[^+]+').search, deps)):
30-
rejects = " \n".join(sorted(rejects))
31-
raise Exception(f'VCS dependencies were detected in [build-system]:\n {rejects}')
23+
continue-on-error: ${{ github.ref_type == 'branch' && github.ref_name != 'release-test-full' }}
24+
uses: pkgcore/gh-actions/reject-python-vcs-deps@main
3225

3326
- name: Set up Python 3.13
3427
uses: actions/setup-python@v5
@@ -40,43 +33,98 @@ jobs:
4033
- name: Install dependencies
4134
run: |
4235
python -m pip install --upgrade pip
43-
pip install build .[test]
44-
45-
- name: Test with pytest
46-
env:
47-
PY_COLORS: 1 # forcibly enable pytest colors
48-
run: pytest
36+
pip install build ".[doc]"
4937
50-
- name: Build sdist
38+
- name: Build the release
5139
run: |
52-
git clean -fxd
53-
# build sdist
54-
make sdist
55-
56-
- name: Build wheel
57-
run: make wheel
40+
make release
5841
5942
- name: Output dist file info
6043
run: |
6144
sha512sum dist/*
45+
echo ::group::Release contents
6246
tar -ztf dist/*.tar.gz | sort
47+
echo ::endgroup::
48+
echo ::group::All generated content in dist
49+
find .
50+
echo ::endgroup::
51+
52+
- name: Upload wheel
53+
id: upload-wheel
54+
uses: actions/upload-artifact@v5
55+
with:
56+
name: wheel-release
57+
path: dist/*.whl
58+
if-no-files-found: error
6359

64-
- uses: actions/upload-artifact@v4
60+
- name: Upload release source
61+
id: upload-release
62+
uses: actions/upload-artifact@v5
6563
with:
66-
name: results
67-
path: dist/*
64+
name: release-source
65+
path: dist/*.tar.gz
6866
if-no-files-found: error
69-
compression-level: 0
70-
overwrite: true
7167

72-
- name: publish
73-
uses: pypa/gh-action-pypi-publish@release/v1
74-
if: startsWith(github.ref, 'refs/tags/')
68+
test:
69+
needs: [build]
70+
uses: ./.github/workflows/test.yml
71+
with:
72+
release-artifact-id: ${{ needs.build.outputs.release-artifact-id }}
73+
format-check: false
74+
75+
publish:
76+
if: github.ref_type == 'tag'
77+
needs: [build, test]
78+
environment: release
79+
permissions:
80+
id-token: write # Used to authenticate to PyPI via OIDC
81+
contents: write # release uploads
82+
runs-on: ubuntu-latest
83+
84+
steps:
85+
- &common_download_artifacts
86+
name: Download artifacts
87+
uses: actions/download-artifact@v5
88+
with:
89+
merge-multiple: true # store both in the root, not in named directories
90+
artifact-ids: ${{ needs.build.outputs.release-artifact-id }},${{ needs.build.outputs.wheel-artifact-id }}
91+
92+
- name: Publish github source
93+
uses: softprops/action-gh-release@v2
94+
with:
95+
files: '*.tar.*'
96+
fail_on_unmatched_files: true
97+
98+
- name: Publish to PyPi server
99+
uses: pypa/gh-action-pypi-publish@release/v1.13
100+
with:
101+
packages-dir: .
102+
103+
test-publish:
104+
# use the full form to ensure insane tags and errors in 'on' filter still don't kick.
105+
if: github.ref_type == 'branch'
106+
needs: [build, test]
107+
environment: test-release
108+
permissions:
109+
id-token: write # Used to authenticate to PyPI via OIDC
110+
contents: write # release uploads-
111+
runs-on: ubuntu-latest
75112

76-
- name: Create GitHub release
77-
uses: softprops/action-gh-release@v1
78-
if: startsWith(github.ref, 'refs/tags/')
113+
steps:
114+
- *common_download_artifacts
115+
- name: Publish github source
116+
uses: softprops/action-gh-release@v2
117+
if: github.ref_name == 'release-test-github' || github.ref_name == 'release-test-full'
79118
with:
80-
files: dist/*.tar.gz
119+
files: '*.tar.*'
81120
fail_on_unmatched_files: true
82121
draft: true
122+
123+
- name: Publish to Test PyPi server
124+
if: github.ref_name == 'release-test-pypi' || github.ref_name == 'release-test-full'
125+
uses: pypa/gh-action-pypi-publish@release/v1.13
126+
with:
127+
packages-dir: .
128+
repository-url: https://test.pypi.org/legacy/
129+
# attestations are bound in a way re-releasing isn't possible. Disable for tests.
130+
attestations: false

.github/workflows/test.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@ name: test
22

33
on:
44
push:
5-
branches-ignore: [deploy]
5+
branches-ignore: [release-test-*]
66
pull_request:
77
branches: [master]
8+
workflow_call:
9+
inputs:
10+
release-artifact-id:
11+
required: false
12+
type: string
13+
default: ''
14+
description: The artifact-id to run the tests against.
15+
disable-format-check:
16+
type: string
17+
default: ''
18+
description: Disable ruff format check if it is a non empty value
819

920
jobs:
1021
build:
@@ -26,7 +37,9 @@ jobs:
2637

2738
steps:
2839
- name: Checkout code
29-
uses: actions/checkout@v4
40+
uses: pkgcore/gh-actions/get-source@main
41+
with:
42+
artifact-id: ${{ inputs.release-artifact-id }}
3043

3144
- name: Set up Python ${{ matrix.python-version }}
3245
uses: actions/setup-python@v5
@@ -66,8 +79,9 @@ jobs:
6679
fail-fast: false
6780
steps:
6881
- name: Checkout snakeoil
69-
uses: actions/checkout@v4
82+
uses: pkgcore/gh-actions/get-source@main
7083
with:
84+
artifact-id: ${{ inputs.release-artifact-id }}
7185
path: snakeoil
7286

7387
- name: Find last ${{ matrix.repo }} release
@@ -112,6 +126,7 @@ jobs:
112126

113127
format:
114128
runs-on: ubuntu-latest
129+
if: inputs.disable-format-check != ''
115130
steps:
116131
- name: Checkout code
117132
uses: actions/checkout@v4

Makefile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
PYTHON ?= python
22

3-
SPHINX_BUILD ?= sphinx-build
4-
53
.PHONY: man html
64
man html:
7-
$(SPHINX_BUILD) -a -b $@ doc build/sphinx/$@
5+
doc/build.sh $@ "$$(pwd)/build/sphinx/$@"
6+
7+
html: man
8+
9+
.PHONY: docs
10+
docs: man html
811

912
.PHONY: sdist wheel
1013
sdist wheel:
1114
$(PYTHON) -m build --$@
1215

16+
sdist: man
17+
18+
.PHONY: release
19+
release: sdist wheel
20+
1321
.PHONY: clean
1422
clean:
15-
$(RM) -r build/sphinx doc/api dist
23+
$(RM) -rf build/sphinx doc/api dist
1624

1725
.PHONY: format
1826
format:
1927
$(PYTHON) -m ruff format
28+
29+
.PHONY: dev-environment
30+
dev-environment:
31+
$(PYTHON) -m pip install -e .[test,doc,formatter]

doc/build.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash -e
2+
base=$(dirname "$(dirname "$(readlink -f "$0")")")
3+
4+
if [ ${#} -ne 2 ]; then
5+
echo "requires 2 arguments; the sphinx mode, and where to put the output."
6+
exit 1;
7+
fi
8+
mode="$1"
9+
output="$2"
10+
11+
12+
13+
# the point of this script is to capture sphinx output for extension
14+
# failures, and also dump that log automatically.
15+
16+
# force US; sphinx errors are localized, and we're abusing grep.
17+
export LANG=en_US.UTF-8
18+
19+
# capture stderr
20+
t=$(mktemp)
21+
if python -m sphinx.cmd.build -a -b "$mode" "$base/doc" "$output" 2>$t; then
22+
exit $?
23+
fi
24+
25+
# extract the traceback path
26+
dump=$(grep -A1 'traceback has been saved in' "$t" | tail -n1)
27+
cat < "$t"
28+
echo
29+
if [ -z "$dump" ]; then
30+
echo "FAILED auto extracting the traceback file. you'll have to do it manually"
31+
else
32+
echo
33+
echo "contents of $dump"
34+
echo
35+
cat < "$dump"
36+
rm "$t"
37+
fi
38+
39+
exit 2

0 commit comments

Comments
 (0)