Skip to content

Commit 5ff18a6

Browse files
committed
chore: rework release workflow to reuse the tests workflow.
High level: * add test-release target that is wired against test-pypi. This is currently against a project I control (including OIDC) but that's required for the dev work of this. I'll unwind/transfer after. * release process now runs the full test suite. This is being done for obvious reasons, but also since the previous setup hid a bug in the man page generation pathway. * 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 web kind of just have to roll with it. * 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. stuff of debate: * 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). Signed-off-by: Brian Harring <ferringb@gmail.com>
1 parent 777c7f3 commit 5ff18a6

2 files changed

Lines changed: 120 additions & 40 deletions

File tree

.github/workflows/release.yml

Lines changed: 90 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ 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
23+
continue-on-error: ${{ github.ref_type == 'branch' && github.ref_name != 'release-test-full' }}
2424
shell: python
2525
run: |
2626
import re, tomllib
@@ -41,15 +41,11 @@ jobs:
4141
- name: Install dependencies
4242
run: |
4343
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
44+
pip install build ".[doc]"
5045
5146
- name: Build sdist
5247
run: |
48+
which pytest && echo "safe"
5349
git clean -fxd
5450
make man
5551
make sdist
@@ -60,21 +56,90 @@ jobs:
6056
- name: Output dist file info
6157
run: |
6258
sha512sum dist/*
59+
echo ::group::Release contents
6360
tar -ztf dist/*.tar.gz | sort
61+
echo ::endgroup::
62+
echo ::group::All generated content in dist
63+
find .
64+
echo ::endgroup::
65+
66+
- name: Upload wheel
67+
id: upload-wheel
68+
uses: actions/upload-artifact@v5
69+
with:
70+
name: wheel-release
71+
path: dist/*.whl
72+
if-no-files-found: error
73+
74+
- name: Upload release source
75+
id: upload-release
76+
uses: actions/upload-artifact@v5
77+
with:
78+
name: release-source
79+
path: dist/*.tar.gz
80+
if-no-files-found: error
81+
82+
test:
83+
needs: [build]
84+
uses: ./.github/workflows/test.yml
85+
with:
86+
release-artifact-id: ${{ needs.build.outputs.release-artifact-id }}
87+
format-check: false
88+
89+
publish:
90+
if: github.ref_type == 'tag'
91+
needs: [build, test]
92+
environment: release
93+
permissions:
94+
id-token: write # Used to authenticate to PyPI via OIDC
95+
contents: write # release uploads
96+
runs-on: ubuntu-latest
6497

65-
- uses: actions/upload-artifact@v4
98+
steps:
99+
- &common_download_artifacts
100+
name: Download artifacts
101+
uses: actions/download-artifact@v5
66102
with:
67-
name: results
68-
path: dist/*
103+
merge-multiple: true # store both in the root, not in named directories
104+
artifact-ids: ${{ needs.build.outputs.release-artifact-id }},${{ needs.build.outputs.wheel-artifact-id }}
69105

70-
- name: publish
71-
uses: pypa/gh-action-pypi-publish@release/v1
72-
if: startsWith(github.ref, 'refs/tags/')
106+
- name: Publish github source
107+
uses: softprops/action-gh-release@v2
108+
with:
109+
files: '*.tar.*'
110+
fail_on_unmatched_files: true
73111

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