From 3d0cbf9e00fbc5a1e88a81878cbc8ef496646cda Mon Sep 17 00:00:00 2001 From: Alex Bacchin Date: Sun, 19 Mar 2023 02:05:56 +1100 Subject: [PATCH] added support for GOARM (#117) --- .github/workflows/autotest.yml | 16 +++++++++++++--- README.md | 1 + action.yml | 6 ++++++ release.sh | 23 +++++++++++++++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/autotest.yml b/.github/workflows/autotest.yml index 0b99d54..5e8b0fb 100644 --- a/.github/workflows/autotest.yml +++ b/.github/workflows/autotest.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: goos: [linux, windows, darwin] - goarch: [amd64, arm64] + goarch: [amd64, arm64, arm] exclude: - goarch: arm64 goos: windows @@ -26,6 +26,10 @@ jobs: goos: linux - goarch: amd64 goos: windows + - goarch: arm + goos: darwin + - goarch: arm + goos: windows include: - goos: linux goarch: amd64 @@ -39,6 +43,11 @@ jobs: - goos: windows goarch: amd64 goamd64: v3 + - goos: darwin + goarch: amd64 + - goos: linux + goarch: arm + goarm: "7" steps: # - name: Wait release docker build for release branches # if: contains(github.ref, 'release') @@ -56,7 +65,8 @@ jobs: goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} goamd64: ${{ matrix.goamd64 }} - goversion: https://go.dev/dl/go1.16.2.linux-amd64.tar.gz + goarm: ${{ matrix.goarm }} + goversion: https://go.dev/dl/go1.19.7.linux-amd64.tar.gz project_path: ./test/ binary_name: testmain pre_command: go mod init localtest @@ -79,7 +89,7 @@ jobs: goos: [linux] goarch: [amd64] # "" means default - goversion: ["", "1.19", "1.19.5", "https://golang.org/dl/go1.16.1.linux-amd64.tar.gz"] + goversion: ["", "1.19", "1.19.7", "https://go.dev/dl/go1.19.7.linux-amd64.tar.gz"] steps: # - name: Wait release docker build for release branches # if: contains(github.ref, 'release') diff --git a/README.md b/README.md index 2979992..2ead500 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ jobs: | 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`, `loong64` and so on. | | goamd64 | **Optional** | `GOAMD64` 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`. | +| goarm | **Optional** | `GOARM` 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`, | | 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`, `1.17`, `1.18`, `1.19`. You can also define a specific minor release, such as `1.19.5`.
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](https://go.dev/dl/).
e.g., `https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz`. | | project_path | **Optional** | Where to run `go build`.
Use `.` by default. | | binary_name | **Optional** | Specify another binary name if do not want to use repository basename.
Use your repository's basename if not set. | diff --git a/action.yml b/action.yml index 2cca486..54a560b 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,10 @@ inputs: description: 'GOAMD64 is the running programs amd64 microarchitecture level: one of v1, v2, v3, v4.' required: false default: '' + goarm: + description: 'GOARM is the running programs arm microarchitecture level: ARMv5,ARMv6,ARMv7' + required: false + default: '' goversion: description: 'The `Go` compiler version.' required: false @@ -103,6 +107,8 @@ runs: - ${{ inputs.github_token }} - ${{ inputs.goos }} - ${{ inputs.goarch }} + - ${{ inputs.goamd64 }} + - ${{ inputs.goarm }} - ${{ inputs.goversion }} - ${{ inputs.build_flags}} - ${{ inputs.ldflags }} diff --git a/release.sh b/release.sh index 53be302..9c27e9a 100755 --- a/release.sh +++ b/release.sh @@ -18,6 +18,9 @@ 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_GOARM}" ]; then + RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}${INPUT_GOARM} +fi if [ ! -z "${INPUT_ASSET_NAME}" ]; then RELEASE_ASSET_NAME=${INPUT_ASSET_NAME} fi @@ -74,19 +77,35 @@ else fi fi +# fulfill GOARM option +if [ ! -z "${INPUT_GOARM}" ]; then + if [[ "${INPUT_GOARCH}" =~ arm ]]; then + GOARM_FLAG="${INPUT_GOARM}" + else + echo "GOARM should only be use with arm arch." >>/dev/stderr + GOARM_FLAG="" + fi +else + if [[ "${INPUT_GOARCH}" =~ arm ]]; then + GOARM_FLAG="" + else + GOARM_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 - GOAMD64=${GOAMD64_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} eval ${INPUT_BUILD_COMMAND} + GOAMD64=${GOAMD64_FLAG} GOARM=${GOARM_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 - 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}" + GOAMD64=${GOAMD64_FLAG} GOARM=${GOARM_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