-
Notifications
You must be signed in to change notification settings - Fork 79
144 lines (141 loc) · 4.39 KB
/
release.yml
File metadata and controls
144 lines (141 loc) · 4.39 KB
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
name: Publish release to PyPI
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
environment:
type: environment
description: "Environment in which to execute the release process"
env:
UV_PYTHON_PREFERENCE: only-system
# we do all UV syncing explicitly
UV_NO_SYNC: "1"
jobs:
extract-params:
name: Determine release parameters
runs-on: ubuntu-latest
permissions: {}
outputs:
publish-env: ${{ steps.setenv.outputs.envname }}
version: ${{ steps.getrelease.outputs.version }}
steps:
- id: setenv
run: |
if [[ $GITHUB_EVENT_NAME == 'workflow_dispatch' ]]; then
echo "envname=${{ inputs.environment }}" >> "$GITHUB_OUTPUT"
elif [[ $GITHUB_EVENT_NAME == 'push' ]]; then
echo "envname=pypi" >> "$GITHUB_OUTPUT"
else
echo "Cannot run release workflow for trigger event $GITHUB_EVENT_NAME"
exit 1
fi
cat "$GITHUB_OUTPUT"
- name: Get version information
id: getrelease
run: |
set -eo pipefail
VER_REGEX="v[0-9]\+\.[0-9]\+\..\+"
if [[ "${GITHUB_REF:0:11}" != 'refs/tags/v' ]]; then
echo "Cannot run release workflow for ref $GITHUB_REF, must be a tag starting with 'v'"
exit 1
fi
VERSION=${GITHUB_REF:10}
if echo $VERSION | grep -q "$VER_REGEX"; then
echo "version=${VERSION:1}" >> "$GITHUB_OUTPUT"
else
echo "Tag $VERSION does not follow v<version> naming scheme"
exit 1
fi
- uses: actions/checkout@v6
- name: Generate release body
run: |
sed "s/:VERSION/$VERSION/g" < .github/release-template.md > release.md
cat release.md
env:
VERSION: ${{ steps.getrelease.outputs.version }}
- name: Upload release body
uses: actions/upload-artifact@v4
with:
name: release-body
path: release.md
build-wheels:
runs-on: ${{ matrix.os }}
needs: [extract-params]
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
- windows-latest
- macos-14
steps:
- uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
- name: Build wheels
uses: pypa/cibuildwheel@v3.3.0
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
build-sdist:
runs-on: ubuntu-latest
needs: [extract-params]
steps:
- uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Build source distribution
run: uv build --sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: ./dist/*.tar.gz
publish:
name: Publish release artifacts
needs: [extract-params, build-sdist, build-wheels]
runs-on: ubuntu-latest
environment: ${{ needs.extract-params.outputs.publish-env }}
permissions:
# we use PyPI's trusted publisher model -> expose identity token
id-token: write
# Needed to create GitHub releases
contents: write
steps:
- name: Download wheels
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist/
merge-multiple: 'true'
- name: Download source distribution
uses: actions/download-artifact@v4
with:
name: sdist
path: dist/
- name: Download release body
uses: actions/download-artifact@v4
with:
name: release-body
path: release-body
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ vars.REPOSITORY_URL }}
- name: Create GitHub release
if: needs.extract-params.outputs.publish-env == 'pypi' && startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
files: |
dist/*.whl
dist/*.tar.gz
body_path: release-body/release.md
fail_on_unmatched_files: true
name: v${{ needs.extract-params.outputs.version }}