From 12bf6268208ff554c527389872ee4b916ee4d983 Mon Sep 17 00:00:00 2001 From: Damian Mee Date: Sun, 15 Mar 2020 20:05:22 +0800 Subject: [PATCH 1/4] 1st attempt at v2.0.0 --- .github/workflows/on-tag.yml | 25 ++--- Dockerfile | 7 +- README.md | 67 +++++++----- action.yml | 15 ++- entrypoint.sh | 205 +++++++++++++++++++---------------- 5 files changed, 175 insertions(+), 144 deletions(-) diff --git a/.github/workflows/on-tag.yml b/.github/workflows/on-tag.yml index a5594e8..74bdf56 100644 --- a/.github/workflows/on-tag.yml +++ b/.github/workflows/on-tag.yml @@ -3,8 +3,7 @@ name: Create shortened tags # Only triggered on git tag push on: push: - tags: - - '*' + tags: [ '*' ] jobs: shorten: @@ -15,29 +14,29 @@ jobs: - name: Make sure that current tag is merged to master run: | - cd "${GITHUB_WORKSPACE}" + cd "$GITHUB_WORKSPACE" git switch master # Returns 1 if it's not, and therefore terminates the workflow - git merge-base --is-ancestor "${GITHUB_SHA}" HEAD + git merge-base --is-ancestor "$GITHUB_SHA" HEAD - name: Create, or update the short-name branch run: | - cd "${GITHUB_WORKSPACE}" + cd "$GITHUB_WORKSPACE" - git config user.name "${GITHUB_ACTOR}" - git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - TAG=$(echo "${GITHUB_REF}" | awk -F/ '{print $NF}') - SHORT=$(echo "${TAG}" | tr -d v | cut -d. -f-2) + TAG=$(echo "$GITHUB_REF" | awk -F/ '{print $NF}') + SHORT=$(echo "${TAG#v}" | cut -d. -f-2) # Do nothing on test tags - if [[ "${SHORT}" = "0.0" ]]; then + if [[ "$SHORT" = "0.0" ]]; then exit 0 fi - git branch -f "${SHORT}" "${TAG}" + git branch -f "$SHORT" "$TAG" - REMOTE="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" - git push --force "${REMOTE}" "${SHORT}" + REMOTE="https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" + git push --force "$REMOTE" "$SHORT" diff --git a/Dockerfile b/Dockerfile index 4ad59df..39a1ee2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ -FROM alpine:3.10 +FROM alpine:3.11 -RUN apk update \ - && apk add file curl jq +RUN apk add --no-cache file curl jq COPY entrypoint.sh / -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/README.md b/README.md index a14df1b..52d3359 100644 --- a/README.md +++ b/README.md @@ -15,24 +15,29 @@ Github Action to create and update Github Releases, as well as upload assets to them. -> ### **NOTICE:** This action is now deprecated, and official actions should be used instead: + +> ### **NOTICE_2:** Deprecation temporarily cancelled, because GH actions are just awful. +> +> ### ~~**NOTICE:** This action is now deprecated, and official actions should be used instead:~~ > -> * https://github.com/actions/create-release -> * https://github.com/actions/upload-release-asset +> * ~~https://github.com/actions/create-release~~ +> * ~~https://github.com/actions/upload-release-asset~~ + # Usage See [action.yml](action.yml) + ### Minimal ```yaml steps: -- uses: actions/checkout@v1 +- uses: actions/checkout@v2 -- uses: meeDamian/github-release@1.0 +- uses: meeDamian/github-release@2.0 with: - token: ${{secrets.GITHUB_TOKEN}} + token: ${{ secrets.GITHUB_TOKEN }} ``` `token` is the only **always required** parameter to be passed to this action. Everything else can use sane defaults in some circumstances. See [arguments] to learn more. @@ -44,22 +49,23 @@ steps: All inputs are available as a _normal_ Action input, but because Github Actions don't accept shell variables there, some are also available as an Environment Variable set beforehand. When both set, one set as input takes precedence. -| name | ENV var alternative | required | description -|:----------------:|:-------------------:|:----------:|---------------- -| `token` | - | **always** | Github Access token. Can be accessed by using `${{secrets.GITHUB_TOKEN}}` in the workflow file. -| `tag` | `RELEASE_TAG` | sometimes | If triggered by git tag push, tag is picked up automatically. Otherwise `tag:` has to be set. For tags constructed dynamically, use `RELEASE_TAG` env var. -| `commitish` | - | no | Commit hash this release should point to. Unnecessary, if `tag` is a git tag. Otherwise, current `master` is used. [more] -| `name` | `RELEASE_NAME` | no | Place to name the release, the more creative, the better. Defaults to the name of the tag used. [more] -| `body` | - | no | Place to put a longer description of the release, ex changelog, or info about contributors. Defaults to the commit message of the reference commit. [more] -| `draft` | - | no | Set to `true` to create a release, but not publish it. `false` by default. [more] -| `prerelease` | - | no | Marks this release as a pre-release. `false` by default. [more] -| `files` | `RELEASE_FILES` | no | A **space-separated** list of files to be uploaded. When left empty, no files are uploaded. [More on files below] -| `gzip` | - | no | Set whether to `gzip` uploaded assets, or not. Available options are: `true`, `false`, and `folders` which uploads files unchanged, but compresses directories/folders. Defaults to `true`. Note: it errors if set to `false`, and `files:` argument contains path to a directory. -| `allow_override` | - | no | Allow override of release, if one with the same tag already exists. Defaults to `false` +| name | required | description +|:----------------:|:----------:|---------------- +| `token` | **always** | Github Access token. Can be accessed by using `${{ secrets.GITHUB_TOKEN }}` in the workflow file. +| `tag` | sometimes | If triggered by git tag push, tag is picked up automatically. Otherwise `tag:` has to be set. +| `commitish` | no | Commit hash this release should point to. Unnecessary, if `tag` is a git tag. Otherwise, current `master` is used. [more] +| `name` | no | Name the release, the more creative, the better. Defaults to the name of the tag used. [more] +| `body` | no | Longer description of the release, ex changelog, or info about contributors. Defaults to the commit message of the reference commit. [more] +| `draft` | no | Set to `true` to create a release, but not publish it. `false` by default. [more] +| `prerelease` | no | Mark this release as a pre-release. `false` by default. [more] +| `files` | no | A **space-separated** list of files to be uploaded. When left empty, no files are uploaded. [More on files below] +| `gzip` | no | Set whether to `gzip` uploaded assets, or not. Available options are: `true`, `false`, and `folders` which uploads files unchanged, but compresses directories/folders. Defaults to `true`. Note: it errors if set to `false`, and `files:` argument contains path to a directory. +| `allow_override` | no | Allow override of release, if one with the same tag already exists. Defaults to `false` [more]: https://developer.github.com/v3/repos/releases/#create-a-release [More on files below]: #Files-syntax + #### Using ENV vars In a step before this action, run ex: @@ -70,11 +76,13 @@ steps: - name: Set enviroment for github-release run: | echo ::set-env name=RELEASE_TAG::"v1.0.0" - echo ::set-env name=RELEASE_NAME::"${GITHUB_WORKFLOW}" + echo ::set-env name=RELEASE_NAME::"$GITHUB_WORKFLOW" - - uses: meeDamian/github-release@1.0 + - uses: meeDamian/github-release@2.0 with: - token: ${{secrets.GITHUB_TOKEN}} + token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ env.RELEASE_TAG }} + name: ${{ env.RELEASE_NAME }} ... ``` @@ -82,9 +90,10 @@ To learn more about notation used above see [this]. [this]: https://help.github.com/en/articles/development-tools-for-github-actions#set-an-environment-variable-set-env + #### Files syntax -In it's simplest form it takes a single file/folder to be compressed & uploaded: +In its simplest form it takes a single file/folder to be compressed & uploaded: ```yaml with: @@ -113,16 +122,17 @@ with: ``` [YAML multiline syntax]: https://yaml-multiline.info/ + ### Advanced example ```yaml steps: - uses: actions/checkout@master -- uses: meeDamian/github-release@0.1 +- uses: meeDamian/github-release@2.0 with: token: ${{ secrets.GITHUB_TOKEN }} - tag: v1.3.6 + tag: ${{ env.MY_CUSTOM_TAG }} name: My Creative Name body: > This release actually changes the fabric of the reality, so be careful @@ -151,13 +161,15 @@ In practice: ```yaml # For exact version steps: - uses: meeDamian/github-release@v1.0.1 + uses: meeDamian/github-release@v2.0.0 ``` + Or + ```yaml -# For newest minor version 1.0 +# For newest minor version 2.0 steps: - uses: meeDamian/github-release@1.0 + uses: meeDamian/github-release@2.0 ``` Note: It's likely branches will be deprecated once Github Actions fixes its limitation. @@ -165,6 +177,7 @@ Note: It's likely branches will be deprecated once Github Actions fixes its limi [The insane thing]: https://git-scm.com/docs/git-tag#_on_re_tagging [here]: .github/workflows/on-tag.yml + # License The scripts and documentation in this project are released under the [MIT License](LICENSE) diff --git a/action.yml b/action.yml index bb5673c..5552493 100644 --- a/action.yml +++ b/action.yml @@ -13,30 +13,33 @@ inputs: tag: description: > - A tag for the release. Required UNLESS action is run on tag push (meaning: `${GITHUB_REF}` contains `ref/tag/`). + A tag for the release. Required UNLESS action is run on tag push (meaning: `$GITHUB_REF` contains `ref/tag/`). required: false commitish: - description: Unnecessary, if the tag provided is a git tag. If it isn't release will be made off `master`. + description: Unnecessary, if the tag provided is a git tag. If it isn't, release will be made off `master`. required: false name: - description: Place to name the release, the more creative, the better. + description: Name the release, the more creative, the better. required: false body: - description: Place to put a longer description of the release, ex changelog, or info about contributors. + description: Longer description of the release, ex changelog, or info about contributors. required: false draft: - description: Set to true to create a release, but not publish it. + description: > + Whether to keep the Release as draft, and not publish it. Defaults to 'false', unless files are specified, when + a draft Release is created first, and published only if all asset uploads succeed. Prevent by explicitly setting + it to 'false'. required: false prerelease: description: Marks this as a pre-release. required: false - # This action specific inputs: + # Inputs specific to this-action: files: description: > A space-separated(!) list of files to be uploaded. It's impossible to pass a list here, so make sure filenames diff --git a/entrypoint.sh b/entrypoint.sh index 6343b98..8b93452 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,14 +3,14 @@ set -e # -# Input verification +## Input verification # -TOKEN="${INPUT_TOKEN}" -if [ -z "${TOKEN}" ]; then +TOKEN="$INPUT_TOKEN" +if [ -z "$TOKEN" ]; then >&2 printf "\nERR: Invalid input: 'token' is required, and must be specified.\n" >&2 printf "\tNote: It's necessary to interact with Github's API.\n\n" >&2 printf "Try:\n" - >&2 printf "\tuses: meeDamian/github-release@TAG\n" + >&2 printf "\tuses: meeDamian/github-release@2.0\n" >&2 printf "\twith:\n" >&2 printf "\t token: \${{ secrets.GITHUB_TOKEN }}\n" >&2 printf "\t ...\n" @@ -18,67 +18,59 @@ if [ -z "${TOKEN}" ]; then fi # Try getting $TAG from action input -TAG="${INPUT_TAG}" +tag="$INPUT_TAG" -# [fallback] Try getting $TAG from ENVironment VARiable -# NOTE: Can be set in a step before using ex: -# echo ::set-env name=RELEASE_TAG::"v1.0.0" -if [ -z "${TAG}" ]; then - TAG="${RELEASE_TAG}" +# [fallback] Try getting $tag from Github context (only works on git-tag push action) +if [ -z "$tag" ]; then + tag="$(echo "$GITHUB_REF" | grep 'refs/tags/' | awk -F/ '{ print $NF }')" fi -# [fallback] Try getting $TAG from Github context (only works on git-tag push action) -if [ -z "${TAG}" ]; then - TAG="$(echo "${GITHUB_REF}" | grep 'refs/tags/' | awk -F/ '{print $NF}')" -fi - -# If all ways of getting the TAG failed, exit with an error -if [ -z "${TAG}" ]; then +# If all ways of getting the $tag failed, exit with an error +if [ -z "$tag" ]; then >&2 printf "\nERR: Invalid input: 'tag' is required, and must be specified.\n" >&2 printf "Try:\n" - >&2 printf "\tuses: meeDamian/github-release@TAG\n" + >&2 printf "\tuses: meeDamian/github-release@2.0\n" >&2 printf "\twith:\n" >&2 printf "\t tag: v0.0.1\n" >&2 printf "\t ...\n\n" - >&2 printf "Note: To use dynamic TAG, set RELEASE_TAG env var in a prior step, ex:\n" - >&2 printf '\techo ::set-env name=RELEASE_TAG::"v1.0.0"\n\n' + >&2 printf "Note: To use \$tag from env variable set before, use:\n" + >&2 printf '\twith:\n' + >&2 printf "\t tag: \${{ env.TAG }}\n" + >&2 printf "\t ...\n\n" exit 1 fi # Verify that gzip: option is set to any of the allowed values -if [ "${INPUT_GZIP}" != "true" ] && [ "${INPUT_GZIP}" != "false" ] && [ "${INPUT_GZIP}" != "folders" ]; then +if [ "$INPUT_GZIP" != "true" ] && [ "$INPUT_GZIP" != "false" ] && [ "$INPUT_GZIP" != "folders" ]; then >&2 printf "\nERR: Invalid input: 'gzip' can only be not set, or one of: true, false, folders\n" >&2 printf "\tNote: It defines what to do with assets before uploading them.\n\n" >&2 printf "Try:\n" - >&2 printf "\tuses: meeDamian/github-release@TAG\n" + >&2 printf "\tuses: meeDamian/github-release@2.0\n" >&2 printf "\twith:\n" >&2 printf "\t gzip: true\n" >&2 printf "\t ...\n" exit 1 fi -BASE_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" +base_url="https://api.github.com/repos/$GITHUB_REPOSITORY/releases" + # ## Check for Github Release existence # -RELEASE_ID="$(curl -H "Authorization: token ${TOKEN}" "${BASE_URL}/tags/${TAG}" | jq -r '.id | select(. != null)')" +release_id="$(curl -H "Authorization: token $TOKEN" "$base_url/tags/$tag" | jq -r '.id | select(. != null)')" -if [ -n "${RELEASE_ID}" ] && [ "${INPUT_ALLOW_OVERRIDE}" != "true" ]; then - >&2 printf "\nERR: Release '%s' already exists, and overriding is not allowed.\n" "${TAG}" - >&2 printf "\tNote: Either use different 'tag:' name, or 'allow_override:'\n\n" +if [ -n "$release_id" ] && [ "$INPUT_ALLOW_OVERRIDE" != "true" ]; then + >&2 printf "\nERR: Release for tag='%s' already exists, and overriding is not allowed.\n" "$tag" + >&2 printf "\tNote: Either use different 'tag:' name, or set 'allow_override:'\n\n" >&2 printf "Try:\n" - >&2 printf "\tuses: meeDamian/github-release@TAG\n" + >&2 printf "\tuses: meeDamian/github-release@2.0\n" >&2 printf "\twith:\n" >&2 printf "\t ...\n" >&2 printf "\t allow_override: true\n" exit 1 fi -# If no `name:` passed as input, but RELEASE_NAME env var is set, use it as the name -if [ -z "${INPUT_NAME}" ] && [ -n "${RELEASE_NAME}" ]; then - INPUT_NAME="${RELEASE_NAME}" -fi # ## Create, or update release on Github @@ -98,81 +90,87 @@ toJsonOrNull() { echo "\"$1\"" } -METHOD="POST" -URL="${BASE_URL}" -if [ -n "${RELEASE_ID}" ]; then - METHOD="PATCH" - URL="${URL}/${RELEASE_ID}" +method="POST" +full_url="$base_url" +if [ -n "$release_id" ]; then + method="PATCH" + full_url="$full_url/$release_id" fi + +# If `draft` is not set, but `files` are provided, then +# 1. Create Release as draft +# 2. Upload all files as Release Assets +# 3. If all uploads succeed, publish the Release +draft="$INPUT_DRAFT" +if [ -z "$INPUT_DRAFT" ] && [ -n "$INPUT_FILES" ]; then + draft=true +fi + + # Creating the object in a PATCH-friendly way -CODE="$(jq -nc \ - --arg tag_name "${TAG}" \ - --argjson target_commitish "$(toJsonOrNull "${INPUT_COMMITISH}")" \ - --argjson name "$(toJsonOrNull "${INPUT_NAME}")" \ - --argjson body "$(toJsonOrNull "${INPUT_BODY}")" \ - --argjson draft "$(toJsonOrNull "${INPUT_DRAFT}")" \ - --argjson prerelease "$(toJsonOrNull "${INPUT_PRERELEASE}")" \ +status_code="$(jq -nc \ + --arg tag_name "$tag" \ + --argjson target_commitish "$(toJsonOrNull "$INPUT_COMMITISH")" \ + --argjson name "$(toJsonOrNull "$INPUT_NAME")" \ + --argjson body "$(toJsonOrNull "$INPUT_BODY")" \ + --argjson draft "$(toJsonOrNull "$draft")" \ + --argjson prerelease "$(toJsonOrNull "$INPUT_PRERELEASE")" \ '{$tag_name, $target_commitish, $name, $body, $draft, $prerelease} | del(.[] | nulls)' | \ - curl -s -X "${METHOD}" -d @- \ - --write-out "%{http_code}" -o "/tmp/${METHOD}.json" \ - -H "Authorization: token ${TOKEN}" \ + curl -s -X "$method" -d @- \ + --write-out "%{http_code}" -o "/tmp/$method.json" \ + -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ - "${URL}")" + "$full_url")" -if [ "${CODE}" != "200" ] && [ "${CODE}" != "201" ]; then - >&2 printf "\n\tERR: %s to Github release has failed\n" "${METHOD}" - >&2 jq < "/tmp/${METHOD}.json" +if [ "$status_code" != "200" ] && [ "$status_code" != "201" ]; then + >&2 printf "\n\tERR: %s to Github release has failed\n" "$method" + >&2 jq . < "/tmp/$method.json" exit 1 fi -RELEASE_ID="$(jq '.id' < "/tmp/${METHOD}.json")" +release_id="$(jq '.id' < "/tmp/$method.json")" + # ## Handle, and prepare assets # -# If no `files:` passed as input, but `RELEASE_FILES` env var is set, use it instead -if [ -z "${INPUT_FILES}" ] && [ -n "${RELEASE_FILES}" ]; then - INPUT_FILES="${RELEASE_FILES}" -fi - -if [ -z "${INPUT_FILES}" ]; then +if [ -z "$INPUT_FILES" ]; then >&2 echo "No assets to upload. All done." exit 0 fi -ASSETS="${HOME}/assets" +assets="$HOME/assets" -mkdir -p "${ASSETS}/" +mkdir -p "$assets/" # this loop splits files by the space -for entry in $(echo "${INPUT_FILES}" | tr ' ' '\n'); do - ASSET_NAME="${entry}" +for entry in $INPUT_FILES; do + asset_name="$entry" # Well, that needs explaining… If delimiter given in `-d` does not occur in string, `cut` always returns # the original string, no matter what the field `-f` specifies. # - # I'm prepanding `:` to `${entry}` in `echo` to ensure match happens, because once it does, `-f` is respected, - # and I can easily check fields, and that way: + # Prepend `:` to `$entry` to ensure match happens, because `-f` in `cut` is only respected when it does, and that way: # * `-f 2` always contains the name of the asset - # * `-f 3` is either the custom name of the asset, - # * `-f 3` is empty, and needs to be set to `-f 2` - ASSET_NAME="$(echo ":${entry}" | cut -d: -f2)" - ASSET_PATH="$(echo ":${entry}" | cut -d: -f3)" - - if [ -z "${ASSET_PATH}" ]; then - ASSET_NAME="$(basename "${entry}")" - ASSET_PATH="${entry}" + # * `-f 3` is either the custom name of the asset, or + # is empty, and needs to be set to value of `-f 2` + asset_name="$(echo ":$entry" | cut -d: -f2)" + asset_path="$(echo ":$entry" | cut -d: -f3)" + + if [ -z "$asset_path" ]; then + asset_name="$(basename "$entry")" + asset_path="$entry" fi # this loop, expands possible globs - for file in ${ASSET_PATH}; do - # Error out on the only illegal combination: compression disabled, and folder provided - if [ "${INPUT_GZIP}" = "false" ] && [ -d "${file}" ]; then + for file in $asset_path; do + # Error out on the only illegal combination: compression disabled AND folder provided + if [ "$INPUT_GZIP" = "false" ] && [ -d "$file" ]; then >&2 printf "\nERR: Invalid configuration: 'gzip' cannot be set to 'false' while there are 'folders/' provided.\n" >&2 printf "\tNote: Either set 'gzip: folders', or remove directories from the 'files:' list.\n\n" >&2 printf "Try:\n" - >&2 printf "\tuses: meeDamian/github-release@TAG\n" + >&2 printf "\tuses: meeDamian/github-release@2.0\n" >&2 printf "\twith:\n" >&2 printf "\t ...\n" >&2 printf "\t gzip: folders\n" @@ -183,38 +181,57 @@ for entry in $(echo "${INPUT_FILES}" | tr ' ' '\n'); do fi # Just copy files, if compression not enabled for all - if [ "${INPUT_GZIP}" != "true" ] && [ -f "${file}" ]; then - cp "${file}" "${ASSETS}/${ASSET_NAME}" + if [ "$INPUT_GZIP" != "true" ] && [ -f "$file" ]; then + cp "$file" "$assets/$asset_name" continue fi # In any other case compress - tar -cf "${ASSETS}/${ASSET_NAME}.tgz" "${file}" + tar -cf "$assets/$asset_name.tgz" "$file" done done -# At this point all assets to-be-uploaded (if any), are in `${ASSETS}/` folder +# At this point all assets to-be-uploaded (if any), are in `$assets/` folder echo "Files to be uploaded to Github:" -ls "${ASSETS}/" +ls "$assets/" -UPLOAD_URL="$(echo "${BASE_URL}" | sed -e 's/api/uploads/')" +upload_url="$(echo "$base_url" | sed -e 's/api/uploads/')" -for asset in "${ASSETS}"/*; do - FILE_NAME="$(basename "${asset}")" +for asset in "$assets"/*; do + file_name="$(basename "$asset")" - CODE="$(curl -sS -X POST \ - --write-out "%{http_code}" -o "/tmp/${FILE_NAME}.json" \ - -H "Authorization: token ${TOKEN}" \ - -H "Content-Length: $(stat -c %s "${asset}")" \ - -H "Content-Type: $(file -b --mime-type "${asset}")" \ - --upload-file "${asset}" \ - "${UPLOAD_URL}/${RELEASE_ID}/assets?name=${FILE_NAME}")" + status_code="$(curl -sS -X POST \ + --write-out "%{http_code}" -o "/tmp/$file_name.json" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Length: $(stat -c %s "$asset")" \ + -H "Content-Type: $(file -b --mime-type "$asset")" \ + --upload-file "$asset" \ + "$upload_url/$release_id/assets?name=$file_name")" - if [ "${CODE}" -ne "201" ]; then - >&2 printf "\n\tERR: Uploading %s to Github release has failed\n" "${FILE_NAME}" - jq < "/tmp/${FILE_NAME}.json" + if [ "$status_code" -ne "201" ]; then + >&2 printf "\n\tERR: Failed asset upload: %s\n" "$file_name" + >&2 jq . < "/tmp/$file_name.json" exit 1 fi done +if [ -n "$INPUT_DRAFT" ]; then + >&2 echo "Draft status already correct. All done." + exit 0 +fi + + +# Publish Release +status_code="$(curl -s -X 'PATCH' -d '{"draft": false}' \ + --write-out "%{http_code}" -o /tmp/publish.json \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + "$base_url/$release_id")" + +if [ "$status_code" != "200" ]; then + >&2 printf "\n\tERR: Final publishing of the ready Github Release has failed\n" + >&2 jq . < /tmp/publish.json + exit 1 +fi + >&2 echo "All done." From 3ca6149fed5469802c93f3f86d21449ad018eb3f Mon Sep 17 00:00:00 2001 From: Damian Mee Date: Sun, 15 Mar 2020 20:22:15 +0800 Subject: [PATCH 2/4] Attempt at fixing new lines in body: --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8b93452..375c69a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -111,11 +111,11 @@ fi # Creating the object in a PATCH-friendly way status_code="$(jq -nc \ --arg tag_name "$tag" \ + --argjson draft "$(toJsonOrNull "$draft")" \ --argjson target_commitish "$(toJsonOrNull "$INPUT_COMMITISH")" \ --argjson name "$(toJsonOrNull "$INPUT_NAME")" \ - --argjson body "$(toJsonOrNull "$INPUT_BODY")" \ - --argjson draft "$(toJsonOrNull "$draft")" \ --argjson prerelease "$(toJsonOrNull "$INPUT_PRERELEASE")" \ + --argjson body "$(toJsonOrNull "$(echo "$INPUT_BODY" | sed -z 's/\n/\\n/g')")" \ '{$tag_name, $target_commitish, $name, $body, $draft, $prerelease} | del(.[] | nulls)' | \ curl -s -X "$method" -d @- \ --write-out "%{http_code}" -o "/tmp/$method.json" \ From 59ad02efb57ba7ae130f726bf273c0c26fde28df Mon Sep 17 00:00:00 2001 From: Damian Mee Date: Sun, 15 Mar 2020 20:27:11 +0800 Subject: [PATCH 3/4] Add more capable sed --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 39a1ee2..0a3a880 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.11 -RUN apk add --no-cache file curl jq +RUN apk add --no-cache sed file curl jq COPY entrypoint.sh / From fb49d824fbefed39350913deaa581e3d660f9e8e Mon Sep 17 00:00:00 2001 From: Damian Mee Date: Sun, 15 Mar 2020 20:34:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Another=20take=20on=20sed=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- entrypoint.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0a3a880..39a1ee2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.11 -RUN apk add --no-cache sed file curl jq +RUN apk add --no-cache file curl jq COPY entrypoint.sh / diff --git a/entrypoint.sh b/entrypoint.sh index 375c69a..851ac65 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -115,7 +115,7 @@ status_code="$(jq -nc \ --argjson target_commitish "$(toJsonOrNull "$INPUT_COMMITISH")" \ --argjson name "$(toJsonOrNull "$INPUT_NAME")" \ --argjson prerelease "$(toJsonOrNull "$INPUT_PRERELEASE")" \ - --argjson body "$(toJsonOrNull "$(echo "$INPUT_BODY" | sed -z 's/\n/\\n/g')")" \ + --argjson body "$(toJsonOrNull "$(echo "$INPUT_BODY" | sed ':a;N;$!ba;s/\n/\\n/g')")" \ '{$tag_name, $target_commitish, $name, $body, $draft, $prerelease} | del(.[] | nulls)' | \ curl -s -X "$method" -d @- \ --write-out "%{http_code}" -o "/tmp/$method.json" \