From cafb3f39de45a9fcae25747b0a959d997d391a33 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 2 Nov 2020 09:41:38 +0000 Subject: [PATCH 01/19] feat: allow to set release_tag to upload binaries to one page --- action.yml | 5 +++++ release.sh | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 6286bbe..1c5092c 100644 --- a/action.yml +++ b/action.yml @@ -51,6 +51,10 @@ inputs: description: 'Publish `.md5` along with artifacts.' required: false default: 'TRUE' + release_tag: + description: 'Upload binaries to specified release page that indicated by Git tag.' + required: false + default: '' runs: using: 'docker' @@ -68,6 +72,7 @@ runs: - ${{ inputs.build_command }} - ${{ inputs.extra_files }} - ${{ inputs.md5sum }} + - ${{ inputs.release_tag }} branding: icon: 'package' diff --git a/release.sh b/release.sh index e988589..d84a7f7 100755 --- a/release.sh +++ b/release.sh @@ -5,11 +5,22 @@ BINARY_NAME=$(basename ${GITHUB_REPOSITORY}) if [ x${INPUT_BINARY_NAME} != x ]; then BINARY_NAME=${INPUT_BINARY_NAME} fi -RELEASE_TAG=$(basename ${GITHUB_REF}) +if [ ! -z "${INPUT_RELEASE_TAG}" ]; then + RELEASE_TAG=${INPUT_RELEASE_TAG} +else + # have to triggered by 'release: [create]' event, so that we can parse the tag from ref + RELEASE_TAG=$(basename ${GITHUB_REF}) +fi RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} # prepare upload URL -RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) +if [ ${GITHUB_EVENT_NAME} == 'release' ]; then + # only for 'release: [created]' event, we can parse event directly to get upload_url + RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) +else + # otherwise we have to get upload url via Github API, e.g., triggerred by 'push' event that no upload url info + RELEASE_ASSETS_UPLOAD_URL=$(curl "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_TAG}" | jq -r .upload_url) +fi RELEASE_ASSETS_UPLOAD_URL=${RELEASE_ASSETS_UPLOAD_URL%\{?name,label\}} # execute pre-command if exist, e.g. `go get -v ./...` From 53b645838a84663c947d4b792aa93be7dcc8b893 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 2 Nov 2020 10:04:32 +0000 Subject: [PATCH 02/19] fix: auto add short sha in release asset name for non-release event to avoid conflict release name --- release.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/release.sh b/release.sh index d84a7f7..f22df39 100755 --- a/release.sh +++ b/release.sh @@ -10,16 +10,17 @@ if [ ! -z "${INPUT_RELEASE_TAG}" ]; then else # have to triggered by 'release: [create]' event, so that we can parse the tag from ref RELEASE_TAG=$(basename ${GITHUB_REF}) -fi -RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} +fi -# prepare upload URL +# prepare upload URL and asset name if [ ${GITHUB_EVENT_NAME} == 'release' ]; then # only for 'release: [created]' event, we can parse event directly to get upload_url RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) + RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} else # otherwise we have to get upload url via Github API, e.g., triggerred by 'push' event that no upload url info - RELEASE_ASSETS_UPLOAD_URL=$(curl "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_TAG}" | jq -r .upload_url) + RELEASE_ASSETS_UPLOAD_URL=$(curl "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_TAG}" | jq -r .upload_url) + RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${GITHUB_SHA::7}-${INPUT_GOOS}-${INPUT_GOARCH} fi RELEASE_ASSETS_UPLOAD_URL=${RELEASE_ASSETS_UPLOAD_URL%\{?name,label\}} From 2c737cbac515da0da9e8b576302b9f7425306460 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Tue, 3 Nov 2020 09:40:54 +0000 Subject: [PATCH 03/19] feat: format release asset name as '{binary_name}-{branch_name}-{date}-{shortsha}-{OS}-{ARCH}' --- release.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/release.sh b/release.sh index f22df39..c41fde7 100755 --- a/release.sh +++ b/release.sh @@ -5,22 +5,18 @@ BINARY_NAME=$(basename ${GITHUB_REPOSITORY}) if [ x${INPUT_BINARY_NAME} != x ]; then BINARY_NAME=${INPUT_BINARY_NAME} fi -if [ ! -z "${INPUT_RELEASE_TAG}" ]; then - RELEASE_TAG=${INPUT_RELEASE_TAG} -else - # have to triggered by 'release: [create]' event, so that we can parse the tag from ref - RELEASE_TAG=$(basename ${GITHUB_REF}) -fi # prepare upload URL and asset name if [ ${GITHUB_EVENT_NAME} == 'release' ]; then # only for 'release: [created]' event, we can parse event directly to get upload_url RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) + RELEASE_TAG=$(basename ${GITHUB_REF}) RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} else - # otherwise we have to get upload url via Github API, e.g., triggerred by 'push' event that no upload url info - RELEASE_ASSETS_UPLOAD_URL=$(curl "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_TAG}" | jq -r .upload_url) - RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${GITHUB_SHA::7}-${INPUT_GOOS}-${INPUT_GOARCH} + # otherwise we have to get upload url via Github API, e.g., triggerred by 'push' event that no upload url info. 'INPUT_RELEASE_TAG' has to be set in this case. + RELEASE_ASSETS_UPLOAD_URL=$(curl "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${INPUT_RELEASE_TAG}" | jq -r .upload_url) + BRANCH_NAME=$(basename ${GITHUB_REF}) + RELEASE_ASSET_NAME=${BINARY_NAME}-${BRANCH_NAME}-$(date -u +%Y%m%d)-${GITHUB_SHA::7}-${INPUT_GOOS}-${INPUT_GOARCH} fi RELEASE_ASSETS_UPLOAD_URL=${RELEASE_ASSETS_UPLOAD_URL%\{?name,label\}} From 5df0b5cbcedc70d403af7bcd3547c4528eb12996 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Tue, 3 Nov 2020 09:50:17 +0000 Subject: [PATCH 04/19] docs: intro to 'release_tag' parameter --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18a9a98..6e0bd1e 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Automatically publish `Go` binaries to Github Release Assets through Github Acti - Support package extra files into artifacts (e.g., `LICENSE`, `README.md`, etc). - Support customize build command, e.g., use [packr2](https://github.com/gobuffalo/packr/tree/master/v2)(`packr2 build`) instead of `go build`. - Support optional `.md5` along with artifacts. +- Customizable release tag to support publish binaries per `push`. ## Usage @@ -57,7 +58,7 @@ jobs: | ldflags | **Optional** | Values to provide to the `-ldflags` argument. | | extra_files | **Optional** | Extra files that will be packaged into artifacts either. Multiple files separated by space. Note that extra folders can be allowed either since internal `cp -r` already in use.
E.g., `extra_files: LICENSE README.md` | | md5sum | **Optional** | Publish `.md5` along with artifacts, `TRUE` by default. | - +| release_tag | **Optional** | Target release tag to publish your binaries to. It's dedicated to publish binaries on every `push` into one specified release page since there's no target in this case. DON'T set it if you trigger the action by `release: [created]` event as most people do.| ### Advanced Example From 978a61196b978fad493119eed428e4d523cc410f Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Tue, 3 Nov 2020 09:56:53 +0000 Subject: [PATCH 05/19] feat: only support 'release' and 'push' event --- release.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release.sh b/release.sh index c41fde7..c880580 100755 --- a/release.sh +++ b/release.sh @@ -12,11 +12,14 @@ if [ ${GITHUB_EVENT_NAME} == 'release' ]; then RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) RELEASE_TAG=$(basename ${GITHUB_REF}) RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} -else +elif [ ${GITHUB_EVENT_NAME} == 'push' ]; then # otherwise we have to get upload url via Github API, e.g., triggerred by 'push' event that no upload url info. 'INPUT_RELEASE_TAG' has to be set in this case. RELEASE_ASSETS_UPLOAD_URL=$(curl "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${INPUT_RELEASE_TAG}" | jq -r .upload_url) BRANCH_NAME=$(basename ${GITHUB_REF}) RELEASE_ASSET_NAME=${BINARY_NAME}-${BRANCH_NAME}-$(date -u +%Y%m%d)-${GITHUB_SHA::7}-${INPUT_GOOS}-${INPUT_GOARCH} +else + echo "Unsupport event: ${GITHUB_EVENT_NAME}!" + exit 1 fi RELEASE_ASSETS_UPLOAD_URL=${RELEASE_ASSETS_UPLOAD_URL%\{?name,label\}} From 37ae8fa16ba011bc0850be150accbeefaca365f6 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 15:30:12 +0800 Subject: [PATCH 06/19] feat: fix release_asset_name since there may no requirement to publish many assets --- release.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/release.sh b/release.sh index c880580..a075b11 100755 --- a/release.sh +++ b/release.sh @@ -1,22 +1,23 @@ #!/bin/bash -eux -# prepare binary/release name +# prepare binary_name/release_tag/release_asset_name BINARY_NAME=$(basename ${GITHUB_REPOSITORY}) if [ x${INPUT_BINARY_NAME} != x ]; then BINARY_NAME=${INPUT_BINARY_NAME} fi +RELEASE_TAG=$(basename ${GITHUB_REF}) +if [ ! -z "${INPUT_RELEASE_TAG}" ]; then + RELEASE_TAG=${INPUT_RELEASE_TAG} +fi +RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} # prepare upload URL and asset name if [ ${GITHUB_EVENT_NAME} == 'release' ]; then # only for 'release: [created]' event, we can parse event directly to get upload_url RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) - RELEASE_TAG=$(basename ${GITHUB_REF}) - RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} elif [ ${GITHUB_EVENT_NAME} == 'push' ]; then # otherwise we have to get upload url via Github API, e.g., triggerred by 'push' event that no upload url info. 'INPUT_RELEASE_TAG' has to be set in this case. RELEASE_ASSETS_UPLOAD_URL=$(curl "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${INPUT_RELEASE_TAG}" | jq -r .upload_url) - BRANCH_NAME=$(basename ${GITHUB_REF}) - RELEASE_ASSET_NAME=${BINARY_NAME}-${BRANCH_NAME}-$(date -u +%Y%m%d)-${GITHUB_SHA::7}-${INPUT_GOOS}-${INPUT_GOARCH} else echo "Unsupport event: ${GITHUB_EVENT_NAME}!" exit 1 From d0b22208d86d2c29fef14891b7e5db70cf782aa9 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 19:08:34 +0800 Subject: [PATCH 07/19] feat: inject github-assets-uploader cli --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index 0baf213..927e6f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,12 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteract zip \ jq +# github-assets-uploader to provide robust github assets upload +RUN wget --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.0/github-assets-uploader-v0.1.0-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ + tar -zxf github-assets-uploader.tar.gz && \ + mv github-assets-uploader /usr/sbin/ && \ + rm -f github-assets-uploader.tar.gz && \ + github-assets-uploader -version COPY *.sh / ENTRYPOINT ["/entrypoint.sh"] From 7ef1214a11922fe8a8e60283f18a87263953cd05 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 19:13:59 +0800 Subject: [PATCH 08/19] chore: reduce docker size, update uploader to v0.1.1 to refresh cdn cache --- Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 927e6f9..f0b6c4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,17 @@ FROM debian:stretch-slim -RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ +RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ curl \ wget \ git \ build-essential \ zip \ - jq + jq \ + && rm -rf /var/lib/apt/lists/* # github-assets-uploader to provide robust github assets upload -RUN wget --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.0/github-assets-uploader-v0.1.0-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ +RUN wget --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.1/github-assets-uploader-v0.1.1-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ tar -zxf github-assets-uploader.tar.gz && \ mv github-assets-uploader /usr/sbin/ && \ rm -f github-assets-uploader.tar.gz && \ From 4fbbbc37b8f1e8832f6b17b183c0c2183ccf7fd7 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 19:17:23 +0800 Subject: [PATCH 09/19] fix: certificate issue --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f0b6c4f..a20dc26 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,11 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteract build-essential \ zip \ jq \ + ca-certificates \ && rm -rf /var/lib/apt/lists/* # github-assets-uploader to provide robust github assets upload -RUN wget --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.1/github-assets-uploader-v0.1.1-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ +RUN wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.1/github-assets-uploader-v0.1.1-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ tar -zxf github-assets-uploader.tar.gz && \ mv github-assets-uploader /usr/sbin/ && \ rm -f github-assets-uploader.tar.gz && \ From bccf5c6a6eeda82396ae00a7f4002c55686a9731 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 19:26:02 +0800 Subject: [PATCH 10/19] fix: update github-assets-uploader to v0.1.2 to fix -version error --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a20dc26..4161b7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteract && rm -rf /var/lib/apt/lists/* # github-assets-uploader to provide robust github assets upload -RUN wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.1/github-assets-uploader-v0.1.1-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ +RUN wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.2/github-assets-uploader-v0.1.2-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ tar -zxf github-assets-uploader.tar.gz && \ mv github-assets-uploader /usr/sbin/ && \ rm -f github-assets-uploader.tar.gz && \ From 743543b1e3f22b639b0e72b2797bffa426906e65 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 19:42:11 +0800 Subject: [PATCH 11/19] feat: try out github-assets_uploader instead of curl --- Dockerfile | 2 +- release.sh | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4161b7e..81c2d34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteract && rm -rf /var/lib/apt/lists/* # github-assets-uploader to provide robust github assets upload -RUN wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.2/github-assets-uploader-v0.1.2-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ +RUN wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.3/github-assets-uploader-v0.1.3-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ tar -zxf github-assets-uploader.tar.gz && \ mv github-assets-uploader /usr/sbin/ && \ rm -f github-assets-uploader.tar.gz && \ diff --git a/release.sh b/release.sh index a075b11..114f56b 100755 --- a/release.sh +++ b/release.sh @@ -59,8 +59,10 @@ ls -lha # compress and package binary, then calculate checksum RELEASE_ASSET_EXT='.tar.gz' +MEDIA_TYPE='application/gzip' if [ ${INPUT_GOOS} == 'windows' ]; then RELEASE_ASSET_EXT='.zip' +MEDIA_TYPE='application/zip' zip -vr ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} * else tar cvfz ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} * @@ -68,14 +70,7 @@ fi MD5_SUM=$(md5sum ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} | cut -d ' ' -f 1) # update binary and checksum -curl \ - --fail \ - -X POST \ - --data-binary @${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} \ - -H 'Content-Type: application/gzip' \ - -H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \ - "${RELEASE_ASSETS_UPLOAD_URL}?name=${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}" -echo $? +github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -mediatype ${MEDIA_TYPE} -tag ${RELEASE_TAG} if [ ${INPUT_MD5SUM^^} == 'TRUE' ]; then curl \ From b9388dd786e3d8757bb1b0a5d146d272fb004726 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 22:58:26 +0800 Subject: [PATCH 12/19] feat: upload md5 by github-assets-uploader too --- release.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/release.sh b/release.sh index 114f56b..225d38d 100755 --- a/release.sh +++ b/release.sh @@ -69,16 +69,12 @@ tar cvfz ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} * fi MD5_SUM=$(md5sum ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} | cut -d ' ' -f 1) -# update binary and checksum -github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -mediatype ${MEDIA_TYPE} -tag ${RELEASE_TAG} +MD5_EXT='.md5' +MD5_MEDIA_TYPE='text/plain' +echo ${MD5_SUM} >${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} +# update binary and checksum +github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} -mediatype ${MEDIA_TYPE} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} if [ ${INPUT_MD5SUM^^} == 'TRUE' ]; then -curl \ - --fail \ - -X POST \ - --data ${MD5_SUM} \ - -H 'Content-Type: text/plain' \ - -H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \ - "${RELEASE_ASSETS_UPLOAD_URL}?name=${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}.md5" -echo $? +github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} -mediatype ${MD5_MEDIA_TYPE} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} fi From b030b1c550d9828c3db680c5df483268d2f97e88 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 23:08:28 +0800 Subject: [PATCH 13/19] chore: upload github-assets-uploader to v0.2.0 to enable the overwrite feature --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 81c2d34..c1dd0b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteract && rm -rf /var/lib/apt/lists/* # github-assets-uploader to provide robust github assets upload -RUN wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.1.3/github-assets-uploader-v0.1.3-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ +RUN wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.2.0/github-assets-uploader-v0.2.0-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \ tar -zxf github-assets-uploader.tar.gz && \ mv github-assets-uploader /usr/sbin/ && \ rm -f github-assets-uploader.tar.gz && \ From e48cfb0130fbf0589b538ee6df827aa99616d70f Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 23:10:35 +0800 Subject: [PATCH 14/19] feat: implements overwrite assets --- README.md | 2 ++ action.yml | 5 +++++ release.sh | 17 +++++++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6e0bd1e..989ff50 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Automatically publish `Go` binaries to Github Release Assets through Github Acti - Support customize build command, e.g., use [packr2](https://github.com/gobuffalo/packr/tree/master/v2)(`packr2 build`) instead of `go build`. - Support optional `.md5` along with artifacts. - Customizable release tag to support publish binaries per `push`. +- Support overwrite assets if it's already exist. ## Usage @@ -59,6 +60,7 @@ jobs: | extra_files | **Optional** | Extra files that will be packaged into artifacts either. Multiple files separated by space. Note that extra folders can be allowed either since internal `cp -r` already in use.
E.g., `extra_files: LICENSE README.md` | | md5sum | **Optional** | Publish `.md5` along with artifacts, `TRUE` by default. | | release_tag | **Optional** | Target release tag to publish your binaries to. It's dedicated to publish binaries on every `push` into one specified release page since there's no target in this case. DON'T set it if you trigger the action by `release: [created]` event as most people do.| +| overwrite | **Optional** | Overwrite asset if it's alreaddy exist.| ### Advanced Example diff --git a/action.yml b/action.yml index 1c5092c..c2751c6 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,10 @@ inputs: description: 'Upload binaries to specified release page that indicated by Git tag.' required: false default: '' + overwrite: + description: 'Overwrite asset if it's already exist.' + required: false + default: 'FALSE' runs: using: 'docker' @@ -73,6 +77,7 @@ runs: - ${{ inputs.extra_files }} - ${{ inputs.md5sum }} - ${{ inputs.release_tag }} + - ${{ inputs.overwrite }} branding: icon: 'package' diff --git a/release.sh b/release.sh index 225d38d..7bce682 100755 --- a/release.sh +++ b/release.sh @@ -11,18 +11,13 @@ if [ ! -z "${INPUT_RELEASE_TAG}" ]; then fi RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} -# prepare upload URL and asset name +# prompt error if non-supported event if [ ${GITHUB_EVENT_NAME} == 'release' ]; then - # only for 'release: [created]' event, we can parse event directly to get upload_url - RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) elif [ ${GITHUB_EVENT_NAME} == 'push' ]; then - # otherwise we have to get upload url via Github API, e.g., triggerred by 'push' event that no upload url info. 'INPUT_RELEASE_TAG' has to be set in this case. - RELEASE_ASSETS_UPLOAD_URL=$(curl "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${INPUT_RELEASE_TAG}" | jq -r .upload_url) else echo "Unsupport event: ${GITHUB_EVENT_NAME}!" exit 1 fi -RELEASE_ASSETS_UPLOAD_URL=${RELEASE_ASSETS_UPLOAD_URL%\{?name,label\}} # execute pre-command if exist, e.g. `go get -v ./...` if [ ! -z "${INPUT_PRE_COMMAND}" ]; then @@ -73,8 +68,14 @@ MD5_EXT='.md5' MD5_MEDIA_TYPE='text/plain' echo ${MD5_SUM} >${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} +# prefix upload extra params +GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS='' +if [ ! -z "${INPUT_OVERWRITE}" ]; then + GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS="-overwrite" +fi + # update binary and checksum -github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} -mediatype ${MEDIA_TYPE} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} +github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} -mediatype ${MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} if [ ${INPUT_MD5SUM^^} == 'TRUE' ]; then -github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} -mediatype ${MD5_MEDIA_TYPE} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} +github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} -mediatype ${MD5_MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} fi From d11c5a73287923ea06353a21c31b6d6f89449959 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 23:12:43 +0800 Subject: [PATCH 15/19] fix: overwrite checking --- release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.sh b/release.sh index 7bce682..eb03391 100755 --- a/release.sh +++ b/release.sh @@ -70,7 +70,7 @@ echo ${MD5_SUM} >${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} # prefix upload extra params GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS='' -if [ ! -z "${INPUT_OVERWRITE}" ]; then +if [ ${INPUT_OVERWRITE^^} == 'TRUE' ]; then GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS="-overwrite" fi From d926610706fff08f48bfaef3c9be0308e2d51ab0 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 23:18:07 +0800 Subject: [PATCH 16/19] fix: syntax --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c2751c6..5a127ef 100644 --- a/action.yml +++ b/action.yml @@ -56,7 +56,7 @@ inputs: required: false default: '' overwrite: - description: 'Overwrite asset if it's already exist.' + description: "Overwrite asset if it's already exist." required: false default: 'FALSE' From bf813d1e2c5c8650805c12dba85a594403886ffc Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 4 Nov 2020 23:22:47 +0800 Subject: [PATCH 17/19] fix: echo to avoid syntax error --- release.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release.sh b/release.sh index eb03391..ba3a265 100755 --- a/release.sh +++ b/release.sh @@ -13,7 +13,9 @@ RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} # prompt error if non-supported event if [ ${GITHUB_EVENT_NAME} == 'release' ]; then + echo "Event: ${GITHUB_EVENT_NAME}" elif [ ${GITHUB_EVENT_NAME} == 'push' ]; then + echo "Event: ${GITHUB_EVENT_NAME}" else echo "Unsupport event: ${GITHUB_EVENT_NAME}!" exit 1 From 3c5c54d315ea71c071baeb7b53aa052e6bf205ea Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Fri, 13 Nov 2020 14:20:02 +0000 Subject: [PATCH 18/19] feat: upload sha256 via github-assets-uploader also --- release.sh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/release.sh b/release.sh index b323f49..76d499e 100755 --- a/release.sh +++ b/release.sh @@ -67,10 +67,6 @@ fi MD5_SUM=$(md5sum ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} | cut -d ' ' -f 1) SHA256_SUM=$(sha256sum ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} | cut -d ' ' -f 1) -MD5_EXT='.md5' -MD5_MEDIA_TYPE='text/plain' -echo ${MD5_SUM} >${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} - # prefix upload extra params GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS='' if [ ${INPUT_OVERWRITE^^} == 'TRUE' ]; then @@ -80,16 +76,15 @@ fi # update binary and checksum github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT} -mediatype ${MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} if [ ${INPUT_MD5SUM^^} == 'TRUE' ]; then +MD5_EXT='.md5' +MD5_MEDIA_TYPE='text/plain' +echo ${MD5_SUM} >${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${MD5_EXT} -mediatype ${MD5_MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} fi if [ ${INPUT_SHA256SUM^^} == 'TRUE' ]; then -curl \ - --fail \ - --X POST \ - --data ${SHA256_SUM} \ - -H 'Content-Type: text/plain' \ - -H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \ - "${RELEASE_ASSETS_UPLOAD_URL}?name=${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}.sha256" -echo $? +SHA256_EXT='.sha256' +SHA256_MEDIA_TYPE='text/plain' +echo ${SHA256_SUM} >${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${SHA256_EXT} +github-assets-uploader -f ${RELEASE_ASSET_NAME}${RELEASE_ASSET_EXT}${SHA256_EXT} -mediatype ${SHA256_MEDIA_TYPE} ${GITHUB_ASSETS_UPLOADR_EXTRA_OPTIONS} -repo ${GITHUB_REPOSITORY} -token ${INPUT_GITHUB_TOKEN} -tag ${RELEASE_TAG} fi From aea8b258987d51128de26fb97639b738b7f4934b Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Fri, 13 Nov 2020 14:29:10 +0000 Subject: [PATCH 19/19] docs: description for overwrite --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 74fe084..48866b8 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ jobs: | md5sum | **Optional** | Publish `.md5` along with artifacts, `TRUE` by default. | | sha256sum | **Optional** | Publish `.sha256` along with artifacts, `FALSE` by default. | | release_tag | **Optional** | Target release tag to publish your binaries to. It's dedicated to publish binaries on every `push` into one specified release page since there's no target in this case. DON'T set it if you trigger the action by `release: [created]` event as most people do.| -| overwrite | **Optional** | Overwrite asset if it's alreaddy exist.| +| overwrite | **Optional** | Overwrite asset if it's already exist. `FALSE` by default. | ### Advanced Example