|
| 1 | +# Requires |
| 2 | +# - pyproject.toml |
| 3 | +name: Package publication for Python only projects |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + pyproject-directory: |
| 9 | + description: 'Directory to find pyproject.toml' |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + default: '.' |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-distribution-artifacts: |
| 16 | + runs-on: ubuntu-24.04 |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4.2.2 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + submodules: true |
| 22 | + |
| 23 | + - name: Install uv and set the python version |
| 24 | + uses: astral-sh/setup-uv@v6 |
| 25 | + with: |
| 26 | + python-version: "3.12" |
| 27 | + version: "0.8.15" |
| 28 | + |
| 29 | + - name: Build artifacts |
| 30 | + working-directory: ${{ inputs.pyproject-directory }} |
| 31 | + run: uv build |
| 32 | + |
| 33 | + - name: Upload artifacts |
| 34 | + working-directory: ${{ inputs.pyproject-directory }} |
| 35 | + uses: actions/upload-artifact@v6.0.0 |
| 36 | + with: |
| 37 | + name: dist |
| 38 | + path: dist/ |
| 39 | + if-no-files-found: error |
| 40 | + |
| 41 | + publish: |
| 42 | + runs-on: ubuntu-24.04 |
| 43 | + environment: release |
| 44 | + needs: [ 'build-distribution-artifacts' ] |
| 45 | + permissions: |
| 46 | + id-token: write |
| 47 | + steps: |
| 48 | + - name: Download artifacts |
| 49 | + working-directory: ${{ inputs.pyproject-directory }} |
| 50 | + uses: actions/download-artifact@v7.0.0 |
| 51 | + with: |
| 52 | + name: dist |
| 53 | + path: dist |
| 54 | + |
| 55 | + - name: Show artifacts |
| 56 | + working-directory: ${{ inputs.pyproject-directory }} |
| 57 | + run: ls -lah dist |
| 58 | + |
| 59 | + - name: Publish distribution to Test PyPI |
| 60 | + working-directory: ${{ inputs.pyproject-directory }} |
| 61 | + if: github.event_name == 'push' && github.ref_name == 'test-publish' |
| 62 | + uses: pypa/gh-action-pypi-publish@v1.13.0 |
| 63 | + with: |
| 64 | + repository-url: https://test.pypi.org/legacy/ |
| 65 | + verbose: true |
| 66 | + |
| 67 | + - name: Publish distribution to PRODUCTION PyPI |
| 68 | + working-directory: ${{ inputs.pyproject-directory }} |
| 69 | + if: github.event_name == 'release' |
| 70 | + uses: pypa/gh-action-pypi-publish@v1.13.0 |
0 commit comments