|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + python-version: |
| 7 | + description: "Python version for build" |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: "3.13" |
| 11 | + tag-name: |
| 12 | + description: "Git tag to release" |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + publish-to-pypi: |
| 16 | + description: "Whether to publish to PyPI (true/false)" |
| 17 | + required: false |
| 18 | + type: boolean |
| 19 | + default: false |
| 20 | + secrets: |
| 21 | + repo-token: |
| 22 | + description: "GitHub token for release creation" |
| 23 | + required: true |
| 24 | + pypi-token: |
| 25 | + description: "PyPI API token" |
| 26 | + required: false |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: write |
| 30 | + |
| 31 | +jobs: |
| 32 | + build-release-publish: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + # only run on a tag push, or on a manual dispatch *where* the user has |
| 35 | + # selected a tag ref (i.e. github.ref starts with refs/tags/) |
| 36 | + if: startsWith(github.ref, 'refs/tags/') |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + # on push this is already the tag ref; on dispatch you must choose |
| 42 | + # the tag in the UI so github.ref is the tag |
| 43 | + ref: ${{ github.ref }} |
| 44 | + fetch-depth: 0 |
| 45 | + - name: Set up Python |
| 46 | + uses: actions/setup-python@v5 |
| 47 | + with: |
| 48 | + python-version: ${{ inputs.python-version }} |
| 49 | + - name: Install uv |
| 50 | + uses: astral-sh/setup-uv@v6 |
| 51 | + with: |
| 52 | + python-version: ${{ inputs.python-version }} |
| 53 | + enable-cache: true |
| 54 | + - name: Install project |
| 55 | + run: uv sync |
| 56 | + - name: Build |
| 57 | + run: uv build |
| 58 | + - name: Verify artifacts |
| 59 | + run: ls -la dist/ |
| 60 | + - name: Create GitHub release |
| 61 | + uses: softprops/action-gh-release@v2 |
| 62 | + with: |
| 63 | + tag_name: ${{ inputs.tag-name }} |
| 64 | + name: Release ${{ inputs.tag-name }} |
| 65 | + generate_release_notes: true |
| 66 | + files: | |
| 67 | + dist/*.tar.gz |
| 68 | + dist/*.whl |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ secrets.repo-token }} |
| 71 | + - name: Publish to PyPI |
| 72 | + if: ${{ inputs.publish-to-pypi }} |
| 73 | + env: |
| 74 | + pypi_token: ${{ secrets.pypi-token }} |
| 75 | + run: | |
| 76 | + if [ -z "$pypi_token" ]; then |
| 77 | + echo "No PyPI token provided, skipping publish." |
| 78 | + else |
| 79 | + uv publish --token "$pypi_token" |
| 80 | + fi |
0 commit comments