|
| 1 | +name: Python uv Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # required for GitHub Release |
| 10 | + id-token: write # required for PyPI Trusted Publishing |
| 11 | + actions: write # required for tag deletion |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Check out code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python 3.12 |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: '3.12' |
| 25 | + |
| 26 | + - name: Install uv |
| 27 | + run: | |
| 28 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 29 | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
| 30 | +
|
| 31 | + - name: Sync dependencies |
| 32 | + run: uv sync --all-groups |
| 33 | + |
| 34 | + - name: Run tests |
| 35 | + id: test |
| 36 | + continue-on-error: true |
| 37 | + run: uv run pytest |
| 38 | + |
| 39 | + - name: Delete tag on failure |
| 40 | + if: steps.test.conclusion == 'failure' |
| 41 | + run: | |
| 42 | + echo "Tests failed. Deleting tag ${GITHUB_REF#refs/tags/}..." |
| 43 | + git config --global user.name "github-actions[bot]" |
| 44 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 45 | + git push --delete origin ${GITHUB_REF#refs/tags/} |
| 46 | + exit 1 |
| 47 | +
|
| 48 | + - name: Build package |
| 49 | + run: uv build |
| 50 | + |
| 51 | + - name: Build changelog |
| 52 | + id: gen_changelog |
| 53 | + uses: mikepenz/release-changelog-builder-action@v5 |
| 54 | + with: |
| 55 | + failOnError: "true" |
| 56 | + configuration: .github/workflows/release_config.json |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + |
| 60 | + - name: Publish release on GitHub |
| 61 | + uses: softprops/action-gh-release@v1 |
| 62 | + with: |
| 63 | + files: dist/* |
| 64 | + body: ${{ steps.gen_changelog.outputs.changelog }} |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Publish to PyPI via Trusted Publishing |
| 69 | + run: uv publish |
0 commit comments