chore: add github workflow #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 | ||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
| jobs: | ||
| release: | ||
| name: goreleaser | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: '1.21' | ||
| - name: Run goreleaser | ||
| uses: goreleaser/goreleaser-action@v3 | ||
| with: | ||
| version: latest | ||
| args: release --rm-dist | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| update-homebrew: | ||
| name: Update Homebrew Tap | ||
| runs-on: ubuntu-latest | ||
| needs: release | ||
| steps: | ||
| - name: Checkout this repo | ||
| uses: actions/checkout@v4 | ||
| - name: Download darwin amd64 archive | ||
| run: | | ||
| set -e | ||
| TAG=${GITHUB_REF#refs/tags/} | ||
| API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" | ||
| ASSET_URL=$(curl -s $API_URL | jq -r '.assets[] | select(.name|test("darwin_amd64")) | .browser_download_url') | ||
| if [ -z "$ASSET_URL" ]; then echo "no asset url"; exit 1; fi | ||
| curl -L "$ASSET_URL" -o /tmp/bb.tar.gz | ||
| - name: Calculate sha256 | ||
| id: calculate_sha256 | ||
| run: | | ||
| sha256=$(shasum -a 256 /tmp/bb.tar.gz | awk '{print $1}') | ||
| echo "sha256=$sha256" >> $GITHUB_OUTPUT | ||
| - name: Checkout homebrew tap | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: livepo/homebrew-tap | ||
| token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }} | ||
| path: tap | ||
| - name: Create formula | ||
| run: | | ||
| set -e | ||
| mkdir -p tap/Formula | ||
| VERSION=${GITHUB_REF#refs/tags/} | ||
| sha256=${{ steps.calculate_sha256.outputs.sha256 }} | ||
| cat > tap/Formula/bb.rb <<EOF | ||
| class Bb < Formula | ||
| desc "bb is a terminal translate app" | ||
| homepage "https://github.com/livepo/bb" | ||
| url "https://github.com/livepo/bb/releases/download/${VERSION}/bb_${VERSION}_darwin_amd64.tar.gz" | ||
| sha256 "${sha256}" | ||
| version "${VERSION}" | ||
| def install | ||
| bin.install "bb" | ||
| end | ||
| test do | ||
| system "#{bin}/bb", "version" | ||
| end | ||
| end | ||
| EOF | ||
| - name: Commit and push formula | ||
| run: | | ||
| set -e | ||
| cd tap | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git add Formula/bb.rb | ||
| git commit -m "chore: bump bb to ${GITHUB_REF#refs/tags/}" || echo "no changes" | ||
| git push origin HEAD:master | ||
| env: | ||
| GIT_ASKPASS: /bin/true | ||
| HOMEBREW_GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_TOKEN }} | ||
| name: Release | ||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
| jobs: | ||
| release: | ||
| name: goreleaser | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: '1.21' | ||
| - name: Run goreleaser | ||
| uses: goreleaser/goreleaser-action@v3 | ||
| with: | ||
| version: latest | ||
| args: release --rm-dist | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| update-homebrew: | ||
| name: Update Homebrew Tap | ||
| runs-on: ubuntu-latest | ||
| needs: release | ||
| steps: | ||
| - name: Checkout this repo | ||
| uses: actions/checkout@v4 | ||
| - name: Get release info | ||
| id: release | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const tag = process.env.GITHUB_REF.replace('refs/tags/','') | ||
| const release = await github.rest.repos.getReleaseByTag({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| tag | ||
| }) | ||
| return {assets: release.data.assets} | ||
| - name: Download darwin amd64 archive | ||
| run: | | ||
| set -e | ||
| ASSETS=$(echo '${{ steps.release.outputs.result }}' || true) | ||
| # fallback: use GitHub API to find asset URL for darwin_amd64 | ||
| TAG=${GITHUB_REF#refs/tags/} | ||
| API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" | ||
| ASSET_URL=$(curl -s $API_URL | jq -r '.assets[] | select(.name|test("darwin_amd64")) | .browser_download_url') | ||
| if [ -z "$ASSET_URL" ]; then echo "no asset url"; exit 1; fi | ||
| curl -L "$ASSET_URL" -o /tmp/bb.tar.gz | ||
| - name: Calculate sha256 | ||
| run: | | ||
| sha256=$(shasum -a 256 /tmp/bb.tar.gz | awk '{print $1}') | ||
| echo "sha256=$sha256" >> $GITHUB_OUTPUT | ||
| - name: Checkout homebrew tap | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: livepo/homebrew-tap | ||
| token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }} | ||
| path: tap | ||
| - name: Create formula | ||
| run: | | ||
| set -e | ||
| mkdir -p tap/Formula | ||
| VERSION=${GITHUB_REF#refs/tags/} | ||
| cat > tap/Formula/bb.rb <<'EOF' | ||
| class Bb < Formula | ||
| desc "bb is a terminal translate app" | ||
| homepage "https://github.com/livepo/bb" | ||
| url "https://github.com/livepo/bb/releases/download/${VERSION}/bb_${VERSION}_darwin_amd64.tar.gz" | ||
| sha256 "${{ steps.calculate_sha256.outputs.sha256 }}" | ||
| version "${VERSION}" | ||
| def install | ||
| bin.install "bb" | ||
| end | ||
| test do | ||
| system "#{bin}/bb", "version" | ||
| end | ||
| end | ||
| EOF | ||
| - name: Commit and push formula | ||
| run: | | ||
| set -e | ||
| cd tap | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git add Formula/bb.rb | ||
| git commit -m "chore: bump bb to ${GITHUB_REF#refs/tags/}" || echo "no changes" | ||
| git push origin HEAD:master | ||
| env: | ||
| GIT_ASKPASS: /bin/true | ||
| HOMEBREW_GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_TOKEN }} | ||