diff --git a/README.md b/README.md index cad357e..38e45f4 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ jobs: | retry | **Optional** | How many times retrying if upload fails. `3` by default. | | post_command | **Optional** | Extra command that will be executed for teardown work. e.g. you can use it to upload artifacts to AWS s3 or aliyun OSS | | compress_assets | **Optional** | `auto` default will produce a `zip` file for Windows and `tar.gz` for others. `zip` will force the use of `zip`. `OFF` will disable packaging of assets. | -| upload | **Optional** | Upload release or not upload. If you need to use subsequent workflow to process the file, you can choose not to upload the release. | +| upload | **Optional** | Upload release assets or not. It'll be useful if you'd like to use subsequent workflow to process the file, such as **signing it on macos**, and so on. | ### Output Parameters diff --git a/action.yml b/action.yml index 665bee8..f5adf41 100644 --- a/action.yml +++ b/action.yml @@ -100,7 +100,7 @@ inputs: required: false default: 'TRUE' upload: - description: 'Upload release or not upload' + description: 'Upload release assets or not' required: false default: 'TRUE' diff --git a/release.sh b/release.sh index 42a99e9..e90b322 100755 --- a/release.sh +++ b/release.sh @@ -17,21 +17,17 @@ elif [ ! -z "${INPUT_RELEASE_NAME}" ]; then # prevent upload-asset by tag due to RELEASE_TAG="" fi -if [ ! -z "${INPUT_RELEASE_NAME}" ]; then - RELEASE_NAME=${INPUT_RELEASE_NAME} -else - RELEASE_NAME=$(jq -r '.release.name' ${GITHUB_EVENT_PATH}) -fi +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} @@ -40,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" @@ -52,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 @@ -64,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 @@ -105,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 @@ -145,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} @@ -169,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