新建一个 Token: https://github.com/settings/tokens/new
创建一个项目,新建 Secrets 把上面的 token 复制进去
在根目录创建 .goreleaser.yml
before:
hooks:
- go mod tidy
builds:
- env: [CGO_ENABLED=0]
goos:
- linux
- windows
- darwin
goarch:
- amd64
- 386
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
- goos: windows
goarch: 'arm'
- goos: windows
goarch: 'arm64'
dir: .
main: .
archives:
- format: zip
replacements:
darwin: macOS
checksum:
algorithm: sha256
新建两个目录一个文件:.github/workflows/go.yml
name: Go
on:
create:
tags:
- v*
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: "Check out code"
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: "Set up Go"
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: "Create release on GitHub"
uses: goreleaser/goreleaser-action@v2
with:
args: "release --rm-dist"
version: latest
workdir: .
env:
GITHUB_TOKEN: "${{ secrets.TEST }}"
具体测试项目结构,然后 push 上去
新建一个 tags
查看 Actions ,没报错
此时再查看 Releases 就已经打包好 go 程序了
参考:
https://github.com/SummerSec/SpringExploit/blob/main/.github/workflows/release-binary.yml
https://github.com/SummerSec/template/blob/main/.goreleaser.yml