|
| 1 | +name: Python Release (uv) |
| 2 | + |
| 3 | +# Creates a GitHub release and publishes the package to PyPI using uv. Would commonly be one of two jobs along |
| 4 | +# with Python Deploy Docs in a repo workflow triggered by e.g. tagging a version. |
| 5 | +# |
| 6 | +# Requires the secret `PYPI_API_TOKEN`. |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_call: |
| 10 | + inputs: |
| 11 | + python-version: |
| 12 | + description: The python version to use |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + default: "3.10" |
| 16 | + uv-version: |
| 17 | + description: The uv version to use |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + default: "latest" |
| 21 | + working-directory: |
| 22 | + description: The working directory |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + default: . |
| 26 | + timeout-minutes: |
| 27 | + description: Maximum runtime in minutes |
| 28 | + required: false |
| 29 | + type: number |
| 30 | + default: 10 |
| 31 | + pypi-publish: |
| 32 | + description: Publish to PyPI or not |
| 33 | + required: false |
| 34 | + type: boolean |
| 35 | + default: true |
| 36 | + |
| 37 | + |
| 38 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 39 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 40 | +concurrency: |
| 41 | + group: "pages" |
| 42 | + cancel-in-progress: false |
| 43 | + |
| 44 | +jobs: |
| 45 | + release: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + timeout-minutes: ${{ inputs.timeout-minutes }} |
| 48 | + defaults: |
| 49 | + run: |
| 50 | + shell: bash |
| 51 | + working-directory: ${{ inputs.working-directory }} |
| 52 | + steps: |
| 53 | + |
| 54 | + - uses: actions/checkout@v5 |
| 55 | + |
| 56 | + - name: install_package |
| 57 | + uses: GNS-Science/nshm-github-actions/.github/actions/python-install-uv@main |
| 58 | + with: |
| 59 | + python-version: ${{ inputs.python-version }} |
| 60 | + uv-version: ${{ inputs.uv-version }} |
| 61 | + working-directory: ${{ inputs.working-directory }} |
| 62 | + |
| 63 | + #---------------------------------------------- |
| 64 | + # get version |
| 65 | + #---------------------------------------------- |
| 66 | + - name: Get version from tag |
| 67 | + id: tag_name |
| 68 | + run: | |
| 69 | + echo name=current_version::${GITHUB_REF#refs/tags/v} >> "$GITHUB_OUTPUT" |
| 70 | + shell: bash |
| 71 | + |
| 72 | + #---------------------------------------------- |
| 73 | + # get changelog entry |
| 74 | + #---------------------------------------------- |
| 75 | + - name: Get Changelog Entry |
| 76 | + id: changelog_reader |
| 77 | + uses: GNS-Science/changelog-reader-action@master |
| 78 | + with: |
| 79 | + validation_depth: 10 |
| 80 | + version: ${{ steps.tag_name.outputs.current_version }} |
| 81 | + path: ${{ inputs.working-directory }}/CHANGELOG.md |
| 82 | + |
| 83 | + #---------------------------------------------- |
| 84 | + # build wheels and tarball |
| 85 | + #---------------------------------------------- |
| 86 | + - name: Build wheels and source tarball |
| 87 | + run: >- |
| 88 | + uv build |
| 89 | +
|
| 90 | + - name: show temporary files |
| 91 | + run: >- |
| 92 | + ls -l |
| 93 | +
|
| 94 | + #---------------------------------------------- |
| 95 | + # create GitHub release |
| 96 | + #---------------------------------------------- |
| 97 | + - name: create github release |
| 98 | + id: create_release |
| 99 | + uses: GNS-Science/action-gh-release@master |
| 100 | + env: |
| 101 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + with: |
| 103 | + body: ${{ steps.changelog_reader.outputs.changes }} |
| 104 | + files: ${{ inputs.working-directory }}/dist/*.whl |
| 105 | + draft: false |
| 106 | + prerelease: false |
| 107 | + |
| 108 | + #---------------------------------------------- |
| 109 | + # publish to PyPI |
| 110 | + #---------------------------------------------- |
| 111 | + - name: publish to PyPI |
| 112 | + if: ${{ inputs.pypi-publish }} |
| 113 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 114 | + with: |
| 115 | + user: __token__ |
| 116 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 117 | + skip-existing: true |
0 commit comments