今天寫了個簡繁體轉換的命令行工具 gopencc,以便對博客內容的簡繁體轉換。自然地,筆者也爲各個平臺編譯打包爲二進制執行文件,但是每次手動編譯並上傳到 GitHub Releases Assets 是十分耗時和枯燥的,幸好我們可以通過 GitHub Actions 來解決這個問題。
目標
每次發佈新版本時,觸發 GitHub Actions,對其進行編譯和打包,並上傳到 GitHub Releases Assets。
配置
1on:
2 release:
3 types: [created]
4
5jobs:
6 releases-matrix:
7 name: Release Go Binary
8 runs-on: ubuntu-latest
9 strategy:
10 matrix:
11 # build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
12 goos: [linux, windows, darwin]
13 goarch: ["386", amd64, arm64]
14 exclude:
15 - goarch: "386"
16 goos: darwin
17 - goarch: arm64
18 goos: windows
19 steps:
20 - uses: actions/checkout@v3
21 - uses: wangyoucao577/[email protected]
22 with:
23 github_token: ${{ secrets.GITHUB_TOKEN }}
24 goos: ${{ matrix.goos }}
25 goarch: ${{ matrix.goarch }}
更多配置請參閱 Go Release Binaries。