| 1 |
--- |
| 2 |
name: Build & upload PyPI package |
| 3 |
|
| 4 |
on: |
| 5 |
push: |
| 6 |
branches: [main] |
| 7 |
tags: ["*"] |
| 8 |
release: |
| 9 |
types: |
| 10 |
- published |
| 11 |
workflow_dispatch: |
| 12 |
|
| 13 |
|
| 14 |
jobs: |
| 15 |
# Always build & lint package. |
| 16 |
build-package: |
| 17 |
name: Build & verify package |
| 18 |
runs-on: ubuntu-latest |
| 19 |
permissions: |
| 20 |
attestations: write |
| 21 |
id-token: write |
| 22 |
|
| 23 |
steps: |
| 24 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 25 |
with: |
| 26 |
fetch-depth: 0 |
| 27 |
persist-credentials: false |
| 28 |
|
| 29 |
- uses: hynek/build-and-inspect-python-package@efb823f52190ad02594531168b7a2d5790e66516 # v2.14.0 |
| 30 |
with: |
| 31 |
attest-build-provenance-github: 'true' |
| 32 |
|
| 33 |
|
| 34 |
# Upload to Test PyPI on every commit on main. |
| 35 |
release-test-pypi: |
| 36 |
name: Publish in-dev package to test.pypi.org |
| 37 |
environment: release-test-pypi |
| 38 |
if: github.repository_owner == 'python-attrs' && github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 39 |
runs-on: ubuntu-latest |
| 40 |
needs: build-package |
| 41 |
|
| 42 |
permissions: |
| 43 |
id-token: write |
| 44 |
|
| 45 |
steps: |
| 46 |
- name: Download packages built by build-and-inspect-python-package |
| 47 |
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 48 |
with: |
| 49 |
name: Packages |
| 50 |
path: dist |
| 51 |
|
| 52 |
- name: Upload package to Test PyPI |
| 53 |
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
| 54 |
with: |
| 55 |
attestations: true |
| 56 |
repository-url: https://test.pypi.org/legacy/ |
| 57 |
|
| 58 |
|
| 59 |
# Upload to real PyPI on GitHub Releases. |
| 60 |
release-pypi: |
| 61 |
name: Publish released package to pypi.org |
| 62 |
environment: release-pypi |
| 63 |
if: github.repository_owner == 'python-attrs' && github.event.action == 'published' |
| 64 |
runs-on: ubuntu-latest |
| 65 |
needs: build-package |
| 66 |
|
| 67 |
permissions: |
| 68 |
id-token: write |
| 69 |
|
| 70 |
steps: |
| 71 |
- name: Download packages built by build-and-inspect-python-package |
| 72 |
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 73 |
with: |
| 74 |
name: Packages |
| 75 |
path: dist |
| 76 |
|
| 77 |
- name: Upload package to PyPI |
| 78 |
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
| 79 |
with: |
| 80 |
attestations: true |