-
Notifications
You must be signed in to change notification settings - Fork 4
152 lines (129 loc) Β· 4.23 KB
/
test-release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
name: "ππ¦ Test build and release"
# GitHub/PyPI trusted publisher documentation:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
env:
python-version: "3.10"
### BUILD ###
jobs:
build:
name: "π Build packages"
runs-on: ubuntu-latest
permissions:
# IMPORTANT: mandatory for Sigstore
id-token: write
steps:
### BUILDING ###
- name: "Checkout repository"
uses: actions/checkout@v4
- name: "Setup Python 3.10"
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}
- name: "Setup PDM for build commands"
uses: pdm-project/[email protected]
with:
python-version: ${{ env.python-version }}
- name: "Populate environment variables"
id: setenv
run: |
vernum="${{ env.python-version }}.$(date +'%Y%m%d%H%M')"
echo "vernum=${vernum}" >> "$GITHUB_OUTPUT"
echo "vernum=${vernum}" >> buildvars.txt
- name: "Tag for test release"
# Delete all local tags, then create a synthetic tag for testing
# Use the date/time to avoid conflicts uploading to Test PyPI
run: |
scripts/dev-versioning.sh "${{ steps.setenv.outputs.vernum }}"
git tag | xargs -L 1 | xargs git tag --delete
git tag "v${{ steps.setenv.outputs.vernum }}"
git checkout "tags/v${{ steps.setenv.outputs.vernum }}"
grep version pyproject.toml
- name: "Build with PDM backend"
run: |
pdm build
# Need to save the build environment for subsequent steps
mv buildvars.txt dist/buildvars.txt
### SIGNING ###
- name: "Sign packages with Sigstore"
uses: sigstore/gh-action-sigstore-python@v2
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: Development
path: dist/
### PUBLISH GITHUB ###
github:
name: "π¦ Test publish to GitHub"
needs:
- build
runs-on: ubuntu-latest
permissions:
# IMPORTANT: mandatory to publish artefacts
contents: write
steps:
- name: "β¬ Download build artefacts"
uses: actions/download-artifact@v4
with:
name: Development
path: dist/
- name: "Source environment variables"
id: setenv
run: |
if [ -f dist/buildvars.txt ]; then
source dist/buildvars.txt
echo "vernum=${vernum}" >> "$GITHUB_OUTPUT"
else
echo "Build environment variables could not be sourced"
fi
echo "tarball=$(ls dist/*.tgz)" >> "$GITHUB_OUTPUT"
echo "wheel=$(ls dist/*.whl)" >> "$GITHUB_OUTPUT"
- name: "π¦ Publish artefacts to GitHub"
# https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: ${{ steps.setenv.outputs.vernum }}
name: "Test/Development Build \
${{ steps.setenv.outputs.vernum }}"
# body_path: ${{ github.workspace }}/CHANGELOG.rst
files: |
dist/*.tar.gz
dist/*.whl
dist/*.sigstore
### PUBLISH TEST PYPI ###
testpypi:
name: "π¦ Test publish to PyPi"
needs:
- build
runs-on: ubuntu-latest
environment:
name: testpypi
permissions:
# IMPORTANT: mandatory for trusted publishing
id-token: write
steps:
- name: "β¬ Download build artefacts"
uses: actions/download-artifact@v4
with:
name: Development
path: dist/
- name: "Remove files unsupported by PyPi"
run: |
if [ -f dist/buildvars.txt ]; then
rm dist/buildvars.txt
fi
rm dist/*.sigstore
- name: Publish distribution to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
repository-url: https://test.pypi.org/legacy/