@@ -149,6 +149,13 @@ jobs:
149149 build-macos :
150150 needs : build-frontend
151151 runs-on : macos-latest
152+ strategy :
153+ matrix :
154+ include :
155+ - target : aarch64-apple-darwin
156+ name : macos_aarch64
157+ - target : x86_64-apple-darwin
158+ name : macos_x86_64
152159 steps :
153160 - uses : actions/checkout@v4
154161
@@ -159,25 +166,25 @@ jobs:
159166
160167 - uses : dtolnay/rust-toolchain@stable
161168 with :
162- targets : aarch64-apple-darwin
169+ targets : ${{ matrix.target }}
163170
164171 - uses : Swatinem/rust-cache@v2
165172 with :
166- key : aarch64-apple-darwin
173+ key : ${{ matrix.target }}
167174
168175 - name : Build
169176 env :
170177 RUSTFLAGS : " -C link-arg=-s"
171- run : cargo build --release --target aarch64-apple-darwin --all-features
178+ run : cargo build --release --target ${{ matrix.target }} --all-features
172179
173180 - name : Rename binary
174181 run : |
175182 VERSION="${GITHUB_REF#refs/tags/}"
176- mv target/aarch64-apple-darwin /release/shortlinker "shortlinker_${VERSION}_macos_aarch64 "
183+ mv target/${{ matrix.target }} /release/shortlinker "shortlinker_${VERSION}_${{ matrix.name }} "
177184
178185 - uses : actions/upload-artifact@v4
179186 with :
180- name : binary-macos_aarch64
187+ name : binary-${{ matrix.name }}
181188 path : shortlinker_*
182189
183190 release :
@@ -223,13 +230,26 @@ jobs:
223230
224231 ---
225232
226- ## Downloads
233+ ## Installation
234+
235+ ### Homebrew (macOS/Linux)
236+ ```bash
237+ brew install AptS-1547/tap/shortlinker
238+ ```
239+
240+ ### Cargo Binstall
241+ ```bash
242+ cargo binstall shortlinker
243+ ```
244+
245+ ### Manual Download
227246
228247 | Platform | Architecture | Download |
229248 |----------|--------------|----------|
230249 | Linux | x86_64 | [shortlinker_${{ github.ref_name }}_linux_x86_64](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/shortlinker_${{ github.ref_name }}_linux_x86_64) |
231250 | Linux | ARM64 | [shortlinker_${{ github.ref_name }}_linux_aarch64](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/shortlinker_${{ github.ref_name }}_linux_aarch64) |
232251 | Windows | x86_64 | [shortlinker_${{ github.ref_name }}_windows_x86_64.exe](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/shortlinker_${{ github.ref_name }}_windows_x86_64.exe) |
252+ | macOS | x86_64 | [shortlinker_${{ github.ref_name }}_macos_x86_64](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/shortlinker_${{ github.ref_name }}_macos_x86_64) |
233253 | macOS | ARM64 | [shortlinker_${{ github.ref_name }}_macos_aarch64](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/shortlinker_${{ github.ref_name }}_macos_aarch64) |
234254 | Admin Panel | - | [shortlinker-admin-panel_${{ github.ref_name }}.tar.gz](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/shortlinker-admin-panel_${{ github.ref_name }}.tar.gz) |
235255
@@ -239,3 +259,119 @@ jobs:
239259 prerelease : ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') }}
240260 env :
241261 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
262+
263+ update-homebrew :
264+ name : Update Homebrew Tap
265+ needs : release
266+ runs-on : ubuntu-latest
267+ # 只在非预发布版本时更新 Homebrew
268+ if : ${{ !contains(github.ref_name, 'alpha') && !contains(github.ref_name, 'beta') && !contains(github.ref_name, 'rc') }}
269+ steps :
270+ - name : Download release assets and calculate SHA256
271+ id : sha256
272+ run : |
273+ VERSION="${GITHUB_REF#refs/tags/}"
274+ BASE_URL="https://github.com/${{ github.repository }}/releases/download/${VERSION}"
275+
276+ curl -sL "${BASE_URL}/shortlinker_${VERSION}_macos_aarch64" -o macos-arm64
277+ curl -sL "${BASE_URL}/shortlinker_${VERSION}_macos_x86_64" -o macos-amd64
278+ curl -sL "${BASE_URL}/shortlinker_${VERSION}_linux_aarch64" -o linux-arm64
279+ curl -sL "${BASE_URL}/shortlinker_${VERSION}_linux_x86_64" -o linux-amd64
280+
281+ echo "macos_arm64=$(sha256sum macos-arm64 | cut -d' ' -f1)" >> $GITHUB_OUTPUT
282+ echo "macos_amd64=$(sha256sum macos-amd64 | cut -d' ' -f1)" >> $GITHUB_OUTPUT
283+ echo "linux_arm64=$(sha256sum linux-arm64 | cut -d' ' -f1)" >> $GITHUB_OUTPUT
284+ echo "linux_amd64=$(sha256sum linux-amd64 | cut -d' ' -f1)" >> $GITHUB_OUTPUT
285+
286+ - name : Update Homebrew Formula
287+ uses : actions/github-script@v7
288+ with :
289+ github-token : ${{ secrets.HOMEBREW_TAP_TOKEN }}
290+ script : |
291+ const version = '${{ github.ref_name }}'.replace(/^v/, '');
292+ const tagVersion = '${{ github.ref_name }}';
293+ const sha256 = {
294+ macos_arm64: '${{ steps.sha256.outputs.macos_arm64 }}',
295+ macos_amd64: '${{ steps.sha256.outputs.macos_amd64 }}',
296+ linux_arm64: '${{ steps.sha256.outputs.linux_arm64 }}',
297+ linux_amd64: '${{ steps.sha256.outputs.linux_amd64 }}'
298+ };
299+
300+ const formula = `# typed: false
301+ # frozen_string_literal: true
302+
303+ class Shortlinker < Formula
304+ desc "A minimalist URL shortener service supporting HTTP 307 redirection"
305+ homepage "https://github.com/AptS-1547/shortlinker"
306+ version "${version}"
307+ license "MIT"
308+
309+ on_macos do
310+ on_arm do
311+ url "https://github.com/AptS-1547/shortlinker/releases/download/${tagVersion}/shortlinker_${tagVersion}_macos_aarch64"
312+ sha256 "${sha256.macos_arm64}"
313+
314+ def install
315+ bin.install "shortlinker_${tagVersion}_macos_aarch64" => "shortlinker"
316+ end
317+ end
318+
319+ on_intel do
320+ url "https://github.com/AptS-1547/shortlinker/releases/download/${tagVersion}/shortlinker_${tagVersion}_macos_x86_64"
321+ sha256 "${sha256.macos_amd64}"
322+
323+ def install
324+ bin.install "shortlinker_${tagVersion}_macos_x86_64" => "shortlinker"
325+ end
326+ end
327+ end
328+
329+ on_linux do
330+ on_arm do
331+ url "https://github.com/AptS-1547/shortlinker/releases/download/${tagVersion}/shortlinker_${tagVersion}_linux_aarch64"
332+ sha256 "${sha256.linux_arm64}"
333+
334+ def install
335+ bin.install "shortlinker_${tagVersion}_linux_aarch64" => "shortlinker"
336+ end
337+ end
338+
339+ on_intel do
340+ url "https://github.com/AptS-1547/shortlinker/releases/download/${tagVersion}/shortlinker_${tagVersion}_linux_x86_64"
341+ sha256 "${sha256.linux_amd64}"
342+
343+ def install
344+ bin.install "shortlinker_${tagVersion}_linux_x86_64" => "shortlinker"
345+ end
346+ end
347+ end
348+
349+ test do
350+ assert_match version.to_s, shell_output("#{bin}/shortlinker --version")
351+ end
352+ end
353+ `.split('\n').map(line => line.replace(/^ /, '')).join('\n');
354+
355+ // Get current file (if exists) to get its SHA
356+ let fileSha;
357+ try {
358+ const { data } = await github.rest.repos.getContent({
359+ owner: 'AptS-1547',
360+ repo: 'homebrew-tap',
361+ path: 'Formula/shortlinker.rb'
362+ });
363+ fileSha = data.sha;
364+ } catch (e) {
365+ // File doesn't exist yet
366+ fileSha = undefined;
367+ }
368+
369+ // Create or update the formula file
370+ await github.rest.repos.createOrUpdateFileContents({
371+ owner: 'AptS-1547',
372+ repo: 'homebrew-tap',
373+ path: 'Formula/shortlinker.rb',
374+ message: `chore: bump shortlinker to ${tagVersion}`,
375+ content: Buffer.from(formula).toString('base64'),
376+ sha: fileSha
377+ });
0 commit comments