chore: add prek pre-commit hooks #8
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 | |
| tags: | |
| - "v[0-9]*" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| prepare-release-pr: | |
| name: Prepare release PR | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| TAG="${GITHUB_REF#refs/tags/}" | |
| VERSION="${TAG#v}" | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Update version.go | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| sed -i "s/const Version = \".*\"/const Version = \"$VERSION\"/" version.go | |
| - name: Generate changelog | |
| uses: orhun/git-cliff-action@v4 | |
| with: | |
| config: cliff.toml | |
| args: --tag ${{ steps.version.outputs.tag }} | |
| env: | |
| OUTPUT: CHANGELOG.md | |
| - name: Check for modifications | |
| id: changes | |
| run: | | |
| if git diff --quiet; then | |
| echo "changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create release PR | |
| if: steps.changes.outputs.changes == 'true' | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| base: main | |
| commit-message: "chore(release): bump version to ${{ steps.version.outputs.version }}" | |
| branch: release/${{ steps.version.outputs.tag }} | |
| title: "chore(release): ${{ steps.version.outputs.tag }}" | |
| body: | | |
| ## Release `${{ steps.version.outputs.tag }}` | |
| Automated release preparation triggered by tag push. | |
| ### Changes | |
| - Update `version.go` to `${{ steps.version.outputs.version }}` | |
| - Refresh `CHANGELOG.md` | |
| ### What happens after merge? | |
| Merging this PR will automatically: | |
| 1. Create a GitHub Release for `${{ steps.version.outputs.tag }}` | |
| 2. Update the release tag to point to the merge commit | |
| add-paths: | | |
| version.go | |
| CHANGELOG.md | |
| labels: release | |
| publish-release: | |
| name: Publish GitHub release | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect release commit | |
| id: release | |
| run: | | |
| set -euo pipefail | |
| BEFORE="${{ github.event.before }}" | |
| AFTER="${{ github.sha }}" | |
| if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then | |
| BEFORE="$(git rev-parse "${AFTER}^" 2>/dev/null || echo "")" | |
| fi | |
| if [ -z "$BEFORE" ]; then | |
| echo "run=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| if git diff --quiet "$BEFORE" "$AFTER" -- version.go; then | |
| echo "run=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| VERSION=$(sed -n 's/^const Version = "\(.*\)"/\1/p' version.go) | |
| if [ -z "$VERSION" ]; then | |
| echo "Unable to determine version from version.go" >&2 | |
| exit 1 | |
| fi | |
| echo "run=true" >> $GITHUB_OUTPUT | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | |
| - name: Configure git | |
| if: steps.release.outputs.run == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Update release tag | |
| if: steps.release.outputs.run == 'true' | |
| run: | | |
| TAG="${{ steps.release.outputs.tag }}" | |
| git fetch origin --tags | |
| git tag -a "$TAG" -f -m "Release $TAG" | |
| git push origin "$TAG" --force | |
| - name: Get previous tag | |
| if: steps.release.outputs.run == 'true' | |
| id: prev_tag | |
| run: | | |
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| if: steps.release.outputs.run == 'true' | |
| id: changelog | |
| uses: orhun/git-cliff-action@v4 | |
| with: | |
| config: cliff.toml | |
| args: >- | |
| ${{ steps.prev_tag.outputs.tag && format('{0}..{1}', steps.prev_tag.outputs.tag, steps.release.outputs.tag) || steps.release.outputs.tag }} | |
| env: | |
| OUTPUT: /tmp/RELEASE_CHANGELOG.md | |
| - name: Create GitHub Release | |
| if: steps.release.outputs.run == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.release.outputs.tag }} | |
| body: ${{ steps.changelog.outputs.content }} | |
| draft: false | |
| prerelease: ${{ contains(steps.release.outputs.tag, '-alpha') || contains(steps.release.outputs.tag, '-beta') || contains(steps.release.outputs.tag, '-rc') }} | |
| generate_release_notes: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |