今天写了个简繁体转换的命令行工具 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。