Skip to content

Commit

Permalink
feat: support Go 1.18 (#84)
Browse files Browse the repository at this point in the history
* feat: add support for Go 1.18

* fix: generate asset name correctly

* ci: update tests

* ci: ignore unsupported unit

* ci: only test on amd64

* ci: specify test target

* fix: fix syntax

* fix: env set

* docs: add GOAMD64 explanation to readme

* ci: fix include
  • Loading branch information
Zxilly authored Apr 25, 2022
1 parent de3baa7 commit f3c2d7b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/autotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ jobs:
goos: darwin
- goarch: arm64
goos: windows
- goarch: amd64
goos: linux
- goarch: amd64
goos: windows
include:
- goos: linux
goarch: amd64
goamd64: v1
- goos: linux
goarch: amd64
goamd64: v3
- goos: windows
goarch: amd64
goamd64: v1
- goos: windows
goarch: amd64
goamd64: v3
steps:
# - name: Wait release docker build for release branches
# if: contains(github.ref, 'release')
Expand All @@ -34,6 +51,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goamd64: ${{ matrix.goamd64 }}
goversion: https://go.dev/dl/go1.16.2.linux-amd64.tar.gz
project_path: ./test/
binary_name: testmain
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
| github_token | **Mandatory** | Your `GITHUB_TOKEN` for uploading releases to Github assets. |
| goos | **Mandatory** | `GOOS` is the running program's operating system target: one of `darwin`, `freebsd`, `linux`, and so on. |
| goarch | **Mandatory** | `GOARCH` is the running program's architecture target: one of `386`, `amd64`, `arm`, `arm64`, `s390x`, and so on. |
| goamd64 | **Optional** | `GOAMD64` is the running programs amd64 microarchitecture level, should only be used when `GOARCH` is `amd64`: one of `v1`, `v2`, `v3`, `v4`. |
| goversion | **Optional** | The `Go` compiler version. `latest`([check it here](https://go.dev/VERSION?m=text)) by default, optional `1.13`, `1.14`, `1.15`, `1.16` or `1.17`. <br>It also takes download URL instead of version string if you'd like to use more specified version. But make sure your URL is `linux-amd64` package, better to find the URL from [Go - Downloads](https://go.dev/dl/).<br>E.g., `https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz`. |
| project_path | **Optional** | Where to run `go build`. <br>Use `.` by default. |
| binary_name | **Optional** | Specify another binary name if do not want to use repository basename. <br>Use your repository's basename if not set. |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ inputs:
description: 'GOARCH is the running programs architecture target: one of 386, amd64, arm, s390x, and so on.'
required: true
default: ''
goamd64:
description: 'GOAMD64 is the running programs amd64 microarchitecture level: one of v1, v2, v3, v4.'
required: false
default: ''
goversion:
description: 'The `Go` compiler version.'
required: false
Expand Down
23 changes: 21 additions & 2 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ fi
RELEASE_NAME=${INPUT_RELEASE_NAME}

RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}
if [ ! -z "${INPUT_GOAMD64}" ]; then
RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}-${INPUT_GOAMD64}
fi
if [ ! -z "${INPUT_ASSET_NAME}" ]; then
RELEASE_ASSET_NAME=${INPUT_ASSET_NAME}
fi
Expand Down Expand Up @@ -48,19 +51,35 @@ if [ ! -z "${INPUT_LDFLAGS}" ]; then
LDFLAGS_PREFIX="-ldflags"
fi

# fulfill GOAMD64 option
if [ ! -z "${INPUT_GOAMD64}" ]; then
if [[ "${INPUT_GOARCH}" =~ amd64 ]]; then
GOAMD64_FLAG="${INPUT_GOAMD64}"
else
echo "GOAMD64 should only be use with amd64 arch." >>/dev/stderr
GOAMD64_FLAG=""
fi
else
if [[ "${INPUT_GOARCH}" =~ amd64 ]]; then
GOAMD64_FLAG="v1"
else
GOAMD64_FLAG=""
fi
fi

# build
BUILD_ARTIFACTS_FOLDER=build-artifacts-$(date +%s)
mkdir -p ${INPUT_PROJECT_PATH}/${BUILD_ARTIFACTS_FOLDER}
cd ${INPUT_PROJECT_PATH}
if [[ "${INPUT_BUILD_COMMAND}" =~ ^make.* ]]; then
# start with make, assumes using make to build golang binaries, execute it directly
GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} eval ${INPUT_BUILD_COMMAND}
GOAMD64=${GOAMD64_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} eval ${INPUT_BUILD_COMMAND}
if [ -f "${BINARY_NAME}${EXT}" ]; then
# assumes the binary will be generated in current dir, copy it for later processes
cp ${BINARY_NAME}${EXT} ${BUILD_ARTIFACTS_FOLDER}/
fi
else
GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} ${INPUT_BUILD_COMMAND} -o ${BUILD_ARTIFACTS_FOLDER}/${BINARY_NAME}${EXT} ${INPUT_BUILD_FLAGS} ${LDFLAGS_PREFIX} "${INPUT_LDFLAGS}"
GOAMD64=${GOAMD64_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} ${INPUT_BUILD_COMMAND} -o ${BUILD_ARTIFACTS_FOLDER}/${BINARY_NAME}${EXT} ${INPUT_BUILD_FLAGS} ${LDFLAGS_PREFIX} "${INPUT_LDFLAGS}"
fi


Expand Down
12 changes: 7 additions & 5 deletions setup-go.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/bash -eux

GO_LINUX_PACKAGE_URL="https://go.dev/dl/$(curl https://go.dev/VERSION?m=text).linux-amd64.tar.gz"
if [[ ${INPUT_GOVERSION} == "1.17" ]]; then
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.17.linux-amd64.tar.gz"
if [[ ${INPUT_GOVERSION} == "1.18" ]]; then
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.18.1.linux-amd64.tar.gz"
elif [[ ${INPUT_GOVERSION} == "1.17" ]]; then
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.17.9.linux-amd64.tar.gz"
elif [[ ${INPUT_GOVERSION} == "1.16" ]]; then
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.16.7.linux-amd64.tar.gz"
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.16.15.linux-amd64.tar.gz"
elif [[ ${INPUT_GOVERSION} == "1.15" ]]; then
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.15.10.linux-amd64.tar.gz"
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.15.15.linux-amd64.tar.gz"
elif [[ ${INPUT_GOVERSION} == "1.14" ]]; then
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.14.15.linux-amd64.tar.gz"
elif [[ ${INPUT_GOVERSION} == "1.13" ]]; then
GO_LINUX_PACKAGE_URL="https://dl.google.com/go/go1.13.8.linux-amd64.tar.gz"
GO_LINUX_PACKAGE_URL="https://go.dev/dl/go1.13.15.linux-amd64.tar.gz"
elif [[ ${INPUT_GOVERSION} == http* ]]; then
GO_LINUX_PACKAGE_URL=${INPUT_GOVERSION}
fi
Expand Down

0 comments on commit f3c2d7b

Please sign in to comment.