-
Notifications
You must be signed in to change notification settings - Fork 31
187 lines (160 loc) · 4.72 KB
/
publish.yml
File metadata and controls
187 lines (160 loc) · 4.72 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Publish to PyPI
on:
release:
types: [published]
pull_request:
paths:
- 'pyproject.toml'
- 'bluebox/**'
- '.github/workflows/publish.yml'
push:
branches: [main]
paths:
- 'pyproject.toml'
- 'bluebox/**'
- '.github/workflows/publish.yml'
workflow_dispatch:
jobs:
# -------------------------
# PR + Release: build & test
# -------------------------
build:
name: Build & test wheel
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build deps
run: |
python -m pip install --upgrade pip
pip install build hatchling
- name: Build package
run: python -m build
- name: Extract version
id: get-version
run: |
VERSION=$(ls dist/*.whl | sed 's/.*bluebox_sdk-\(.*\)-py3.*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Verify wheel installs
run: |
pip install dist/*.whl
python -c "import bluebox"
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# -------------------------
# Release only: TestPyPI
# -------------------------
publish-testpypi:
name: Publish to TestPyPI
if: github.event_name == 'release'
needs: build
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
outputs:
test_version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build deps
run: |
python -m pip install --upgrade pip
pip install build hatchling
- name: Add dev suffix for TestPyPI
run: |
TIMESTAMP=$(date +%Y%m%d%H%M%S)
VERSION=$(python - <<'PY'
import tomllib
print(tomllib.load(open("pyproject.toml","rb"))["project"]["version"])
PY
)
DEV_VERSION="${VERSION}.dev${TIMESTAMP}"
sed -i "s/version = \"$VERSION\"/version = \"$DEV_VERSION\"/" pyproject.toml
echo "DEV_VERSION=$DEV_VERSION" >> $GITHUB_ENV
- name: Clean dist
run: rm -rf dist
- name: Build TestPyPI artifacts
run: python -m build
- name: Extract TestPyPI version
id: get-version
run: |
VERSION=$(ls dist/*.whl | sed 's/.*bluebox_sdk-\(.*\)-py3.*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
test-install-testpypi:
name: Verify install from TestPyPI
if: github.event_name == 'release'
needs: publish-testpypi
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
run: pip install uv
- name: Install from TestPyPI
run: |
VERSION="${{ needs.publish-testpypi.outputs.test_version }}"
for i in {1..10}; do
# Package from TestPyPI, deps from PyPI
if uv pip install --system --pre \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
--index-strategy unsafe-best-match \
"bluebox-sdk==$VERSION"; then
python -c "import bluebox"
exit 0
fi
sleep 30
done
exit 1
# -------------------------
# Release only: PyPI
# -------------------------
publish-pypi:
name: Publish to PyPI
if: github.event_name == 'release'
needs: test-install-testpypi
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
test-install-pypi:
name: Verify install from PyPI
if: github.event_name == 'release'
needs: [build, publish-pypi]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
run: pip install uv
- name: Install from PyPI
run: |
VERSION="${{ needs.build.outputs.version }}"
for i in {1..10}; do
if uv pip install --system "bluebox-sdk==$VERSION"; then
python -c "import bluebox"
exit 0
fi
sleep 30
done
exit 1