Skip to content

Commit

Permalink
feat: add gomips support (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrz-cloud committed Jun 15, 2024
1 parent ec68290 commit d5316f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ 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`, |
| 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`. |
| gomips | **Optional** | `GOMIPS` is the running programs arm microarchitecture level, which is available since `go1.13`. It should only be used when `GOARCH` is one of `mips`, `mipsle`, `mips64`, `mips64le`: one of `hardfloat`, `softfloat`. |
| 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. <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_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
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: 'GOARM is the running programs arm microarchitecture level: ARMv5,ARMv6,ARMv7'
required: false
default: ''
gomips:
description: 'GOMIPS is the running programs mips microarchitecture level: hardfloat,softfloat'
required: false
default: ''
goversion:
description: 'The `Go` compiler version.'
required: false
Expand Down Expand Up @@ -121,6 +125,7 @@ runs:
- ${{ inputs.goarch }}
- ${{ inputs.goamd64 }}
- ${{ inputs.goarm }}
- ${{ inputs.gomips }}
- ${{ inputs.goversion }}
- ${{ inputs.build_flags}}
- ${{ inputs.ldflags }}
Expand Down
25 changes: 22 additions & 3 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ fi
if [ ! -z "${INPUT_GOARM}" ] && [[ "${INPUT_GOARCH}" == 'arm' ]]; then
RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}v${INPUT_GOARM}
fi
if [ ! -z "${INPUT_GOMIPS}" ] && [[ "${INPUT_GOARCH}" -eq 'mips' || "${INPUT_GOARCH}" -eq 'mipsle' || "${INPUT_GOARCH}" -eq 'mips64' || "${INPUT_GOARCH}" -eq 'mips64le' ]]; then
RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}-${INPUT_GOMIPS}
fi
if [ ! -z "${INPUT_ASSET_NAME}" ]; then
RELEASE_ASSET_NAME=${INPUT_ASSET_NAME}
fi
Expand Down Expand Up @@ -95,6 +98,22 @@ else
fi
fi

# fulfill GOMIPS option
if [ ! -z "${INPUT_GOMIPS}" ]; then
if [[ "${INPUT_GOARCH}" =~ mips ]]; then
GOMIPS_FLAG="${INPUT_GOMIPS}"
else
echo "GOMIPS should only be use with mips arch." >>/dev/stderr
GOMIPS_FLAG=""
fi
else
if [[ "${INPUT_GOARCH}" =~ mips ]]; then
GOMIPS_FLAG=""
else
GOMIPS_FLAG=""
fi
fi


# build
BUILD_ARTIFACTS_FOLDER=build-artifacts-$(date +%s)
Expand All @@ -104,20 +123,20 @@ if [ ${INPUT_MULTI_BINARIES^^} == 'TRUE' ]; then

# leverage golang feature to support multiple binaries
# for example, 'go build -o xxx ./cmd/...' or 'go build -o xxx ./cmd/app1 ./cmd/app2' to generate multiple binaries'
GOAMD64=${GOAMD64_FLAG} GOARM=${GOARM_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} ${INPUT_BUILD_COMMAND} ${INPUT_BUILD_FLAGS} -o ${BUILD_ARTIFACTS_FOLDER} ${INPUT_PROJECT_PATH}
GOAMD64=${GOAMD64_FLAG} GOARM=${GOARM_FLAG} GOMIPS=${GOMIPS_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} ${INPUT_BUILD_COMMAND} ${INPUT_BUILD_FLAGS} -o ${BUILD_ARTIFACTS_FOLDER} ${INPUT_PROJECT_PATH}
else
RELEASE_ASSET_DIR=${INPUT_PROJECT_PATH}/${BUILD_ARTIFACTS_FOLDER}
mkdir -p ${RELEASE_ASSET_DIR}
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} GOARM=${GOARM_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} eval ${INPUT_BUILD_COMMAND}
GOAMD64=${GOAMD64_FLAG} GOARM=${GOARM_FLAG} GOMIPS=${GOMIPS_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} 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}"
GOAMD64=${GOAMD64_FLAG} GOARM=${GOARM_FLAG} GOMIPS=${GOMIPS_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
fi

Expand Down

0 comments on commit d5316f1

Please sign in to comment.