From d5316f1e747b6a25ccc25186f654c346c332e0a5 Mon Sep 17 00:00:00 2001 From: xrz <62951481+xrz-cloud@users.noreply.github.com> Date: Sat, 15 Jun 2024 20:49:24 +0800 Subject: [PATCH] feat: add gomips support (#173) --- README.md | 3 ++- action.yml | 5 +++++ release.sh | 25 ++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 020051f..3605f67 100644 --- a/README.md +++ b/README.md @@ -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`.
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.
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.
Use your repository's basename if not set. | diff --git a/action.yml b/action.yml index 16e3b38..3d79c57 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -121,6 +125,7 @@ runs: - ${{ inputs.goarch }} - ${{ inputs.goamd64 }} - ${{ inputs.goarm }} + - ${{ inputs.gomips }} - ${{ inputs.goversion }} - ${{ inputs.build_flags}} - ${{ inputs.ldflags }} diff --git a/release.sh b/release.sh index 2ceda46..7e4b476 100755 --- a/release.sh +++ b/release.sh @@ -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 @@ -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) @@ -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