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: f05192ada8 ('release.sh: release to freedesktop.org, not to GNOME')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2148
This commit is contained in:
Beniamino Galvani
2025-02-27 16:08:16 +01:00
parent ea0be49451
commit 481afec6ea

View File

@@ -559,9 +559,11 @@ if [[ $GITLAB_TOKEN == "" ]]; then
fi fi
# This step is not necessary for authentication, we use it only to provide a meaningful error message. # 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" \ GITLAB_USER_ID=$(curl --request GET --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
"https://gitlab.freedesktop.org/api/v4/personal_access_tokens/self" &>/dev/null \ "https://gitlab.freedesktop.org/api/v4/personal_access_tokens/self" 2>/dev/null | jq ".user_id" || true)
|| die "failed to authenticate at gitlab.freedesktop.org with the private token" 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" 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 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" die "failed creating the release at gitlab.freedesktop.org. This was the last step, create it manually from the web UI"
fi fi