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