Skip to content

Commit

Permalink
added support for GOARM (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbacchin authored Mar 18, 2023
1 parent b91658d commit 3d0cbf9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/autotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ jobs:
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64]
goarch: [amd64, arm64, arm]
exclude:
- goarch: arm64
goos: windows
- goarch: amd64
goos: linux
- goarch: amd64
goos: windows
- goarch: arm
goos: darwin
- goarch: arm
goos: windows
include:
- goos: linux
goarch: amd64
Expand All @@ -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')
Expand All @@ -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
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. <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](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
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,6 +107,8 @@ runs:
- ${{ inputs.github_token }}
- ${{ inputs.goos }}
- ${{ inputs.goarch }}
- ${{ inputs.goamd64 }}
- ${{ inputs.goarm }}
- ${{ inputs.goversion }}
- ${{ inputs.build_flags}}
- ${{ inputs.ldflags }}
Expand Down
23 changes: 21 additions & 2 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 3d0cbf9

Please sign in to comment.