|
8 | 8 |
|
9 | 9 | permissions: |
10 | 10 | contents: write |
11 | | - packages: write |
12 | 11 |
|
13 | 12 | jobs: |
14 | | - goreleaser: |
15 | | - runs-on: ubuntu-latest |
| 13 | + build: |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + include: |
| 17 | + - runner: macos-13 |
| 18 | + goos: darwin |
| 19 | + goarch: amd64 |
| 20 | + - runner: macos-latest |
| 21 | + goos: darwin |
| 22 | + goarch: arm64 |
| 23 | + - runner: ubuntu-latest |
| 24 | + goos: linux |
| 25 | + goarch: amd64 |
| 26 | + - runner: ubuntu-24.04-arm |
| 27 | + goos: linux |
| 28 | + goarch: arm64 |
| 29 | + runs-on: ${{ matrix.runner }} |
16 | 30 | steps: |
17 | 31 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 |
18 | | - with: |
19 | | - fetch-depth: 0 |
20 | 32 |
|
21 | 33 | - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6 |
22 | 34 | with: |
23 | 35 | go-version-file: go.mod |
24 | 36 | cache: true |
25 | 37 |
|
26 | | - - name: Generate a token for homebrew-tap |
| 38 | + - name: Build |
| 39 | + env: |
| 40 | + CGO_ENABLED: "1" |
| 41 | + GOOS: ${{ matrix.goos }} |
| 42 | + GOARCH: ${{ matrix.goarch }} |
| 43 | + run: | |
| 44 | + VERSION="${GITHUB_REF_NAME#v}" |
| 45 | + go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o tero ./cmd/tero |
| 46 | +
|
| 47 | + - name: Package |
| 48 | + run: | |
| 49 | + VERSION="${GITHUB_REF_NAME#v}" |
| 50 | + ARCHIVE="tero_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz" |
| 51 | + tar czf "${ARCHIVE}" tero LICENSE |
| 52 | + shasum -a 256 "${ARCHIVE}" > "${ARCHIVE}.sha256" |
| 53 | + echo "ARCHIVE=${ARCHIVE}" >> "$GITHUB_ENV" |
| 54 | +
|
| 55 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 56 | + with: |
| 57 | + name: tero-${{ matrix.goos }}-${{ matrix.goarch }} |
| 58 | + path: | |
| 59 | + tero_*.tar.gz |
| 60 | + tero_*.tar.gz.sha256 |
| 61 | +
|
| 62 | + release: |
| 63 | + needs: build |
| 64 | + runs-on: ubuntu-latest |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 |
| 67 | + |
| 68 | + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 |
| 69 | + with: |
| 70 | + path: artifacts |
| 71 | + merge-multiple: true |
| 72 | + |
| 73 | + - name: Create checksums |
| 74 | + working-directory: artifacts |
| 75 | + run: | |
| 76 | + cat *.sha256 > checksums.txt |
| 77 | + rm *.sha256 |
| 78 | +
|
| 79 | + - name: Create GitHub release |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + run: | |
| 83 | + gh release create "${GITHUB_REF_NAME}" \ |
| 84 | + --title "${GITHUB_REF_NAME}" \ |
| 85 | + --generate-notes \ |
| 86 | + artifacts/*.tar.gz \ |
| 87 | + artifacts/checksums.txt \ |
| 88 | + scripts/install.sh |
| 89 | +
|
| 90 | + - name: Generate a token |
27 | 91 | id: generate-token |
28 | 92 | uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2 |
29 | 93 | with: |
30 | 94 | app-id: ${{ secrets.TERO_BOT_CLIENT_ID }} |
31 | 95 | private-key: ${{ secrets.TERO_BOT_PRIVATE_SIGNING_KEY }} |
32 | 96 | owner: ${{ github.repository_owner }} |
33 | | - repositories: homebrew-tap,scoop-bucket |
| 97 | + repositories: homebrew-tap |
34 | 98 |
|
35 | | - - name: Set up Docker Buildx |
36 | | - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 |
| 99 | + - name: Update Homebrew formula |
| 100 | + env: |
| 101 | + GH_TOKEN: ${{ steps.generate-token.outputs.token }} |
| 102 | + run: | |
| 103 | + VERSION="${GITHUB_REF_NAME#v}" |
| 104 | + BASE_URL="https://github.com/usetero/cli/releases/download/${GITHUB_REF_NAME}" |
37 | 105 |
|
38 | | - - name: Login to Docker Hub |
39 | | - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3 |
40 | | - with: |
41 | | - username: ${{ secrets.DOCKERHUB_USERNAME }} |
42 | | - password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 106 | + darwin_amd64_sha=$(awk '/darwin_amd64/ {print $1}' artifacts/checksums.txt) |
| 107 | + darwin_arm64_sha=$(awk '/darwin_arm64/ {print $1}' artifacts/checksums.txt) |
| 108 | + linux_amd64_sha=$(awk '/linux_amd64/ {print $1}' artifacts/checksums.txt) |
| 109 | + linux_arm64_sha=$(awk '/linux_arm64/ {print $1}' artifacts/checksums.txt) |
43 | 110 |
|
44 | | - - uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6 |
45 | | - with: |
46 | | - distribution: goreleaser |
47 | | - version: "~> v2" |
48 | | - args: release --clean |
49 | | - env: |
50 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
51 | | - HOMEBREW_TAP_TOKEN: ${{ steps.generate-token.outputs.token }} |
| 111 | + cat > /tmp/tero.rb <<EOF |
| 112 | + # typed: false |
| 113 | + # frozen_string_literal: true |
| 114 | +
|
| 115 | + class Tero < Formula |
| 116 | + desc "Improve your observability data quality from the terminal" |
| 117 | + homepage "https://usetero.com" |
| 118 | + version "${VERSION}" |
| 119 | + license "Apache-2.0" |
| 120 | +
|
| 121 | + on_macos do |
| 122 | + if Hardware::CPU.intel? |
| 123 | + url "${BASE_URL}/tero_${VERSION}_darwin_amd64.tar.gz" |
| 124 | + sha256 "${darwin_amd64_sha}" |
| 125 | +
|
| 126 | + def install |
| 127 | + bin.install "tero" |
| 128 | + end |
| 129 | + end |
| 130 | + if Hardware::CPU.arm? |
| 131 | + url "${BASE_URL}/tero_${VERSION}_darwin_arm64.tar.gz" |
| 132 | + sha256 "${darwin_arm64_sha}" |
| 133 | +
|
| 134 | + def install |
| 135 | + bin.install "tero" |
| 136 | + end |
| 137 | + end |
| 138 | + end |
| 139 | +
|
| 140 | + on_linux do |
| 141 | + if Hardware::CPU.intel? && Hardware::CPU.is_64_bit? |
| 142 | + url "${BASE_URL}/tero_${VERSION}_linux_amd64.tar.gz" |
| 143 | + sha256 "${linux_amd64_sha}" |
| 144 | + def install |
| 145 | + bin.install "tero" |
| 146 | + end |
| 147 | + end |
| 148 | + if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? |
| 149 | + url "${BASE_URL}/tero_${VERSION}_linux_arm64.tar.gz" |
| 150 | + sha256 "${linux_arm64_sha}" |
| 151 | + def install |
| 152 | + bin.install "tero" |
| 153 | + end |
| 154 | + end |
| 155 | + end |
| 156 | +
|
| 157 | + test do |
| 158 | + system "#{bin}/tero", "--version" |
| 159 | + end |
| 160 | + end |
| 161 | + EOF |
| 162 | +
|
| 163 | + # Remove leading whitespace from heredoc |
| 164 | + sed -i 's/^ //' /tmp/tero.rb |
| 165 | +
|
| 166 | + cd "$(mktemp -d)" |
| 167 | + git clone "https://x-access-token:${GH_TOKEN}@github.com/usetero/homebrew-tap.git" . |
| 168 | + cp /tmp/tero.rb Formula/tero.rb |
| 169 | + git config user.name "tero-bot[bot]" |
| 170 | + git config user.email "tero-bot[bot]@users.noreply.github.com" |
| 171 | + git add Formula/tero.rb |
| 172 | + git commit -m "tero ${VERSION}" |
| 173 | + git push |
0 commit comments