Skip to content

Commit

Permalink
fix github-release.sh, fix bad quotes, and use awk to make the script…
Browse files Browse the repository at this point in the history
… work on macos (#47)
  • Loading branch information
barchetta committed Sep 15, 2018
1 parent 8d9eaf8 commit 40d76b2
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions etc/scripts/github-release.sh 100644 → 100755
Expand Up @@ -59,7 +59,7 @@ for ((i=0;i<${#ARGS[@]};i++))
{
ARG=${ARGS[${i}]}
case ${ARG} in
"--changelog=")
"--changelog="*)
readonly CHANGELOG=${ARG#*=}
;;
"--version="*)
Expand All @@ -71,7 +71,7 @@ for ((i=0;i<${#ARGS[@]};i++))
;;
*)
if [ -z "${CHANGELOG}" ] || [ ! -f "${CHANGELOG}" ]; then
echo "ERROR: invalid changelog: ${CHANGELOG}.
echo "ERROR: invalid changelog: ${CHANGELOG}."
exit 1
elif [ -z "${version}" ]; then
echo "ERROR: no version provided"
Expand All @@ -82,7 +82,7 @@ for ((i=0;i<${#ARGS[@]};i++))
}

if [ -z "${GITHUB_API_KEY}" ] ; then
echo "ERROR: GITHUB_API_KEY is not set
echo "ERROR: GITHUB_API_KEY is not set"
exit 1
fi

Expand All @@ -91,7 +91,7 @@ readonly MEDIA_TYPE="application/vnd.github.v3+json"
readonly GITHUB_OWNER="oracle"
readonly REPO="helidon"

BODY=$(cat ${CHANGELOG} | sed -n ':a;N;${s/\n/\\n/g;p};ba' | sed -e 's/"/\\"/g')
BODY=$(cat ${CHANGELOG} | awk '{printf "%s\\n", $0;}' | sed -e 's/"/\\"/g')
PAYLOAD="{
\"tag_name\": \"${VERSION}\",
\"name\": \"${VERSION}\",
Expand All @@ -100,17 +100,12 @@ PAYLOAD="{
\"prerelease\": false
}"

HTTP_CODE=$(curl \
curl \
-vvv \
-w "%{http_code}" \
-u "${GITHUB_OWNER}:${GITHUB_API_KEY}" \
-s -o /dev/null \
-H "Accept: ${MEDIA_TYPE}" \
-X POST \
-d "${PAYLOAD}" \
${GITHUB_API_URL}/repos/${GITHUB_OWNER}/${REPO}/releases)
${GITHUB_API_URL}/repos/${GITHUB_OWNER}/${REPO}/releases

if [ "${HTTP_CODE}" != "201" ] ; then
echo "GITHUB RELEASE CREATION ERROR, HTTP_CODE=${HTTP_CODE}"
else
echo "GITHUB RELEASE CREATED."
fi

0 comments on commit 40d76b2

Please sign in to comment.