|
1 | | -name: Release to PyPI |
| 1 | +name: Publish to PyPI |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - '*' |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - deploy: |
10 | | - |
| 9 | + publish: |
11 | 10 | runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + id-token: write |
12 | 14 |
|
13 | 15 | steps: |
14 | | - - uses: actions/checkout@v2 |
15 | | - - name: Set up Python 3.9 |
16 | | - uses: actions/setup-python@v2 |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Python |
| 20 | + uses: actions/setup-python@v5 |
17 | 21 | with: |
18 | | - python-version: 3.9 |
19 | | - - name: Install dependencies for testing |
| 22 | + python-version: "3.11" |
| 23 | + |
| 24 | + - name: Install build and test dependencies |
20 | 25 | run: | |
21 | | - pip install pytest |
22 | | - pip install zarr |
23 | | - pip install setuptools wheel twine |
24 | | - pip install . |
25 | | - - name: Test core with pytest |
| 26 | + python -m pip install --upgrade pip |
| 27 | + python -m pip install hatch twine |
| 28 | +
|
| 29 | + - name: Run tests |
| 30 | + run: hatch run test:pytest -v |
| 31 | + |
| 32 | + - name: Build artifacts |
| 33 | + run: hatch build |
| 34 | + |
| 35 | + - name: Configure publish credentials |
| 36 | + id: publish-config |
| 37 | + env: |
| 38 | + EVENT_NAME: ${{ github.event_name }} |
| 39 | + RELEASE_NAME: ${{ github.event.release.name }} |
| 40 | + DEFAULT_USERNAME: ${{ secrets.twine_username }} |
| 41 | + DEFAULT_PASSWORD: ${{ secrets.twine_password }} |
| 42 | + TEST_USERNAME: ${{ secrets.twine_test_username }} |
| 43 | + TEST_PASSWORD: ${{ secrets.twine_test_password }} |
26 | 44 | run: | |
27 | | - pytest -v |
28 | | - - name: Publish on PyPI |
| 45 | + set -euo pipefail |
| 46 | +
|
| 47 | + repository="pypi" |
| 48 | + username="$DEFAULT_USERNAME" |
| 49 | + password="$DEFAULT_PASSWORD" |
| 50 | +
|
| 51 | + if [[ "${EVENT_NAME}" == "release" && -n "${RELEASE_NAME}" ]]; then |
| 52 | + if [[ "${RELEASE_NAME}" =~ ^[Tt]est ]]; then |
| 53 | + if [[ -z "${TEST_USERNAME}" || -z "${TEST_PASSWORD}" ]]; then |
| 54 | + echo "::error::Test PyPI credentials are required for releases starting with 'Test'" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + repository="testpypi" |
| 58 | + username="$TEST_USERNAME" |
| 59 | + password="$TEST_PASSWORD" |
| 60 | + fi |
| 61 | + fi |
| 62 | +
|
| 63 | + if [[ -z "${username}" || -z "${password}" ]]; then |
| 64 | + echo "::error::PyPI credentials are not configured" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + { |
| 69 | + echo "repository=${repository}" |
| 70 | + echo "username=${username}" |
| 71 | + echo "password=${password}" |
| 72 | + } >> "$GITHUB_OUTPUT" |
| 73 | +
|
| 74 | + - name: Publish distribution to PyPI |
29 | 75 | env: |
30 | | - TWINE_USERNAME: __token__ |
31 | | - TWINE_PASSWORD: ${{ secrets.AIND_PYPI_TOKEN }} |
| 76 | + TWINE_USERNAME: ${{ steps.publish-config.outputs.username }} |
| 77 | + TWINE_PASSWORD: ${{ steps.publish-config.outputs.password }} |
| 78 | + TWINE_REPOSITORY: ${{ steps.publish-config.outputs.repository }} |
32 | 79 | run: | |
33 | | - python setup.py sdist |
34 | | - twine upload dist/* |
| 80 | + twine upload --repository "${TWINE_REPOSITORY}" dist/* |
0 commit comments