新建一个 Token: https://github.com/settings/tokens/new
    image.png
    创建一个项目,新建 Secrets 把上面的 token 复制进去
    image.png

    在根目录创建 .goreleaser.yml

    1. before:
    2. hooks:
    3. - go mod tidy
    4. builds:
    5. - env: [CGO_ENABLED=0]
    6. goos:
    7. - linux
    8. - windows
    9. - darwin
    10. goarch:
    11. - amd64
    12. - 386
    13. - arm
    14. - arm64
    15. ignore:
    16. - goos: darwin
    17. goarch: '386'
    18. - goos: windows
    19. goarch: 'arm'
    20. - goos: windows
    21. goarch: 'arm64'
    22. dir: .
    23. main: .
    24. archives:
    25. - format: zip
    26. replacements:
    27. darwin: macOS
    28. checksum:
    29. algorithm: sha256

    新建两个目录一个文件:.github/workflows/go.yml

    1. name: Go
    2. on:
    3. create:
    4. tags:
    5. - v*
    6. workflow_dispatch:
    7. jobs:
    8. release:
    9. runs-on: ubuntu-latest
    10. steps:
    11. - name: "Check out code"
    12. uses: actions/checkout@v3
    13. with:
    14. fetch-depth: 0
    15. - name: "Set up Go"
    16. uses: actions/setup-go@v2
    17. with:
    18. go-version: 1.17
    19. - name: "Create release on GitHub"
    20. uses: goreleaser/goreleaser-action@v2
    21. with:
    22. args: "release --rm-dist"
    23. version: latest
    24. workdir: .
    25. env:
    26. GITHUB_TOKEN: "${{ secrets.TEST }}"

    image.png
    具体测试项目结构,然后 push 上去
    image.png
    新建一个 tags
    image.png
    查看 Actions ,没报错
    image.png
    此时再查看 Releases 就已经打包好 go 程序了
    image.png

    参考:
    https://github.com/SummerSec/SpringExploit/blob/main/.github/workflows/release-binary.yml
    https://github.com/SummerSec/template/blob/main/.goreleaser.yml