-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathtidy3d-python-client-deploy.yml
More file actions
241 lines (214 loc) · 7.84 KB
/
tidy3d-python-client-deploy.yml
File metadata and controls
241 lines (214 loc) · 7.84 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
name: "public/tidy3d/python-client-deploy"
on:
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag to deploy (e.g., v2.10.0, v2.10.0rc1)'
required: true
type: string
deploy_testpypi:
description: 'Deploy to TestPyPI (recommended first step)'
type: boolean
default: false
deploy_pypi:
description: 'Deploy to production PyPI'
type: boolean
default: false
workflow_call:
inputs:
release_tag:
description: 'Release tag to deploy'
required: true
type: string
deploy_testpypi:
type: boolean
default: false
deploy_pypi:
type: boolean
default: false
secrets:
TEST_PYPI_API_TOKEN:
description: 'API token for uploading to TestPyPI'
required: false
PYPI_API_TOKEN:
description: 'API token for uploading to PyPI'
required: false
permissions:
contents: read
jobs:
validate-inputs:
name: validate-deployment-inputs
runs-on: ubuntu-latest
outputs:
release_tag: ${{ env.RELEASE_TAG }}
deploy_testpypi: ${{ env.DEPLOY_TESTPYPI }}
deploy_pypi: ${{ env.DEPLOY_PYPI }}
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag || inputs.release_tag }}
DEPLOY_TESTPYPI: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_testpypi || inputs.deploy_testpypi }}
DEPLOY_PYPI: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_pypi || inputs.deploy_pypi }}
steps:
- name: validate-inputs
run: |
set -e
echo "=== Deployment Configuration ==="
echo "Release tag: $RELEASE_TAG"
echo "Deploy to TestPyPI: $DEPLOY_TESTPYPI"
echo "Deploy to PyPI: $DEPLOY_PYPI"
echo ""
# Validate at least one target is selected
if [[ "$DEPLOY_TESTPYPI" != "true" && "$DEPLOY_PYPI" != "true" ]]; then
echo "Error: At least one deployment target must be selected"
exit 1
fi
# Validate tag format
TAG_REGEX='^v[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+|\.dev[0-9]+)?$'
if [[ ! "$RELEASE_TAG" =~ $TAG_REGEX ]]; then
echo " Warning: Tag format doesn't match standard pattern v{major}.{minor}.{patch}[rc{num}|.dev{num}]"
echo " Tag: $RELEASE_TAG"
echo " Continuing anyway..."
fi
echo "Validation passed"
build-package:
name: build-distribution-package
needs: validate-inputs
runs-on: ubuntu-latest
steps:
- name: checkout-tag
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.validate-inputs.outputs.release_tag }}
persist-credentials: false
- name: setup-python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.10'
- name: install-poetry
run: |
python -m pip install --upgrade pip
python -m pip install poetry
- name: build-package
env:
RELEASE_TAG: ${{ needs.validate-inputs.outputs.release_tag }}
run: |
echo "Building package from tag ${RELEASE_TAG}..."
poetry build
echo ""
echo "Build artifacts:"
ls -lh dist/
echo ""
echo "Package built successfully"
- name: upload-artifacts
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: dist-${{ needs.validate-inputs.outputs.release_tag }}
path: dist/
retention-days: 7
deploy-testpypi:
name: deploy-to-testpypi
needs: [validate-inputs, build-package]
if: needs.validate-inputs.outputs.deploy_testpypi == 'true'
runs-on: ubuntu-latest
steps:
- name: download-artifacts
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: dist-${{ needs.validate-inputs.outputs.release_tag }}
path: dist/
- name: setup-python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.10'
- name: install-twine
run: |
python -m pip install --upgrade pip
python -m pip install twine
- name: publish-to-testpypi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: | # zizmor: ignore[use-trusted-publishing]
echo "Publishing to TestPyPI..."
python -m twine upload \
--repository-url https://test.pypi.org/legacy/ \
--verbose \
dist/*
echo ""
echo "Successfully published to TestPyPI"
echo "View at: https://test.pypi.org/project/tidy3d/"
deploy-pypi:
name: deploy-to-pypi
needs: [validate-inputs, build-package]
if: |
always() &&
needs.validate-inputs.outputs.deploy_pypi == 'true' &&
needs.build-package.result == 'success'
runs-on: ubuntu-latest
steps:
- name: download-artifacts
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: dist-${{ needs.validate-inputs.outputs.release_tag }}
path: dist/
- name: setup-python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.10'
- name: install-twine
run: |
python -m pip install --upgrade pip
python -m pip install twine
- name: publish-to-pypi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: | # zizmor: ignore[use-trusted-publishing]
echo "Publishing to production PyPI..."
python -m twine upload \
--repository pypi \
--verbose \
dist/*
echo ""
echo "Successfully published to PyPI"
echo "View at: https://pypi.org/project/tidy3d/"
deployment-summary:
name: deployment-summary
needs: [validate-inputs, build-package, deploy-testpypi, deploy-pypi]
if: always()
runs-on: ubuntu-latest
steps:
- name: generate-summary
env:
RELEASE_TAG: ${{ needs.validate-inputs.outputs.release_tag }}
BUILD_RESULT: ${{ needs.build-package.result }}
TESTPYPI_RESULT: ${{ needs.deploy-testpypi.result }}
PYPI_RESULT: ${{ needs.deploy-pypi.result }}
DEPLOY_TESTPYPI: ${{ needs.validate-inputs.outputs.deploy_testpypi }}
DEPLOY_PYPI: ${{ needs.validate-inputs.outputs.deploy_pypi }}
run: |
echo "=== Deployment Summary ==="
echo "Release Tag: ${RELEASE_TAG}"
echo ""
echo "Build Package: ${BUILD_RESULT}"
echo "TestPyPI: ${TESTPYPI_RESULT}"
echo "PyPI: ${PYPI_RESULT}"
echo ""
# Check for failures
if [[ "${BUILD_RESULT}" == "failure" ]]; then
echo "Build failed"
exit 1
fi
# Check if any selected deployment failed
failed=false
if [[ "${DEPLOY_TESTPYPI}" == "true" && "${TESTPYPI_RESULT}" == "failure" ]]; then
echo "TestPyPI deployment failed"
failed=true
fi
if [[ "${DEPLOY_PYPI}" == "true" && "${PYPI_RESULT}" == "failure" ]]; then
echo "PyPI deployment failed"
failed=true
fi
if [[ "$failed" == "true" ]]; then
exit 1
fi
echo "All selected deployments completed successfully"