|
4 | 4 | push: |
5 | 5 | tags: |
6 | 6 | - 'v[0-9]+.[0-9]+.[0-9]+' |
7 | | - |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + environment: |
| 10 | + type: environment |
| 11 | + description: "Environment in which to execute the release process" |
| 12 | +env: |
| 13 | + UV_PYTHON_PREFERENCE: only-system |
| 14 | + # we do all UV syncing explicitly |
| 15 | + UV_NO_SYNC: "1" |
8 | 16 | jobs: |
9 | | - pypi-publish: |
10 | | - name: Build and upload release to PyPI |
| 17 | + extract-params: |
| 18 | + name: Determine release parameters |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: {} |
| 21 | + outputs: |
| 22 | + publish-env: ${{ steps.setenv.outputs.envname }} |
| 23 | + version: ${{ steps.getrelease.outputs.version }} |
| 24 | + steps: |
| 25 | + - id: setenv |
| 26 | + run: | |
| 27 | + if [[ $GITHUB_EVENT_NAME == 'workflow_dispatch' ]]; then |
| 28 | + echo "envname=${{ inputs.environment }}" >> "$GITHUB_OUTPUT" |
| 29 | + elif [[ $GITHUB_EVENT_NAME == 'push' ]]; then |
| 30 | + echo "envname=pypi" >> "$GITHUB_OUTPUT" |
| 31 | + else |
| 32 | + echo "Cannot run release workflow for trigger event $GITHUB_EVENT_NAME" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + cat "$GITHUB_OUTPUT" |
| 36 | + - name: Get version information |
| 37 | + id: getrelease |
| 38 | + run: | |
| 39 | + set -eo pipefail |
| 40 | +
|
| 41 | + VER_REGEX="v[0-9]\+\.[0-9]\+\..\+" |
| 42 | + if [[ "${GITHUB_REF:0:11}" != 'refs/tags/v' ]]; then |
| 43 | + echo "Cannot run release workflow for ref $GITHUB_REF, must be a tag starting with 'v'" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + VERSION=${GITHUB_REF:10} |
| 47 | +
|
| 48 | + if echo $VERSION | grep -q "$VER_REGEX"; then |
| 49 | + echo "version=${VERSION:1}" >> "$GITHUB_OUTPUT" |
| 50 | + else |
| 51 | + echo "Tag $VERSION does not follow v<version> naming scheme" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + - name: Generate release body |
| 56 | + run: | |
| 57 | + sed "s/:VERSION/$VERSION/g" < .github/release-template.md > release.md |
| 58 | + cat release.md |
| 59 | + env: |
| 60 | + VERSION: ${{ steps.getrelease.outputs.version }} |
| 61 | + - name: Upload release body |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: release-body |
| 65 | + path: release.md |
| 66 | + build-wheels: |
| 67 | + runs-on: ${{ matrix.os }} |
| 68 | + needs: [extract-params] |
| 69 | + strategy: |
| 70 | + fail-fast: false |
| 71 | + matrix: |
| 72 | + os: |
| 73 | + - ubuntu-latest |
| 74 | + - ubuntu-24.04-arm |
| 75 | + - windows-latest |
| 76 | + - macos-latest |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v4 |
| 79 | + - name: Setup Python |
| 80 | + uses: actions/setup-python@v5 |
| 81 | + - name: Build wheels |
| 82 | + |
| 83 | + - uses: actions/upload-artifact@v4 |
| 84 | + with: |
| 85 | + name: wheels-${{ matrix.os }}-${{ strategy.job-index }} |
| 86 | + path: ./wheelhouse/*.whl |
| 87 | + build-sdist: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + needs: [extract-params] |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + - name: Setup Python |
| 93 | + uses: actions/setup-python@v5 |
| 94 | + - name: Install uv |
| 95 | + uses: astral-sh/setup-uv@v4 |
| 96 | + with: |
| 97 | + enable-cache: true |
| 98 | + - name: Build source distribution |
| 99 | + run: uv build --sdist |
| 100 | + - uses: actions/upload-artifact@v4 |
| 101 | + with: |
| 102 | + name: sdist |
| 103 | + path: ./dist/*.tar.gz |
| 104 | + publish: |
| 105 | + name: Publish release artifacts |
| 106 | + needs: [extract-params, build-sdist, build-wheels] |
11 | 107 | runs-on: ubuntu-latest |
12 | | - environment: release |
| 108 | + environment: ${{ needs.extract-params.outputs.publish-env }} |
13 | 109 | permissions: |
| 110 | + # we use PyPI's trusted publisher model -> expose identity token |
14 | 111 | id-token: write |
| 112 | + # Needed to create GitHub releases |
| 113 | + contents: write |
15 | 114 | steps: |
16 | | - - uses: actions/checkout@v4 |
17 | | - - uses: actions/setup-python@v5 |
18 | | - - run: pip install build |
19 | | - - run: python -m build |
20 | | - - name: Publish package distributions to PyPI |
| 115 | + - name: Download wheels |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + pattern: wheels-* |
| 119 | + path: dist/ |
| 120 | + merge-multiple: 'true' |
| 121 | + - name: Download source distribution |
| 122 | + uses: actions/download-artifact@v4 |
| 123 | + with: |
| 124 | + name: sdist |
| 125 | + path: dist/ |
| 126 | + - name: Download release body |
| 127 | + uses: actions/download-artifact@v4 |
| 128 | + with: |
| 129 | + name: release-body |
| 130 | + path: release-body |
| 131 | + - name: Upload to PyPI |
21 | 132 | uses: pypa/gh-action-pypi-publish@release/v1 |
| 133 | + with: |
| 134 | + repository-url: ${{ vars.REPOSITORY_URL }} |
| 135 | + - name: Create GitHub release |
| 136 | + if: needs.extract-params.outputs.publish-env == 'pypi' && startsWith(github.ref, 'refs/tags/') |
| 137 | + uses: softprops/action-gh-release@v2 |
| 138 | + with: |
| 139 | + files: | |
| 140 | + dist/*.whl |
| 141 | + dist/*.tar.gz |
| 142 | + body_path: release-body/release.md |
| 143 | + fail_on_unmatched_files: true |
| 144 | + name: python-pkcs11 ${{ needs.extract-params.outputs.version }} |
0 commit comments