@@ -13,6 +13,7 @@ permissions:
1313
1414env :
1515 CARGO_TERM_COLOR : always
16+ HOMEBREW_TAP_REPO : hanbu97/homebrew-tap
1617
1718jobs :
1819 build :
5556 cp "target/${{ matrix.target }}/release/tu" "dist/${ASSET_NAME}/"
5657 cp README.md LICENSE "dist/${ASSET_NAME}/"
5758 tar -C dist -czf "dist/${ASSET_NAME}.tar.gz" "${ASSET_NAME}"
59+ cp "target/${{ matrix.target }}/release/tu" "dist/${ASSET_NAME}"
60+ chmod +x "dist/${ASSET_NAME}"
5861 rm -rf "dist/${ASSET_NAME}"
5962
6063 - name : Package archive (Windows)
6669 Copy-Item "target/${{ matrix.target }}/release/tu.exe" "dist/$assetName/"
6770 Copy-Item "README.md","LICENSE" "dist/$assetName/"
6871 Compress-Archive -Path "dist/$assetName/*" -DestinationPath "dist/$assetName.zip" -Force
72+ Copy-Item "target/${{ matrix.target }}/release/tu.exe" "dist/$assetName.exe"
6973 Remove-Item "dist/$assetName" -Recurse -Force
7074
7175 - name : Upload build artifact
9195 run : |
9296 set -euxo pipefail
9397 cd dist
94- sha256sum *.tar.gz *.zip > SHA256SUMS.txt
98+ shopt -s nullglob
99+ files=( *.tar.gz *.zip tu-* tu-*.exe )
100+ sha256sum "${files[@]}" > SHA256SUMS.txt
95101
96102 - name : Upload release bundle
97103 uses : actions/upload-artifact@v4
@@ -117,3 +123,124 @@ jobs:
117123 with :
118124 files : dist/*
119125 generate_release_notes : true
126+
127+ publish-crates :
128+ name : Publish crates.io
129+ runs-on : ubuntu-latest
130+ needs : checksums
131+ if : startsWith(github.ref, 'refs/tags/v') && secrets.CRATES_IO_TOKEN != ''
132+ steps :
133+ - name : Checkout
134+ uses : actions/checkout@v4
135+
136+ - name : Install Rust toolchain
137+ uses : dtolnay/rust-toolchain@stable
138+
139+ - name : Verify Cargo version matches tag
140+ run : |
141+ set -euxo pipefail
142+ tag="${GITHUB_REF_NAME#v}"
143+ cargo_version=$(grep -E '^version\\s*=\\s*\"' Cargo.toml | head -n1 | sed -E 's/.*\"([^\"]+)\".*/\\1/')
144+ test "$tag" = "$cargo_version"
145+
146+ - name : Publish crate
147+ run : cargo publish --locked --token "${{ secrets.CRATES_IO_TOKEN }}"
148+
149+ publish-npm :
150+ name : Publish npm package
151+ runs-on : ubuntu-latest
152+ needs : publish
153+ if : startsWith(github.ref, 'refs/tags/v') && secrets.NPM_TOKEN != ''
154+ steps :
155+ - name : Checkout
156+ uses : actions/checkout@v4
157+
158+ - name : Setup Node
159+ uses : actions/setup-node@v4
160+ with :
161+ node-version : " 20"
162+ registry-url : " https://registry.npmjs.org"
163+
164+ - name : Verify npm package version matches tag
165+ run : |
166+ set -euxo pipefail
167+ tag="${GITHUB_REF_NAME#v}"
168+ npm_version=$(node -p "require('./npm/tu/package.json').version")
169+ test "$tag" = "$npm_version"
170+
171+ - name : Publish npm package
172+ working-directory : npm/tu
173+ run : npm publish --access public
174+ env :
175+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
176+
177+ publish-homebrew-tap :
178+ name : Publish Homebrew tap formula
179+ runs-on : ubuntu-latest
180+ needs : checksums
181+ if : startsWith(github.ref, 'refs/tags/v') && secrets.HOMEBREW_TAP_PAT != ''
182+ steps :
183+ - name : Download release bundle
184+ uses : actions/download-artifact@v4
185+ with :
186+ name : tu-release-bundle
187+ path : dist
188+
189+ - name : Generate Formula
190+ run : |
191+ set -euxo pipefail
192+ version="${GITHUB_REF_NAME#v}"
193+ linux_sha=$(sha256sum "dist/tu-${GITHUB_REF_NAME}-x86_64-unknown-linux-gnu.tar.gz" | awk '{print $1}')
194+ mac_arm_sha=$(sha256sum "dist/tu-${GITHUB_REF_NAME}-aarch64-apple-darwin.tar.gz" | awk '{print $1}')
195+ mac_x64_sha=$(sha256sum "dist/tu-${GITHUB_REF_NAME}-x86_64-apple-darwin.tar.gz" | awk '{print $1}')
196+
197+ mkdir -p out/Formula
198+ cat > out/Formula/tu.rb <<RUBY
199+ class Tu < Formula
200+ desc "Blazing-fast Rust token usage tracker for Codex and Claude Code"
201+ homepage "https://github.com/hanbu97/tokenusage"
202+ license "MIT"
203+ version "${version}"
204+
205+ on_macos do
206+ if Hardware::CPU.arm?
207+ url "https://github.com/hanbu97/tokenusage/releases/download/v${version}/tu-v${version}-aarch64-apple-darwin.tar.gz"
208+ sha256 "${mac_arm_sha}"
209+ else
210+ url "https://github.com/hanbu97/tokenusage/releases/download/v${version}/tu-v${version}-x86_64-apple-darwin.tar.gz"
211+ sha256 "${mac_x64_sha}"
212+ end
213+ end
214+
215+ on_linux do
216+ url "https://github.com/hanbu97/tokenusage/releases/download/v${version}/tu-v${version}-x86_64-unknown-linux-gnu.tar.gz"
217+ sha256 "${linux_sha}"
218+ end
219+
220+ def install
221+ bin.install "tu"
222+ prefix.install "README.md", "LICENSE"
223+ end
224+
225+ test do
226+ assert_match "tokenusage", shell_output("#{bin}/tu --version")
227+ end
228+ end
229+ RUBY
230+
231+ - name : Update tap repository
232+ run : |
233+ set -euxo pipefail
234+ git clone "https://x-access-token:${{ secrets.HOMEBREW_TAP_PAT }}@github.com/${HOMEBREW_TAP_REPO}.git" tap
235+ mkdir -p tap/Formula
236+ cp out/Formula/tu.rb tap/Formula/tu.rb
237+ cd tap
238+ git config user.name "github-actions[bot]"
239+ git config user.email "github-actions[bot]@users.noreply.github.com"
240+ git add Formula/tu.rb
241+ if git diff --cached --quiet; then
242+ echo "No formula changes."
243+ exit 0
244+ fi
245+ git commit -m "chore: update tu formula for ${GITHUB_REF_NAME}"
246+ git push origin HEAD:main
0 commit comments