Skip to content

Commit 297685a

Browse files
committed
chore: rework release workflow to reuse the tests workflow.
High level: * Add multiple release-test-* branch targets as a way to flex and test the release pathway. This includes wiring test pypi in. The pkgcore project there is under my account which I'll transfer once the PR lands and I figure out the 'how'. * The release process now runs the full test suite. This is being done for obvious reasons, but particularly since the previous pathway was covering up an unstated dep of .[doc] requiring pytest due to snakeoil/test/mixins. * To support that, test workflow was rewired to use a custom action that can pivot between git cloning, or using a git artifact (IE, the release tarball being tested). https://github.com/ferringb/gh-actions/blob/main/get-source/action.yml shows why an action encapsulating this was necessary. lesser stuff: * disable format check for releases. If we've tagged, by the time the tag is in github we have to just accept any format violations. * The publish code is duplicated because pypi upload doesn't support being invoked from reusable workflows. And GH doesn't support the yaml spec fully (no <<:*), thus just violating DRY. Moving that to an in repo action is a possibility. * I turned off 'draft' for github publishing. If we publish to PyPI, the source has to be publically available. I also forced the github release to be first for this reason (if it fails, no pypi release). * Since I broke out actions, I also moved out the VCS check code. This gh-actions repo I intend as pkgcore/gh-actions, but that requires some gentoo infra interactions which I'll do after folks double check this work. Signed-off-by: Brian Harring <[email protected]>
1 parent 777c7f3 commit 297685a

File tree

2 files changed

+121
-49
lines changed

2 files changed

+121
-49
lines changed

.github/workflows/release.yml

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

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

9+
910
jobs:
10-
build-and-deploy:
11+
build:
1112
runs-on: ubuntu-latest
12-
environment: release
13-
14-
permissions:
15-
id-token: write # Used to authenticate to PyPI via OIDC
16-
17-
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 }}
1817

1918
steps:
2019
- name: Checkout code
21-
uses: actions/checkout@v4
20+
uses: actions/checkout@v5
2221

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

3427
- name: Set up Python 3.13
3528
uses: actions/setup-python@v5
@@ -41,15 +34,11 @@ jobs:
4134
- name: Install dependencies
4235
run: |
4336
python -m pip install --upgrade pip
44-
pip install build ".[test,doc]"
45-
46-
- name: Test with pytest
47-
env:
48-
PY_COLORS: 1 # forcibly enable pytest colors
49-
run: pytest
37+
pip install build ".[doc]"
5038
5139
- name: Build sdist
5240
run: |
41+
which pytest && echo "safe"
5342
git clean -fxd
5443
make man
5544
make sdist
@@ -60,21 +49,89 @@ jobs:
6049
- name: Output dist file info
6150
run: |
6251
sha512sum dist/*
52+
echo ::group::Release contents
6353
tar -ztf dist/*.tar.gz | sort
54+
echo ::endgroup::
55+
echo ::group::All generated content in dist
56+
find .
57+
echo ::endgroup::
58+
59+
- name: Upload wheel
60+
id: upload-wheel
61+
uses: actions/upload-artifact@v5
62+
with:
63+
name: wheel-release
64+
path: dist/*.whl
65+
if-no-files-found: error
66+
67+
- name: Upload release source
68+
id: upload-release
69+
uses: actions/upload-artifact@v5
70+
with:
71+
name: release-source
72+
path: dist/*.tar.gz
73+
if-no-files-found: error
74+
75+
test:
76+
needs: [build]
77+
uses: ./.github/workflows/test.yml
78+
with:
79+
release-artifact-id: ${{ needs.build.outputs.release-artifact-id }}
80+
format-check: false
81+
82+
publish:
83+
if: github.ref_type == 'tag'
84+
needs: [build, test]
85+
environment: release
86+
permissions:
87+
id-token: write # Used to authenticate to PyPI via OIDC
88+
contents: write # release uploads
89+
runs-on: ubuntu-latest
6490

65-
- uses: actions/upload-artifact@v4
91+
steps:
92+
- &common_download_artifacts
93+
name: Download artifacts
94+
uses: actions/download-artifact@v5
6695
with:
67-
name: results
68-
path: dist/*
96+
merge-multiple: true # store both in the root, not in named directories
97+
artifact-ids: ${{ needs.build.outputs.release-artifact-id }},${{ needs.build.outputs.wheel-artifact-id }}
6998

70-
- name: publish
71-
uses: pypa/gh-action-pypi-publish@release/v1
72-
if: startsWith(github.ref, 'refs/tags/')
99+
- name: Publish github source
100+
uses: softprops/action-gh-release@v2
101+
with:
102+
files: '*.tar.*'
103+
fail_on_unmatched_files: true
73104

74-
- name: Create GitHub release
75-
uses: softprops/action-gh-release@v1
76-
if: startsWith(github.ref, 'refs/tags/')
105+
- name: Publish to PyPi server
106+
uses: pypa/gh-action-pypi-publish@release/v1.13
77107
with:
78-
files: dist/*.tar.gz
108+
packages-dir: .
109+
110+
test-publish:
111+
# use the full form to ensure insane tags and errors in 'on' filter still don't kick.
112+
if: github.ref_type == 'branch'
113+
needs: [build, test]
114+
environment: test-release
115+
permissions:
116+
id-token: write # Used to authenticate to PyPI via OIDC
117+
contents: write # release uploads-
118+
runs-on: ubuntu-latest
119+
120+
steps:
121+
- *common_download_artifacts
122+
- name: Publish github source
123+
uses: softprops/action-gh-release@v2
124+
if: github.ref_name == 'release-test-github' || github.ref_name == 'release-test-full'
125+
with:
126+
files: '*.tar.*'
79127
fail_on_unmatched_files: true
80128
draft: true
129+
130+
- name: Publish to Test PyPi server
131+
if: github.ref_name == 'release-test-pypi' || github.ref_name == 'release-test-full'
132+
uses: pypa/gh-action-pypi-publish@release/v1.13
133+
with:
134+
packages-dir: .
135+
repository-url: https://test.pypi.org/legacy/
136+
# attestations are bound in a way re-releasing isn't possible. Disable for tests.
137+
attestations: false

.github/workflows/test.yml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +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-
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+
format-check:
16+
type: boolean
17+
default: true
18+
description: Run the ruff format check. This should only be disabled for releases.
919
jobs:
1020
build:
1121
runs-on: ${{ matrix.os }}
@@ -32,8 +42,10 @@ jobs:
3242
fail-fast: false
3343

3444
steps:
35-
- name: Checkout code
36-
uses: actions/checkout@v4
45+
- name: Checkout pkgcore
46+
uses: ferringb/gh-actions/get-source@main
47+
with:
48+
artifact-id: ${{ inputs.release-artifact-id }}
3749

3850
- name: Pin dependencies to minimal versions
3951
if: ${{ matrix.deps == 'minimal-deps' }}
@@ -77,12 +89,13 @@ jobs:
7789
runs-on: ubuntu-latest
7890
steps:
7991
- name: Checkout pkgcore
80-
uses: actions/checkout@v4
92+
uses: ferringb/gh-actions/get-source@main
8193
with:
94+
artifact-id: ${{ inputs.release-artifact-id }}
8295
path: pkgcore
8396

8497
- name: Checkout pkgcheck
85-
uses: actions/checkout@v4
98+
uses: actions/checkout@v5
8699
with:
87100
repository: pkgcore/pkgcheck
88101
path: pkgcheck
@@ -99,7 +112,7 @@ jobs:
99112
- name: Install pip dependencies
100113
run: |
101114
python -m pip install --upgrade pip
102-
pip install -e "./pkgcore"
115+
pip install "./pkgcore"
103116
pip install "./pkgcheck[test]"
104117
105118
- name: Test with pytest
@@ -112,12 +125,12 @@ jobs:
112125
runs-on: ubuntu-latest
113126
steps:
114127
- name: Checkout pkgcore
115-
uses: actions/checkout@v4
128+
uses: ferringb/gh-actions/get-source@main
116129
with:
130+
artifact-id: ${{ inputs.release-artifact-id }}
117131
path: pkgcore
118-
119132
- name: Checkout pkgdev
120-
uses: actions/checkout@v4
133+
uses: actions/checkout@v5
121134
with:
122135
repository: pkgcore/pkgdev
123136
path: pkgdev
@@ -134,7 +147,7 @@ jobs:
134147
- name: Install pip dependencies
135148
run: |
136149
python -m pip install --upgrade pip
137-
pip install -e "./pkgcore"
150+
pip install "./pkgcore"
138151
pip install "./pkgdev[test]"
139152
140153
- name: Test with pytest
@@ -145,9 +158,10 @@ jobs:
145158

146159
format:
147160
runs-on: ubuntu-latest
161+
if: inputs.format-check
148162
steps:
149-
- name: Checkout code
150-
uses: actions/checkout@v4
163+
- name: Checkout pkgcore
164+
uses: actions/checkout@v5
151165
- uses: astral-sh/ruff-action@v3
152166
with:
153167
args: "format --check --diff"
@@ -156,8 +170,9 @@ jobs:
156170
runs-on: ubuntu-latest
157171
steps:
158172
- name: Checkout pkgcore
159-
uses: actions/checkout@v4
173+
uses: ferringb/gh-actions/get-source@main
160174
with:
175+
artifact-id: ${{ inputs.release-artifact-id }}
161176
path: pkgcore
162177

163178
- name: Checkout gentoo
@@ -174,7 +189,7 @@ jobs:
174189
- name: Install pip dependencies
175190
run: |
176191
python -m pip install --upgrade pip
177-
pip install -e "./pkgcore"
192+
pip install "./pkgcore"
178193
179194
- name: Run pmaint regen
180195
working-directory: ./gentoo

0 commit comments

Comments
 (0)