ci: auto-update homebrew formula on release #9
Workflow file for this run
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: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: write | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| goreleaser: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| version: "~> v2" | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| update-formula: | |
| runs-on: ubuntu-latest | |
| needs: goreleaser | |
| steps: | |
| - name: Update Homebrew formula | |
| env: | |
| TAG: ${{ github.ref_name }} | |
| GH_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${TAG#v}" | |
| URL="https://github.com/WarriorsCode/deck/archive/refs/tags/${TAG}.tar.gz" | |
| SHA256=$(curl -sL "$URL" | sha256sum | cut -d' ' -f1) | |
| FORMULA="class Deck < Formula | |
| desc \"Lightweight local dev orchestrator\" | |
| homepage \"https://github.com/WarriorsCode/deck\" | |
| url \"${URL}\" | |
| sha256 \"${SHA256}\" | |
| license \"MIT\" | |
| depends_on \"go\" => :build | |
| def install | |
| ldflags = \"-s -w -X github.com/warriorscode/deck.Version=#{version}\" | |
| system \"go\", \"build\", *std_go_args(ldflags:), \"./cmd/deck\" | |
| end | |
| test do | |
| system bin/\"deck\", \"--version\" | |
| end | |
| end" | |
| # dedent | |
| FORMULA=$(echo "$FORMULA" | sed 's/^ //') | |
| # get current file sha | |
| FILE_SHA=$(gh api repos/WarriorsCode/homebrew-tap/contents/Formula/deck.rb --jq '.sha' 2>/dev/null || echo "") | |
| ARGS=(-f "message=formula: update deck to ${VERSION}") | |
| ARGS+=(-f "content=$(echo "$FORMULA" | base64 -w0)") | |
| if [ -n "$FILE_SHA" ]; then | |
| ARGS+=(-f "sha=${FILE_SHA}") | |
| fi | |
| gh api -X PUT repos/WarriorsCode/homebrew-tap/contents/Formula/deck.rb "${ARGS[@]}" | |
| sync-docs: | |
| runs-on: ubuntu-latest | |
| needs: goreleaser | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - name: Sync CHANGELOG into docs site | |
| run: | | |
| head="--- | |
| title: Changelog | |
| layout: default | |
| nav_order: 4 | |
| ---" | |
| # dedent the heredoc | |
| head=$(echo "$head" | sed 's/^ //') | |
| echo "$head" > docs/changelog.md | |
| echo "" >> docs/changelog.md | |
| cat CHANGELOG.md >> docs/changelog.md | |
| - name: Commit and push if changed | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add docs/changelog.md | |
| git diff --cached --quiet && exit 0 | |
| git commit -m "docs: sync changelog from release ${{ github.ref_name }}" | |
| git push |