From 481afec6ea2b136fa8eb73a4d5e6e045570351fc Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 27 Feb 2025 16:08:16 +0100 Subject: [PATCH] release: fix validation of gitlab token If the token is wrong or expired, the command still returns success. Check the content of the reply instead. Fixes: f05192ada84b ('release.sh: release to freedesktop.org, not to GNOME') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2148 --- contrib/fedora/rpm/release.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/fedora/rpm/release.sh b/contrib/fedora/rpm/release.sh index 5a7e0c16de..ff18cc5b00 100755 --- a/contrib/fedora/rpm/release.sh +++ b/contrib/fedora/rpm/release.sh @@ -559,9 +559,11 @@ if [[ $GITLAB_TOKEN == "" ]]; then fi # This step is not necessary for authentication, we use it only to provide a meaningful error message. -curl --request GET --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ - "https://gitlab.freedesktop.org/api/v4/personal_access_tokens/self" &>/dev/null \ - || die "failed to authenticate at gitlab.freedesktop.org with the private token" +GITLAB_USER_ID=$(curl --request GET --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ + "https://gitlab.freedesktop.org/api/v4/personal_access_tokens/self" 2>/dev/null | jq ".user_id" || true) +if [ -z "$GITLAB_USER_ID" ] || [ "$GITLAB_USER_ID" = "null" ]; then + die "failed to authenticate to gitlab.freedesktop.org with the private token" +fi do_command git push "$ORIGIN" "${BRANCHES[@]}" || die "failed to to push branches ${BRANCHES[@]} to $ORIGIN" @@ -640,4 +642,4 @@ fi if [[ $CREATE_RELEASE_FAIL == 1 ]]; then die "failed creating the release at gitlab.freedesktop.org. This was the last step, create it manually from the web UI" -fi \ No newline at end of file +fi