Skip to content

Commit

Permalink
style: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Feb 7, 2024
1 parent dc224f0 commit 0b47d78
Showing 1 changed file with 56 additions and 51 deletions.
107 changes: 56 additions & 51 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ 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}
RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}-${INPUT_GOAMD64}
fi
if [ ! -z "${INPUT_GOARM}" ] && [[ "${INPUT_GOARCH}" =~ arm ]]; then
RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}v${INPUT_GOARM}
RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH}v${INPUT_GOARM}
fi
if [ ! -z "${INPUT_ASSET_NAME}" ]; then
RELEASE_ASSET_NAME=${INPUT_ASSET_NAME}
RELEASE_ASSET_NAME=${INPUT_ASSET_NAME}
fi

RELEASE_REPO=${GITHUB_REPOSITORY}
Expand All @@ -36,7 +36,7 @@ if [ ! -z "${INPUT_RELEASE_REPO}" ]; then
fi

# prompt error if non-supported event
if egrep -q 'release|push|workflow_dispatch|workflow_run|schedule' <<< "${GITHUB_EVENT_NAME}"; then
if egrep -q 'release|push|workflow_dispatch|workflow_run|schedule' <<<"${GITHUB_EVENT_NAME}"; then
echo "Event: ${GITHUB_EVENT_NAME}"
else
echo -e "Unsupport event: ${GITHUB_EVENT_NAME}! \nSupport: release | push | workflow_dispatch | workflow_run | schedule"
Expand All @@ -48,7 +48,7 @@ git config --global --add safe.directory ${GITHUB_WORKSPACE}

# execute pre-command if exist, e.g. `go get -v ./...`
if [ ! -z "${INPUT_PRE_COMMAND}" ]; then
eval ${INPUT_PRE_COMMAND}
eval ${INPUT_PRE_COMMAND}
fi

# binary suffix
Expand All @@ -60,39 +60,39 @@ fi
# prefix for ldflags
LDFLAGS_PREFIX=''
if [ ! -z "${INPUT_LDFLAGS}" ]; then
LDFLAGS_PREFIX="-ldflags"
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
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
if [[ "${INPUT_GOARCH}" =~ amd64 ]]; then
GOAMD64_FLAG="v1"
else
GOAMD64_FLAG=""
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
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
if [[ "${INPUT_GOARCH}" =~ arm ]]; then
GOARM_FLAG=""
else
GOARM_FLAG=""
fi
fi

# build
Expand All @@ -101,26 +101,25 @@ 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}
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
# 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}
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} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} ${INPUT_BUILD_COMMAND} -o ${BUILD_ARTIFACTS_FOLDER}/${BINARY_NAME}${EXT} ${INPUT_BUILD_FLAGS} ${LDFLAGS_PREFIX} "${INPUT_LDFLAGS}"
fi


# executable compression
if [ ! -z "${INPUT_EXECUTABLE_COMPRESSION}" ]; then
if [[ "${INPUT_EXECUTABLE_COMPRESSION}" =~ ^upx.* ]]; then
if [[ "${INPUT_EXECUTABLE_COMPRESSION}" =~ ^upx.* ]]; then
# start with upx, use upx to compress the executable binary
eval ${INPUT_EXECUTABLE_COMPRESSION} ${BUILD_ARTIFACTS_FOLDER}/${BINARY_NAME}${EXT}
else
else
echo "Unsupport executable compression: ${INPUT_EXECUTABLE_COMPRESSION}!"
exit 1
fi
fi
fi

# prepare extra files
Expand All @@ -141,13 +140,19 @@ if [ ${INPUT_COMPRESS_ASSETS^^} == "TRUE" ] || [ ${INPUT_COMPRESS_ASSETS^^} == "
MEDIA_TYPE='application/zip'
RELEASE_ASSET_FILE=${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}
RELEASE_ASSET_PATH="../${RELEASE_ASSET_FILE}"
( shopt -s dotglob; zip -vr ${RELEASE_ASSET_PATH} * )
(
shopt -s dotglob
zip -vr ${RELEASE_ASSET_PATH} *
)
else
RELEASE_ASSET_EXT='.tar.gz'
MEDIA_TYPE='application/gzip'
RELEASE_ASSET_FILE=${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}
RELEASE_ASSET_PATH="../${RELEASE_ASSET_FILE}"
( shopt -s dotglob; tar cvfz ${RELEASE_ASSET_PATH} * )
(
shopt -s dotglob
tar cvfz ${RELEASE_ASSET_PATH} *
)
fi
elif [ ${INPUT_COMPRESS_ASSETS^^} == "OFF" ] || [ ${INPUT_COMPRESS_ASSETS^^} == "FALSE" ]; then
RELEASE_ASSET_EXT=${EXT}
Expand All @@ -165,34 +170,34 @@ SHA256_SUM=$(sha256sum ${RELEASE_ASSET_PATH} | cut -d ' ' -f 1)
# prefix upload extra params
GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS=''
if [ ${INPUT_OVERWRITE^^} == 'TRUE' ]; then
GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS="-overwrite"
GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS="-overwrite"
fi

if [ ${INPUT_UPLOAD^^} == 'TRUE' ]; then
# update binary and checksum
github-assets-uploader -logtostderr -f ${RELEASE_ASSET_PATH} -mediatype ${MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${RELEASE_REPO} -token ${INPUT_GITHUB_TOKEN} -tag=${RELEASE_TAG} -releasename=${RELEASE_NAME} -retry ${INPUT_RETRY}
if [ ${INPUT_MD5SUM^^} == 'TRUE' ]; then
# update binary and checksum
github-assets-uploader -logtostderr -f ${RELEASE_ASSET_PATH} -mediatype ${MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${RELEASE_REPO} -token ${INPUT_GITHUB_TOKEN} -tag=${RELEASE_TAG} -releasename=${RELEASE_NAME} -retry ${INPUT_RETRY}
if [ ${INPUT_MD5SUM^^} == 'TRUE' ]; then
MD5_EXT='.md5'
MD5_MEDIA_TYPE='text/plain'
echo ${MD5_SUM} >${RELEASE_ASSET_PATH}${MD5_EXT}
github-assets-uploader -logtostderr -f ${RELEASE_ASSET_PATH}${MD5_EXT} -mediatype ${MD5_MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${RELEASE_REPO} -token ${INPUT_GITHUB_TOKEN} -tag=${RELEASE_TAG} -releasename=${RELEASE_NAME} -retry ${INPUT_RETRY}
fi
fi

if [ ${INPUT_SHA256SUM^^} == 'TRUE' ]; then
if [ ${INPUT_SHA256SUM^^} == 'TRUE' ]; then
SHA256_EXT='.sha256'
SHA256_MEDIA_TYPE='text/plain'
echo ${SHA256_SUM} >${RELEASE_ASSET_PATH}${SHA256_EXT}
github-assets-uploader -logtostderr -f ${RELEASE_ASSET_PATH}${SHA256_EXT} -mediatype ${SHA256_MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${RELEASE_REPO} -token ${INPUT_GITHUB_TOKEN} -tag=${RELEASE_TAG} -releasename=${RELEASE_NAME} -retry ${INPUT_RETRY}
fi
fi
fi

ls -lha ../

# output path for use by other workflows (e.g.: actions/upload-artifact)
echo "release_asset_dir=${RELEASE_ASSET_DIR}" >> "${GITHUB_OUTPUT}"
echo "release_asset_dir=${RELEASE_ASSET_DIR}" >>"${GITHUB_OUTPUT}"

# execute post-command if exist, e.g. upload to AWS s3 or aliyun OSS
if [ ! -z "${INPUT_POST_COMMAND}" ]; then
INPUT_POST_COMMAND=${INPUT_POST_COMMAND/"{RELEASE_ASSET_DIR}"/${RELEASE_ASSET_DIR}}
eval ${INPUT_POST_COMMAND}
INPUT_POST_COMMAND=${INPUT_POST_COMMAND/"{RELEASE_ASSET_DIR}"/${RELEASE_ASSET_DIR}}
eval ${INPUT_POST_COMMAND}
fi

0 comments on commit 0b47d78

Please sign in to comment.