Skip to content

Commit 5bb2bea

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 475f404 commit 5bb2bea

File tree

2 files changed

+120
-49
lines changed

2 files changed

+120
-49
lines changed

.github/workflows/release.yml

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +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*]
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+
continue-on-error: ${{ github.ref_type == 'branch' && github.ref_name != 'release-test-full' }}
24+
uses: ferringb/gh-actions/reject-python-vcs-deps@main
3325

3426
- name: Set up Python 3.13
3527
uses: actions/setup-python@v5
@@ -41,15 +33,11 @@ jobs:
4133
- name: Install dependencies
4234
run: |
4335
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
36+
pip install build ".[doc]"
5037
5138
- name: Build sdist
5239
run: |
40+
which pytest && echo "safe"
5341
git clean -fxd
5442
make man
5543
make sdist
@@ -60,21 +48,89 @@ jobs:
6048
- name: Output dist file info
6149
run: |
6250
sha512sum dist/*
51+
echo ::group::Release contents
6352
tar -ztf dist/*.tar.gz | sort
53+
echo ::endgroup::
54+
echo ::group::All generated content in dist
55+
find .
56+
echo ::endgroup::
57+
58+
- name: Upload wheel
59+
id: upload-wheel
60+
uses: actions/upload-artifact@v5
61+
with:
62+
name: wheel-release
63+
path: dist/*.whl
64+
if-no-files-found: error
65+
66+
- name: Upload release source
67+
id: upload-release
68+
uses: actions/upload-artifact@v5
69+
with:
70+
name: release-source
71+
path: dist/*.tar.gz
72+
if-no-files-found: error
73+
74+
test:
75+
needs: [build]
76+
uses: ./.github/workflows/test.yml
77+
with:
78+
release-artifact-id: ${{ needs.build.outputs.release-artifact-id }}
79+
format-check: false
80+
81+
publish:
82+
if: github.ref_type == 'tag'
83+
needs: [build, test]
84+
environment: release
85+
permissions:
86+
id-token: write # Used to authenticate to PyPI via OIDC
87+
contents: write # release uploads
88+
runs-on: ubuntu-latest
6489

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

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

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