From a2a40279769ecc97210d81cb51597f62309cb664 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 8 Feb 2020 10:51:12 +0100 Subject: [PATCH] [ci] Fix github-releases-api script to preserve the tag_name Obviously, when updating the release to add the release notes, the tag_name gets lost, resulting in github creating a "untagged_xyz" tag and not connecting the release to the correct tag, although the commit matches. --- .travis.yml | 3 ++- .travis/github-releases-api.sh | 40 +++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1c8fa50d5c..bcfbfccb5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - secure: "B2quYqla3mqu3QHqeRGMde66IFAluUHhzY87q/giPvONm/V7xmIcxzC6JNQ7X4pHotC7MUbsMf7vdcL1tyuPP5nqyfaxk0nnGnVoJZIQhMaBQ6Lkyt2Ac5u5/QBeHujrj8gqGjT7vzgPIYMYiSLV09VcPgMaYS6WxCrFmXOEJOeVGOGjG9J2wApAmlf6m/hBogLEbdbzRheqJwX5gMxppKX5XRaiqvKGR7hHFiW5HBaAiQ6caQEw6DZL9GnjMsqd5VMVL7DmbETncNE1utLVDO7mFwDMbkeonmwjsmQsJAo5Be+WFl/a/yRQLrqhhTFwag+V7g7RjcBKAdJ5IZJkN0EC9GjY0ZGOjE2cmcrX03U1g1voO7oreH6+25VqPTTGWHv5K8wDWM5QnhBJGtH2yH76p5XYK8iNOXPTqvjubN9sG3INsnTjxBHuQw+aY2vgwBGCvW+Asqe73BV8SDrmqcCqgmm/BUy0kZRd8mhaQdFL0SAO3suV7uf+fzIsmRtndFx24J5Cm6LE6NnTmtbhHhs4mUEqfngMq0XZBXj5z4LDhzOH4g3rf/Y7jHBjAAa6sKeh1sINdHrMdB843dDfNQPp/7g3hfKi31U9ZMczndsr2QYqm2OC/3lPiRHC+8Grj5PxXmiBplzTppyhl+1pjZWy5SCoQi6ulBOyaZcwfYM=" - secure: "Kmh31kozw9NBbwtkucpf+QslinJI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AAGgTKZAVdAN0mGXbe63tWmwaBlEbK8h2A8di6abW5x6YHTkTo2BRlHUSTU8dE3VqTnpSkne5n1SlEa4g1Bci3J45M0/pLmHV6yCxCM5BrVXS5ByaB61py/umSbpmdIBFV6TM1MaKK3lAucQrR+8To/vCbm8XqPyujJdOR+ENIuuDgEU/Yh5Hv5SAODekUYaCp4pjfGzFADHQWVNDxIOXrwBN4OfSiAvRc1x6HXndOmNI4QtOxheuCRFFthq8VZI=" + - GITHUB_BASE_URL=https://api.github.com/repos/pmd/pmd jobs: fast_finish: true @@ -96,5 +97,5 @@ cache: # add the encrypted GPG keyring file to repo (https://docs.travis-ci.com/user/encrypting-files/#Automated-Encryption), decrypt it and install it at the beginning of .travis-deploy.sh # # GITHUB_OAUTH_TOKEN - the token used to upload the binaries to github releases +# GITHUB_BASE_URL - the api url to use for github releases - does not need to be secure (https://api.github.com/repos/pmd/pmd) # - diff --git a/.travis/github-releases-api.sh b/.travis/github-releases-api.sh index f523041111..c30c223f75 100644 --- a/.travis/github-releases-api.sh +++ b/.travis/github-releases-api.sh @@ -1,9 +1,10 @@ # # The functions here require the following scripts: -# .travis/logger.sh +# logger.sh # # The functions here require the following environment variables: # GITHUB_OAUTH_TOKEN +# GITHUB_BASE_URL # # @@ -30,13 +31,13 @@ function gh_releases_createDraftRelease() { EOF ) - log_debug "POST https://api.github.com/repos/pmd/pmd/releases" + log_debug "POST $GITHUB_BASE_URL/releases" log_info "Creating github draft release" RESULT=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ -H "Content-Type: application/json" \ -X POST \ --data "${request}" \ - "https://api.github.com/repos/pmd/pmd/releases") + "$GITHUB_BASE_URL/releases") log_debug " -> response: $RESULT" log_success "Created draft release with id $(echo $RESULT | jq --raw-output ".url")" @@ -53,9 +54,9 @@ function gh_releases_createDraftRelease() { # function gh_releases_getLatestDraftRelease() { log_debug "$FUNCNAME" - log_debug "GET https://api.github.com/repos/pmd/pmd/releases?per_page=1" + log_debug "GET $GITHUB_BASE_URL/releases?per_page=1" RESULT=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ - "https://api.github.com/repos/pmd/pmd/releases?per_page=1" | jq ".[0]") + "$GITHUB_BASE_URL/releases?per_page=1" | jq ".[0]") log_debug " -> response: $RESULT" local draft=$(echo $RESULT | jq ".draft") if [ "$draft" != "true" ]; then @@ -77,12 +78,12 @@ function gh_release_deleteRelease() { gh_release_getIdFromData "$release" local releaseId="$RESULT" log_debug "$FUNCNAME id=$releaseId" - log_debug "DELETE https://api.github.com/repos/pmd/pmd/releases/$releaseId" + log_debug "DELETE $GITHUB_BASE_URL/releases/$releaseId" log_info "Deleting github release $releaseId" local response response=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ -X DELETE \ - "https://api.github.com/repos/pmd/pmd/releases/$releaseId") + "$GITHUB_BASE_URL/releases/$releaseId") log_debug " -> response: $response" log_success "Deleted release with id $releaseId" } @@ -98,6 +99,17 @@ function gh_release_getIdFromData() { RESULT=$(echo $release | jq --raw-output ".id") } +# +# Determines the tag_name from the given JSON release data. +# +# RESULT = "the tag name" +# +function gh_release_getTagNameFromData() { + local release="$1" + + RESULT=$(echo $release | jq --raw-output ".tag_name") +} + # # Uploads a asset to an existing release. # @@ -141,7 +153,9 @@ function gh_release_updateRelease() { gh_release_getIdFromData "$release" local releaseId="$RESULT" - log_debug "$FUNCNAME releaseId=$releaseId name=$name" + gh_release_getTagNameFromData "$release" + local tagName="$RESULT" + log_debug "$FUNCNAME releaseId=$releaseId name=$name tag_name=$tagName" body="${body//'\'/\\\\}" body="${body//$'\r'/}" @@ -150,13 +164,14 @@ function gh_release_updateRelease() { local request=$(cat <<-EOF { + "tag_name": "${tagName}", "name": "${name}", "body": "${body}" } EOF ) - log_debug "PATCH https://api.github.com/repos/pmd/pmd/releases/${releaseId}" + log_debug "PATCH $GITHUB_BASE_URL/releases/${releaseId}" log_debug " -> request: $request" log_info "Updating github release $releaseId" local response @@ -164,7 +179,7 @@ function gh_release_updateRelease() { -H "Content-Type: application/json" \ --data "${request}" \ -X PATCH \ - "https://api.github.com/repos/pmd/pmd/releases/${releaseId}") + "$GITHUB_BASE_URL/releases/${releaseId}") log_debug " -> response: $response" log_success "Updated release with id=$releaseId" } @@ -184,7 +199,7 @@ function gh_release_publishRelease() { log_debug "$FUNCNAME releaseId=$releaseId" local request='{"draft":false}' - log_debug "PATCH https://api.github.com/repos/pmd/pmd/releases/${releaseId}" + log_debug "PATCH $GITHUB_BASE_URL/releases/${releaseId}" log_debug " -> request: $request" log_info "Publishing github release $releaseId" local response @@ -192,9 +207,8 @@ function gh_release_publishRelease() { -H "Content-Type: application/json" \ --data "${request}" \ -X PATCH \ - "https://api.github.com/repos/pmd/pmd/releases/${releaseId}") + "$GITHUB_BASE_URL/releases/${releaseId}") log_debug " -> response: $response" local htmlUrl=$(echo "$response" | jq --raw-output ".html_url") log_success "Published release with id=$releaseId at $htmlUrl" } -