initial #2
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 to Homebrew | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-homebrew-main | |
| cancel-in-progress: false | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| env: | |
| HOMEBREW_TAP_OWNER: ${{ vars.HOMEBREW_TAP_OWNER || github.repository_owner }} | |
| HOMEBREW_TAP_NAME: ${{ vars.HOMEBREW_TAP_NAME || 'homebrew-tap' }} | |
| HOMEBREW_TAP_BRANCH: ${{ vars.HOMEBREW_TAP_BRANCH || 'main' }} | |
| HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: apps/sprout/go.mod | |
| cache: true | |
| - name: Test | |
| run: go test ./... | |
| working-directory: apps/sprout | |
| - name: Determine release tag | |
| id: tag | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| head_tag="$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true)" | |
| if [[ -n "$head_tag" ]]; then | |
| echo "tag=$head_tag" >> "$GITHUB_OUTPUT" | |
| echo "create_tag=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| latest_tag="" | |
| while IFS= read -r candidate; do | |
| if [[ "$candidate" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
| latest_tag="$candidate" | |
| break | |
| fi | |
| done < <(git tag --sort=-v:refname) | |
| if [[ -z "$latest_tag" ]]; then | |
| next_tag="v0.1.0" | |
| else | |
| [[ "$latest_tag" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] | |
| major="${BASH_REMATCH[1]}" | |
| minor="${BASH_REMATCH[2]}" | |
| patch="${BASH_REMATCH[3]}" | |
| next_tag="v${major}.${minor}.$((patch + 1))" | |
| fi | |
| echo "tag=$next_tag" >> "$GITHUB_OUTPUT" | |
| echo "create_tag=true" >> "$GITHUB_OUTPUT" | |
| - name: Validate Homebrew tap token | |
| if: env.HOMEBREW_TAP_GITHUB_TOKEN == '' | |
| run: | | |
| echo "HOMEBREW_TAP_GITHUB_TOKEN is required to update the Homebrew tap." >&2 | |
| exit 1 | |
| - name: Create and push tag | |
| if: steps.tag.outputs.create_tag == 'true' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| tag="${{ steps.tag.outputs.tag }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$tag" -m "Release $tag" | |
| git push origin "$tag" | |
| - name: Run GoReleaser | |
| uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| distribution: goreleaser | |
| version: "~> v2" | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |