fix(release): push only new tags instead of all tags (#31) #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: [main] | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: release | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for changesets | |
| id: changesets | |
| run: | | |
| COUNT=$(find .sampo/changesets -name '*.md' 2>/dev/null | wc -l | tr -d ' ') | |
| echo "count=$COUNT" >> "$GITHUB_OUTPUT" | |
| - uses: astral-sh/setup-uv@v6 | |
| if: steps.changesets.outputs.count != '0' | |
| - run: uv sync --all-packages | |
| if: steps.changesets.outputs.count != '0' | |
| - name: Create Release Pull Request | |
| if: steps.changesets.outputs.count != '0' | |
| uses: bruits/sampo/crates/sampo-github-action@main | |
| with: | |
| command: auto | |
| pr-title: "chore(release): bump versions and changelogs" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| publish: | |
| name: Publish to PyPI | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: release | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| fetch-tags: true | |
| - uses: astral-sh/setup-uv@v6 | |
| - name: Check for version changes | |
| id: check | |
| run: | | |
| CHANGED=$(git diff HEAD~1 -- 'packages/*/pyproject.toml' | grep -c '^+version' || true) | |
| echo "changed=$CHANGED" >> "$GITHUB_OUTPUT" | |
| - name: Create tags and GitHub releases | |
| id: tag | |
| if: steps.check.outputs.changed != '0' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| NEW_PACKAGES="" | |
| for pkg in packages/*/; do | |
| name=$(grep '^name = ' "$pkg/pyproject.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| version=$(grep '^version = ' "$pkg/pyproject.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| tag="${name}@${version}" | |
| if ! git tag -l "$tag" | grep -q .; then | |
| git tag "$tag" | |
| git push origin "$tag" | |
| echo "Tagged $tag" | |
| NEW_PACKAGES="$NEW_PACKAGES $name" | |
| fi | |
| done | |
| # Create GitHub releases for each new tag | |
| for pkg in packages/*/; do | |
| name=$(grep '^name = ' "$pkg/pyproject.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| version=$(grep '^version = ' "$pkg/pyproject.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| tag="${name}@${version}" | |
| # Only create releases for packages that were newly tagged | |
| if echo "$NEW_PACKAGES" | grep -qw "$name"; then | |
| gh release create "$tag" --title "$tag" --generate-notes | |
| echo "Created release $tag" | |
| fi | |
| done | |
| echo "new_packages=$NEW_PACKAGES" >> "$GITHUB_OUTPUT" | |
| - name: Build changed packages | |
| if: steps.check.outputs.changed != '0' | |
| run: | | |
| for pkg_name in ${{ steps.tag.outputs.new_packages }}; do | |
| echo "Building $pkg_name..." | |
| uv build --package "$pkg_name" --out-dir dist/ | |
| done | |
| - name: Publish to PyPI | |
| if: steps.check.outputs.changed != '0' | |
| run: uv publish dist/* | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |