Skip to content

Commit 2757866

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 2757866

2 files changed

Lines changed: 111 additions & 40 deletions

File tree

.github/workflows/release.yml

Lines changed: 81 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,81 @@ 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::
6465
65-
- uses: actions/upload-artifact@v4
66+
- name: Upload wheel
67+
id: upload-wheel
68+
uses: actions/upload-artifact@v5
6669
with:
67-
name: results
68-
path: dist/*
70+
name: wheel-release
71+
path: dist/*.whl
72+
if-no-files-found: error
6973

70-
- name: publish
71-
uses: pypa/gh-action-pypi-publish@release/v1
72-
if: startsWith(github.ref, 'refs/tags/')
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
7381

74-
- name: Create GitHub release
75-
uses: softprops/action-gh-release@v1
76-
if: startsWith(github.ref, 'refs/tags/')
82+
publish:
83+
if: github.ref_type == 'tag'
84+
needs: [build]
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
90+
91+
steps:
92+
- &common_download_artifacts
93+
name: Download artifacts
94+
uses: actions/download-artifact@v5
7795
with:
78-
files: dist/*.tar.gz
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 }}
98+
99+
- name: Publish github source
100+
uses: softprops/action-gh-release@v2
101+
with:
102+
files: '*.tar.*'
103+
fail_on_unmatched_files: true
104+
105+
- name: Publish to PyPi server
106+
uses: pypa/gh-action-pypi-publish@release/v1.13
107+
with:
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]
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+
123+
- name: Publish github source
124+
uses: softprops/action-gh-release@v2
125+
if: github.ref_name == 'release-test-github' || github.ref_name == 'release-test-full'
126+
with:
127+
files: '*.tar.*'
79128
fail_on_unmatched_files: true
80129
draft: true
130+
131+
- name: Publish to Test PyPi server
132+
if: github.ref_name == 'release-test-pypi' || github.ref_name == 'release-test-full'
133+
uses: pypa/gh-action-pypi-publish@release/v1.13
134+
with:
135+
packages-dir: .
136+
repository-url: https://test.pypi.org/legacy/

.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)