|
| 1 | +name: "public/tidy3d/python-client-deploy" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_tag: |
| 7 | + description: 'Release tag to deploy (e.g., v2.10.0, v2.10.0rc1)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | + deploy_testpypi: |
| 12 | + description: 'Deploy to TestPyPI (recommended first step)' |
| 13 | + type: boolean |
| 14 | + default: false |
| 15 | + |
| 16 | + deploy_pypi: |
| 17 | + description: 'Deploy to production PyPI' |
| 18 | + type: boolean |
| 19 | + default: false |
| 20 | + |
| 21 | + deploy_aws: |
| 22 | + description: 'Deploy to AWS CodeArtifact' |
| 23 | + type: boolean |
| 24 | + default: false |
| 25 | + |
| 26 | + workflow_call: |
| 27 | + inputs: |
| 28 | + release_tag: |
| 29 | + description: 'Release tag to deploy' |
| 30 | + required: true |
| 31 | + type: string |
| 32 | + deploy_testpypi: |
| 33 | + type: boolean |
| 34 | + default: false |
| 35 | + deploy_pypi: |
| 36 | + type: boolean |
| 37 | + default: false |
| 38 | + deploy_aws: |
| 39 | + type: boolean |
| 40 | + default: false |
| 41 | + |
| 42 | +permissions: |
| 43 | + contents: read |
| 44 | + |
| 45 | +env: |
| 46 | + AWS_REGION: "us-east-1" |
| 47 | + |
| 48 | +jobs: |
| 49 | + validate-inputs: |
| 50 | + name: validate-deployment-inputs |
| 51 | + runs-on: ubuntu-latest |
| 52 | + outputs: |
| 53 | + release_tag: ${{ env.RELEASE_TAG }} |
| 54 | + deploy_testpypi: ${{ env.DEPLOY_TESTPYPI }} |
| 55 | + deploy_pypi: ${{ env.DEPLOY_PYPI }} |
| 56 | + deploy_aws: ${{ env.DEPLOY_AWS }} |
| 57 | + env: |
| 58 | + RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag || inputs.release_tag }} |
| 59 | + DEPLOY_TESTPYPI: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_testpypi || inputs.deploy_testpypi }} |
| 60 | + DEPLOY_PYPI: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_pypi || inputs.deploy_pypi }} |
| 61 | + DEPLOY_AWS: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_aws || inputs.deploy_aws }} |
| 62 | + steps: |
| 63 | + - name: validate-inputs |
| 64 | + run: | |
| 65 | + set -e |
| 66 | + echo "=== Deployment Configuration ===" |
| 67 | + echo "Release tag: $RELEASE_TAG" |
| 68 | + echo "Deploy to TestPyPI: $DEPLOY_TESTPYPI" |
| 69 | + echo "Deploy to PyPI: $DEPLOY_PYPI" |
| 70 | + echo "Deploy to AWS CodeArtifact: $DEPLOY_AWS" |
| 71 | + echo "" |
| 72 | + |
| 73 | + # Validate at least one target is selected |
| 74 | + if [[ "$DEPLOY_TESTPYPI" != "true" && "$DEPLOY_PYPI" != "true" && "$DEPLOY_AWS" != "true" ]]; then |
| 75 | + echo "Error: At least one deployment target must be selected" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + |
| 79 | + # Validate tag format |
| 80 | + TAG_REGEX='^v[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?$' |
| 81 | + if [[ ! "$RELEASE_TAG" =~ $TAG_REGEX ]]; then |
| 82 | + echo " Warning: Tag format doesn't match standard pattern v{major}.{minor}.{patch}[rc{num}]" |
| 83 | + echo " Tag: $RELEASE_TAG" |
| 84 | + echo " Continuing anyway..." |
| 85 | + fi |
| 86 | + |
| 87 | + echo "Validation passed" |
| 88 | +
|
| 89 | + build-package: |
| 90 | + name: build-distribution-package |
| 91 | + needs: validate-inputs |
| 92 | + runs-on: ubuntu-latest |
| 93 | + steps: |
| 94 | + - name: checkout-tag |
| 95 | + uses: actions/checkout@v4 |
| 96 | + with: |
| 97 | + ref: ${{ needs.validate-inputs.outputs.release_tag }} |
| 98 | + persist-credentials: false |
| 99 | + |
| 100 | + - name: setup-python |
| 101 | + uses: actions/setup-python@v5 |
| 102 | + with: |
| 103 | + python-version: '3.10' |
| 104 | + |
| 105 | + - name: install-poetry |
| 106 | + run: | |
| 107 | + python -m pip install --upgrade pip |
| 108 | + python -m pip install poetry |
| 109 | + |
| 110 | + - name: build-package |
| 111 | + env: |
| 112 | + RELEASE_TAG: ${{ needs.validate-inputs.outputs.release_tag }} |
| 113 | + run: | |
| 114 | + echo "Building package from tag ${RELEASE_TAG}..." |
| 115 | + poetry build |
| 116 | + echo "" |
| 117 | + echo "Build artifacts:" |
| 118 | + ls -lh dist/ |
| 119 | + echo "" |
| 120 | + echo "Package built successfully" |
| 121 | + |
| 122 | + - name: upload-artifacts |
| 123 | + uses: actions/upload-artifact@v4 |
| 124 | + with: |
| 125 | + name: dist-${{ needs.validate-inputs.outputs.release_tag }} |
| 126 | + path: dist/ |
| 127 | + retention-days: 7 |
| 128 | + |
| 129 | + deploy-testpypi: |
| 130 | + name: deploy-to-testpypi |
| 131 | + needs: [validate-inputs, build-package] |
| 132 | + if: needs.validate-inputs.outputs.deploy_testpypi == 'true' |
| 133 | + runs-on: ubuntu-latest |
| 134 | + steps: |
| 135 | + - name: download-artifacts |
| 136 | + uses: actions/download-artifact@v4 |
| 137 | + with: |
| 138 | + name: dist-${{ needs.validate-inputs.outputs.release_tag }} |
| 139 | + path: dist/ |
| 140 | + |
| 141 | + - name: setup-python |
| 142 | + uses: actions/setup-python@v5 |
| 143 | + with: |
| 144 | + python-version: '3.10' |
| 145 | + |
| 146 | + - name: install-twine |
| 147 | + run: | |
| 148 | + python -m pip install --upgrade pip |
| 149 | + python -m pip install twine |
| 150 | + |
| 151 | + - name: publish-to-testpypi |
| 152 | + env: |
| 153 | + TWINE_USERNAME: __token__ |
| 154 | + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 155 | + run: | |
| 156 | + echo "Publishing to TestPyPI..." |
| 157 | + # zizmor: ignore[use-trusted-publishing] |
| 158 | + python -m twine upload \ |
| 159 | + --repository-url https://test.pypi.org/legacy/ \ |
| 160 | + --verbose \ |
| 161 | + dist/* |
| 162 | + echo "" |
| 163 | + echo "Successfully published to TestPyPI" |
| 164 | + echo "View at: https://test.pypi.org/project/tidy3d/" |
| 165 | +
|
| 166 | + deploy-pypi: |
| 167 | + name: deploy-to-pypi |
| 168 | + needs: [validate-inputs, build-package, deploy-testpypi] |
| 169 | + # Run after TestPyPI succeeds (or is skipped if not selected) |
| 170 | + if: | |
| 171 | + always() && |
| 172 | + needs.validate-inputs.outputs.deploy_pypi == 'true' && |
| 173 | + needs.build-package.result == 'success' && |
| 174 | + (needs.deploy-testpypi.result == 'success' || needs.deploy-testpypi.result == 'skipped') |
| 175 | + runs-on: ubuntu-latest |
| 176 | + steps: |
| 177 | + - run: echo "hi" |
| 178 | + # - name: download-artifacts |
| 179 | + # uses: actions/download-artifact@v4 |
| 180 | + # with: |
| 181 | + # name: dist-${{ needs.validate-inputs.outputs.release_tag }} |
| 182 | + # path: dist/ |
| 183 | + |
| 184 | + # - name: setup-python |
| 185 | + # uses: actions/setup-python@v5 |
| 186 | + # with: |
| 187 | + # python-version: '3.10' |
| 188 | + |
| 189 | + # - name: install-twine |
| 190 | + # run: | |
| 191 | + # python -m pip install --upgrade pip |
| 192 | + # python -m pip install twine |
| 193 | + |
| 194 | + # - name: publish-to-pypi |
| 195 | + # env: |
| 196 | + # TWINE_USERNAME: __token__ |
| 197 | + # TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 198 | + # run: | |
| 199 | + # echo "Publishing to production PyPI..." |
| 200 | + # python -m twine upload \ |
| 201 | + # --repository pypi \ |
| 202 | + # --verbose \ |
| 203 | + # dist/* |
| 204 | + # echo "" |
| 205 | + # echo "Successfully published to PyPI" |
| 206 | + # echo " View at: https://pypi.org/project/tidy3d/" |
| 207 | + |
| 208 | + deploy-aws-codeartifact: |
| 209 | + name: deploy-to-aws-codeartifact |
| 210 | + needs: [validate-inputs, build-package] |
| 211 | + if: | |
| 212 | + always() && |
| 213 | + needs.validate-inputs.outputs.deploy_aws == 'true' && |
| 214 | + needs.build-package.result == 'success' |
| 215 | + runs-on: ubuntu-latest |
| 216 | + steps: |
| 217 | + - name: download-artifacts |
| 218 | + uses: actions/download-artifact@v4 |
| 219 | + with: |
| 220 | + name: dist-${{ needs.validate-inputs.outputs.release_tag }} |
| 221 | + path: dist/ |
| 222 | + |
| 223 | + - name: setup-python |
| 224 | + uses: actions/setup-python@v5 |
| 225 | + with: |
| 226 | + python-version: '3.10' |
| 227 | + |
| 228 | + - name: install-twine |
| 229 | + run: | |
| 230 | + python -m pip install --upgrade pip |
| 231 | + python -m pip install twine |
| 232 | + |
| 233 | + - name: configure-aws-credentials |
| 234 | + uses: aws-actions/configure-aws-credentials@v4 |
| 235 | + with: |
| 236 | + aws-region: ${{ env.AWS_REGION }} |
| 237 | + aws-access-key-id: ${{ secrets.AWS_CODEARTIFACT_ACCESS_KEY }} |
| 238 | + aws-secret-access-key: ${{ secrets.AWS_CODEARTIFACT_ACCESS_SECRET }} |
| 239 | + |
| 240 | + - name: configure-codeartifact-package |
| 241 | + run: | |
| 242 | + echo "Configuring CodeArtifact package settings..." |
| 243 | + aws codeartifact put-package-origin-configuration \ |
| 244 | + --domain flexcompute \ |
| 245 | + --repository pypi-releases \ |
| 246 | + --format pypi \ |
| 247 | + --package tidy3d \ |
| 248 | + --restrictions '{"publish":"ALLOW", "upstream":"BLOCK"}' |
| 249 | + |
| 250 | + - name: get-codeartifact-token |
| 251 | + run: | |
| 252 | + echo "Getting CodeArtifact authorization token..." |
| 253 | + CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \ |
| 254 | + --domain flexcompute \ |
| 255 | + --domain-owner 625554095313 \ |
| 256 | + --region us-east-1 \ |
| 257 | + --query authorizationToken \ |
| 258 | + --output text) |
| 259 | + echo "CODEARTIFACT_AUTH_TOKEN=${CODEARTIFACT_AUTH_TOKEN}" >> $GITHUB_ENV |
| 260 | + |
| 261 | + |
| 262 | + - name: publish-to-codeartifact |
| 263 | + env: |
| 264 | + TWINE_PASSWORD: ${{ env.CODEARTIFACT_AUTH_TOKEN }} |
| 265 | + run: | |
| 266 | + echo "Publishing to AWS CodeArtifact..." |
| 267 | + # zizmor: ignore[use-trusted-publishing] |
| 268 | + python -m twine upload \ |
| 269 | + --repository-url https://flexcompute-625554095313.d.codeartifact.us-east-1.amazonaws.com/pypi/pypi-releases/ \ |
| 270 | + --verbose \ |
| 271 | + -u aws \ |
| 272 | + -p "$TWINE_PASSWORD" \ |
| 273 | + dist/* |
| 274 | + echo "" |
| 275 | + echo "Successfully published to AWS CodeArtifact" |
| 276 | +
|
| 277 | + deployment-summary: |
| 278 | + name: deployment-summary |
| 279 | + needs: [validate-inputs, build-package, deploy-testpypi, deploy-pypi, deploy-aws-codeartifact] |
| 280 | + if: always() |
| 281 | + runs-on: ubuntu-latest |
| 282 | + steps: |
| 283 | + - name: generate-summary |
| 284 | + env: |
| 285 | + RELEASE_TAG: ${{ needs.validate-inputs.outputs.release_tag }} |
| 286 | + BUILD_RESULT: ${{ needs.build-package.result }} |
| 287 | + TESTPYPI_RESULT: ${{ needs.deploy-testpypi.result }} |
| 288 | + PYPI_RESULT: ${{ needs.deploy-pypi.result }} |
| 289 | + AWS_RESULT: ${{ needs.deploy-aws-codeartifact.result }} |
| 290 | + DEPLOY_TESTPYPI: ${{ needs.validate-inputs.outputs.deploy_testpypi }} |
| 291 | + DEPLOY_PYPI: ${{ needs.validate-inputs.outputs.deploy_pypi }} |
| 292 | + DEPLOY_AWS: ${{ needs.validate-inputs.outputs.deploy_aws }} |
| 293 | + run: | |
| 294 | + echo "=== Deployment Summary ===" |
| 295 | + echo "Release Tag: ${RELEASE_TAG}" |
| 296 | + echo "" |
| 297 | + echo "Build Package: ${BUILD_RESULT}" |
| 298 | + echo "TestPyPI: ${TESTPYPI_RESULT}" |
| 299 | + echo "PyPI: ${PYPI_RESULT}" |
| 300 | + echo "AWS CodeArtifact: ${AWS_RESULT}" |
| 301 | + echo "" |
| 302 | + |
| 303 | + # Check for failures |
| 304 | + if [[ "${BUILD_RESULT}" == "failure" ]]; then |
| 305 | + echo "Build failed" |
| 306 | + exit 1 |
| 307 | + fi |
| 308 | + |
| 309 | + # Check if any selected deployment failed |
| 310 | + failed=false |
| 311 | + if [[ "${DEPLOY_TESTPYPI}" == "true" && "${TESTPYPI_RESULT}" == "failure" ]]; then |
| 312 | + echo "TestPyPI deployment failed" |
| 313 | + failed=true |
| 314 | + fi |
| 315 | + if [[ "${DEPLOY_PYPI}" == "true" && "${PYPI_RESULT}" == "failure" ]]; then |
| 316 | + echo "PyPI deployment failed" |
| 317 | + failed=true |
| 318 | + fi |
| 319 | + if [[ "${DEPLOY_AWS}" == "true" && "${AWS_RESULT}" == "failure" ]]; then |
| 320 | + echo "AWS CodeArtifact deployment failed" |
| 321 | + failed=true |
| 322 | + fi |
| 323 | + |
| 324 | + if [[ "$failed" == "true" ]]; then |
| 325 | + exit 1 |
| 326 | + fi |
| 327 | + |
| 328 | + echo "All selected deployments completed successfully" |
0 commit comments