Release #25
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: | |
| workflow_run: | |
| workflows: [CI] | |
| types: [completed] | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.head_branch == 'main' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| - name: Check for Go changes | |
| id: changes | |
| run: | | |
| PREV_SHA=${{ github.event.workflow_run.head_commit.id }}~1 | |
| if git diff --name-only "$PREV_SHA" HEAD | grep -qE '\.go$|^go\.(mod|sum)$|\.goreleaser\.yml$'; then | |
| echo "release=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "release=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Generate CalVer tag | |
| if: steps.changes.outputs.release == 'true' | |
| id: version | |
| run: | | |
| # Semver-compatible CalVer: YYYY.M.D (no leading zeros). | |
| YEAR=$(date -u +%Y) | |
| MONTH=$(date -u +%-m) | |
| DAY=$(date -u +%-d) | |
| BASE="${YEAR}.${MONTH}.${DAY}" | |
| # If this date already has a tag, append a pre-release sequence. | |
| if git rev-parse "${BASE}" >/dev/null 2>&1; then | |
| LAST=$(git tag -l "${BASE}-*" | sed "s/${BASE}-//" | sort -n | tail -1) | |
| SEQ=$(( ${LAST:-1} + 1 )) | |
| TAG="${BASE}-${SEQ}" | |
| else | |
| TAG="${BASE}" | |
| fi | |
| echo "tag=${TAG}" >> "$GITHUB_OUTPUT" | |
| - name: Create and push tag | |
| if: steps.changes.outputs.release == 'true' | |
| run: | | |
| git tag ${{ steps.version.outputs.tag }} | |
| git push origin ${{ steps.version.outputs.tag }} | |
| - name: Run GoReleaser | |
| if: steps.changes.outputs.release == 'true' | |
| uses: goreleaser/goreleaser-action@v7 | |
| with: | |
| version: '~> v2' | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |