|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] |
| 6 | + types: [completed] |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + name: Release |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + outputs: |
| 21 | + skipped: ${{ steps.changelog.outputs.skipped }} |
| 22 | + tag: ${{ steps.changelog.outputs.tag }} |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Conventional Changelog Action |
| 28 | + id: changelog |
| 29 | + uses: TriPSs/conventional-changelog-action@v6 |
| 30 | + with: |
| 31 | + github-token: ${{ secrets.github_token }} |
| 32 | + skip-commit: true |
| 33 | + skip-tag: true |
| 34 | + version-file: "pyproject.toml" |
| 35 | + version-path: "project.version" |
| 36 | + preset: "conventionalcommits" |
| 37 | + release-count: 0 |
| 38 | + tag-prefix: "v" |
| 39 | + output-file: "false" |
| 40 | + |
| 41 | + - name: Set version as environment variable |
| 42 | + run: echo "VERSION=${{ steps.changelog.outputs.version }}" >> $GITHUB_ENV |
| 43 | + |
| 44 | + - name: Update version in pyproject.toml |
| 45 | + run: sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml |
| 46 | + |
| 47 | + - name: Update version in Python file |
| 48 | + run: sed -i "s/__version__ = [\"'].*[\"']/__version__ = '$VERSION'/" pixiq/__init__.py |
| 49 | + |
| 50 | + - name: Commit all changes together |
| 51 | + if: ${{ steps.changelog.outputs.skipped == 'false' }} |
| 52 | + run: | |
| 53 | + git config user.name "github-actions[bot]" |
| 54 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 55 | + git add pyproject.toml pixiq/__init__.py |
| 56 | + git diff --cached --quiet || git commit -m "chore(release): v$VERSION [skip ci]" |
| 57 | + git tag -f "v$VERSION" |
| 58 | + git push |
| 59 | + git push --force origin "v$VERSION" |
| 60 | +
|
| 61 | + - name: Create Release |
| 62 | + uses: softprops/action-gh-release@v2 |
| 63 | + if: ${{ steps.changelog.outputs.skipped == 'false' }} |
| 64 | + with: |
| 65 | + tag_name: ${{ steps.changelog.outputs.tag }} |
| 66 | + name: ${{ steps.changelog.outputs.tag }} |
| 67 | + body: ${{ steps.changelog.outputs.clean_changelog }} |
| 68 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + |
| 70 | + build-and-publish: |
| 71 | + name: Build & Publish |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: release |
| 74 | + if: ${{ needs.release.outputs.skipped == 'false' }} |
| 75 | + permissions: |
| 76 | + contents: read |
| 77 | + steps: |
| 78 | + - name: Checkout exact release tag |
| 79 | + uses: actions/checkout@v4 |
| 80 | + with: |
| 81 | + fetch-depth: 0 |
| 82 | + ref: ${{ needs.release.outputs.tag }} |
| 83 | + |
| 84 | + - name: Install uv |
| 85 | + uses: astral-sh/setup-uv@v6 |
| 86 | + with: |
| 87 | + enable-cache: true |
| 88 | + |
| 89 | + - name: Set up Python |
| 90 | + uses: actions/setup-python@v5 |
| 91 | + with: |
| 92 | + python-version-file: "pyproject.toml" |
| 93 | + |
| 94 | + - name: Install packages |
| 95 | + run: uv sync --no-dev |
| 96 | + |
| 97 | + - name: Build package |
| 98 | + run: uv build |
| 99 | + |
| 100 | + - name: Publish to PyPI |
| 101 | + run: | |
| 102 | + if [ -n "${{ secrets.PYPI_API_TOKEN }}" ]; then |
| 103 | + uv publish --token "${{ secrets.PYPI_API_TOKEN }}" |
| 104 | + else |
| 105 | + echo "No PyPI token provided, skipping publish." |
| 106 | + fi |
0 commit comments