|
| 1 | +name: publish distributions |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + tags: |
| 7 | + - '[0-9]+.[0-9]+' |
| 8 | + - '[0-9]+.[0-9]+.[0-9]+' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + release: |
| 13 | + types: [published] |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + publish: |
| 17 | + type: choice |
| 18 | + description: 'Publish to TestPyPI?' |
| 19 | + options: |
| 20 | + - false |
| 21 | + - true |
| 22 | + |
| 23 | +concurrency: |
| 24 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 25 | + cancel-in-progress: true |
| 26 | + |
| 27 | +jobs: |
| 28 | + build: |
| 29 | + name: Build Python distribution |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: '3.x' |
| 41 | + |
| 42 | + - name: Install python-build and twine |
| 43 | + run: | |
| 44 | + python -m pip install --upgrade pip setuptools |
| 45 | + python -m pip install build twine |
| 46 | + python -m pip list |
| 47 | +
|
| 48 | + - name: Build a wheel and a sdist |
| 49 | + run: | |
| 50 | + PYTHONWARNINGS=error,default::DeprecationWarning python -m build . |
| 51 | +
|
| 52 | + - name: Verify the distribution |
| 53 | + run: twine check --strict dist/* |
| 54 | + |
| 55 | + - name: List contents of sdist |
| 56 | + run: python -m tarfile --list dist/array_api_strict-*.tar.gz |
| 57 | + |
| 58 | + - name: List contents of wheel |
| 59 | + run: python -m zipfile --list dist/array_api_strict-*.whl |
| 60 | + |
| 61 | + - name: Upload distribution artifact |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: dist-artifact |
| 65 | + path: dist |
| 66 | + |
| 67 | + publish: |
| 68 | + name: Publish Python distribution to (Test)PyPI |
| 69 | + if: github.event_name != 'pull_request' && github.repository == 'data-apis/array-api-strict' |
| 70 | + needs: build |
| 71 | + runs-on: ubuntu-latest |
| 72 | + # Mandatory for publishing with a trusted publisher |
| 73 | + # c.f. https://docs.pypi.org/trusted-publishers/using-a-publisher/ |
| 74 | + permissions: |
| 75 | + id-token: write |
| 76 | + contents: write |
| 77 | + # Restrict to the environment set for the trusted publisher |
| 78 | + environment: |
| 79 | + name: publish-package |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Download distribution artifact |
| 83 | + uses: actions/download-artifact@v4 |
| 84 | + with: |
| 85 | + name: dist-artifact |
| 86 | + path: dist |
| 87 | + |
| 88 | + - name: List all files |
| 89 | + run: ls -lh dist |
| 90 | + |
| 91 | + - name: Publish distribution 📦 to Test PyPI |
| 92 | + # Publish to TestPyPI on tag events of if manually triggered |
| 93 | + # Compare to 'true' string as booleans get turned into strings in the console |
| 94 | + if: >- |
| 95 | + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) |
| 96 | + || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true') |
| 97 | + |
| 98 | + with: |
| 99 | + repository-url: https://test.pypi.org/legacy/ |
| 100 | + print-hash: true |
| 101 | + |
| 102 | + - name: Create GitHub Release from a Tag |
| 103 | + uses: softprops/action-gh-release@v1 |
| 104 | + if: startsWith(github.ref, 'refs/tags/') |
| 105 | + with: |
| 106 | + files: dist/* |
| 107 | + |
| 108 | + - name: Publish distribution 📦 to PyPI |
| 109 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 110 | + |
| 111 | + with: |
| 112 | + print-hash: true |
0 commit comments