ci: add Homebrew formula to repo, auto-update on release #1
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 | |
| jobs: | |
| build: | |
| runs-on: macos-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - goos: darwin | |
| goarch: arm64 | |
| suffix: darwin-arm64 | |
| - goos: darwin | |
| goarch: amd64 | |
| suffix: darwin-amd64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Build | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| SUFFIX: ${{ matrix.suffix }} | |
| TAG: ${{ github.ref_name }} | |
| run: | | |
| go build -ldflags="-s -w" -o awake . | |
| tar czf "awake-${TAG}-${SUFFIX}.tar.gz" awake | |
| shasum -a 256 "awake-${TAG}-${SUFFIX}.tar.gz" > "awake-${TAG}-${SUFFIX}.tar.gz.sha256" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: awake-${{ matrix.suffix }} | |
| path: | | |
| awake-*.tar.gz | |
| awake-*.sha256 | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| merge-multiple: true | |
| path: dist | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| generate_release_notes: true | |
| files: | | |
| dist/awake-*.tar.gz | |
| dist/awake-*.sha256 | |
| - name: Update Homebrew formula | |
| env: | |
| TAG: ${{ github.ref_name }} | |
| run: | | |
| ARM64_SHA=$(cat dist/awake-*-darwin-arm64.tar.gz.sha256 | awk '{print $1}') | |
| AMD64_SHA=$(cat dist/awake-*-darwin-amd64.tar.gz.sha256 | awk '{print $1}') | |
| sed -i "s|version \".*\"|version \"${TAG#v}\"|" Formula/awake.rb | |
| sed -i "s|/download/v[^/]*/awake-v[^-]*-darwin-arm64|/download/${TAG}/awake-${TAG}-darwin-arm64|" Formula/awake.rb | |
| sed -i "s|/download/v[^/]*/awake-v[^-]*-darwin-amd64|/download/${TAG}/awake-${TAG}-darwin-amd64|" Formula/awake.rb | |
| sed -i "s|sha256 \"PLACEHOLDER_ARM64_SHA256\"|sha256 \"${ARM64_SHA}\"|" Formula/awake.rb | |
| sed -i "s|sha256 \"PLACEHOLDER_AMD64_SHA256\"|sha256 \"${AMD64_SHA}\"|" Formula/awake.rb | |
| # Also handle updates to existing real hashes | |
| sed -i "/darwin-arm64/{n;s|sha256 \"[a-f0-9]\{64\}\"|sha256 \"${ARM64_SHA}\"|;}" Formula/awake.rb | |
| sed -i "/darwin-amd64/{n;s|sha256 \"[a-f0-9]\{64\}\"|sha256 \"${AMD64_SHA}\"|;}" Formula/awake.rb | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/awake.rb | |
| git commit -m "chore: update Homebrew formula for ${TAG}" || true | |
| git push origin HEAD:main |