Home

Awesome

Go Release GitHub Action

Build Docker PR Build Test
Automatically publish Go binaries to Github Release Assets through Github Action.

Features

Usage

Basic Example

# .github/workflows/release.yaml

on:
  release:
    types: [created]

permissions:
    contents: write
    packages: write

jobs:
  release-linux-amd64:
    name: release linux/amd64
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: wangyoucao577/go-release-action@v1
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        goos: linux
        goarch: amd64

Input Parameters

ParameterMandatory/OptionalDescription
github_tokenMandatoryYour GITHUB_TOKEN for uploading releases to Github assets.
goosMandatoryGOOS is the running program's operating system target: one of darwin, freebsd, linux, and so on.
goarchMandatoryGOARCH is the running program's architecture target: one of 386, amd64, arm, arm64, s390x, loong64 and so on.
goamd64OptionalGOAMD64 is the running programs amd64 microarchitecture level, which is available since go1.18. It should only be used when GOARCH is amd64: one of v1, v2, v3, v4.
goarmOptionalGOARM is the running programs arm microarchitecture level, which is available since go1.1. It should only be used when GOARCH is arm: one of 5, 6, 7.
gomipsOptionalGOMIPS is the running programs arm microarchitecture level, which is available since go1.13. It should only be used when GOMIPS is one of mips, mipsle, mips64, mips64le: one of hardfloat, softfloat.
goversionOptionalThe Go compiler version. latest(check it here) by default, optional 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19. You can also define a specific minor release, such as 1.19.5. <br>Alternatively takes a download URL or a path to go.mod instead of version string. Make sure your URL references the linux-amd64 package. You can find the URL on Go - Downloads.<br>e.g., https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz.
project_pathOptionalWhere to run go build. <br>Use . by default. <br>If enable multi_binaries: true, you can use project_path: ./cmd/... or project_path: ./cmd/app1 ./cmd/app2 to build multiple binaries and include them in one package.
binary_nameOptionalSpecify another binary name if do not want to use repository basename. <br>Use your repository's basename if not set.
pre_commandOptionalExtra command that will be executed before go build. You may want to use it to solve dependency if you're NOT using Go Modules.
build_commandOptionalThe actual command to build binary, typically go build. You may want to use other command wrapper, e.g., packr2, example build_command: 'packr2 build'. Remember to use pre_command to set up packr2 command in this scenario.<br>It also supports the make(Makefile) building system, example build_command: make. In this case both build_flags and ldflags will be ignored since they should be written in your Makefile already. Also, please make sure the generated binary placed in the path where make runs, i.e., project_path.
executable_compressionOptionalCompression executable binary by some third-party tools. It takes compression command with optional args as input, e.g., upx or upx -v. <br>Only upx is supported at the moment.
build_flagsOptionalAdditional arguments to pass the go build command.
ldflagsOptionalValues to provide to the -ldflags argument.
extra_filesOptionalExtra files that will be packaged into artifacts either. Multiple files separated by space. Note that extra folders can be allowed either since internal cp -r already in use. <br>E.g., extra_files: LICENSE README.md
md5sumOptionalPublish .md5 along with artifacts, TRUE by default.
sha256sumOptionalPublish .sha256 along with artifacts, FALSE by default.
release_tagOptionalTarget release tag to publish your binaries to. It's dedicated to publish binaries on every push into one specified release page since there's no target in this case. DON'T set it if you trigger the action by release: [created] event as most people do.
release_nameOptionalAlternative to release_tag for release target specification and binary push. The newest release by given release_name will be picked from all releases. Useful for e.g. untagged(draft) ones.
release_repoOptionalRepository where the build should be pushed to. By default the value for this is the repo from where the action is running. Useful if you use a different repository for your releases (private repo for code, public repo for releases).
overwriteOptionalOverwrite asset if it's already exist. FALSE by default.
asset_nameOptionalCustomize asset name if do not want to use the default format ${BINARY_NAME}-${RELEASE_TAG}-${GOOS}-${GOARCH}. <br>Make sure set it correctly, especially for matrix usage that you have to append -${{ matrix.goos }}-${{ matrix.goarch }}. A valid example could be asset_name: binary-name-${{ matrix.goos }}-${{ matrix.goarch }}.
retryOptionalHow many times retrying if upload fails. 3 by default.
post_commandOptionalExtra command that will be executed for teardown work. e.g. you can use it to upload artifacts to AWS s3 or aliyun OSS
compress_assetsOptionalauto default will produce a zip file for Windows and tar.gz for others. zip will force the use of zip. OFF will disable packaging of assets.
uploadOptionalUpload release assets or not. It'll be useful if you'd like to use subsequent workflow to process the file, such as signing it on macos, and so on.

Output Parameters

ParameterDescription
release_asset_dirRelease file directory provided for use by other workflows.

Advanced Example

# .github/workflows/release.yaml

on:
  release:
    types: [created]

permissions:
    contents: write
    packages: write

jobs:
  releases-matrix:
    name: Release Go Binary
    runs-on: ubuntu-latest
    strategy:
      matrix:
        # build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
        goos: [linux, windows, darwin]
        goarch: ["386", amd64, arm64]
        exclude:
          - goarch: "386"
            goos: darwin
          - goarch: arm64
            goos: windows
    steps:
    - uses: actions/checkout@v4
    - uses: wangyoucao577/go-release-action@v1
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        goos: ${{ matrix.goos }}
        goarch: ${{ matrix.goarch }}
        goversion: "https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz"
        project_path: "./cmd/test-binary"
        binary_name: "test-binary"
        extra_files: LICENSE README.md

More Examples

Welcome share your usage for other people's reference!

:clap::clap::clap: Enjoy! Welcome star if like it:smile: