From c4b4b66692effe7ced03e1f24ae6a745fcf5eec4 Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Sat, 5 Oct 2024 11:08:26 +0200 Subject: [PATCH] fix: make curl fail fast on HTTP error --- Release.gitlab-ci.yml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Release.gitlab-ci.yml b/Release.gitlab-ci.yml index 840515b..3a20e9c 100644 --- a/Release.gitlab-ci.yml +++ b/Release.gitlab-ci.yml @@ -70,13 +70,19 @@ handle_mr: --arg content "${CONTENT}" \ --arg startBranch "${CI_DEFAULT_BRANCH}" \ "${BODY_TMPL}")" - curl -s -X PUT \ + # Check if CHANGELOG.md exists + if curl -sf --head \ -H "Authorization: Bearer ${UNBOUND_RELEASE_TOKEN}" \ - -H "Content-Type: application/json" \ - --data "${BODY}" \ - "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/repository/files/CHANGELOG%2Emd" - if [ $? -ne 0 ]; then - curl -s -X POST \ + "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/repository/files/CHANGELOG%2Emd?ref=next-release"; then + # Exists => update + curl -sf -X PUT \ + -H "Authorization: Bearer ${UNBOUND_RELEASE_TOKEN}" \ + -H "Content-Type: application/json" \ + --data "${BODY}" \ + "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/repository/files/CHANGELOG%2Emd" + else + # Not exists => create + curl -sf -X POST \ -H "Authorization: Bearer ${UNBOUND_RELEASE_TOKEN}" \ -H "Content-Type: application/json" \ --data "${BODY}" \ @@ -85,7 +91,7 @@ handle_mr: if [ -n "${MR}" ]; then echo "Updating existing MR" echo "Rebasing branch" - curl -s -X PUT \ + curl -sf -X PUT \ -H "Authorization: Bearer ${UNBOUND_RELEASE_TOKEN}" \ -H "Content-Type: application/json" \ "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/merge_requests/${MR}/rebase" @@ -95,7 +101,7 @@ handle_mr: --arg title "${TITLE}" \ --arg target "${CI_DEFAULT_BRANCH}" \ "${BODY_TMPL}") - curl -s -X PUT \ + curl -sf -X PUT \ -H "Authorization: Bearer ${UNBOUND_RELEASE_TOKEN}" \ -H "Content-Type: application/json" \ --data "${BODY}" \ @@ -107,7 +113,7 @@ handle_mr: --arg title "${TITLE}" \ --arg target "${CI_DEFAULT_BRANCH}" \ "${BODY_TMPL}") - curl -s -X POST \ + curl -sf -X POST \ -H "Authorization: Bearer ${UNBOUND_RELEASE_TOKEN}" \ -H "Content-Type: application/json" \ --data "${BODY}" \ @@ -162,7 +168,7 @@ release: --arg message "${MESSAGE}" \ --arg ref "${CI_DEFAULT_BRANCH}" \ "${BODY_TMPL}")" - curl -s -X POST \ + curl -sf -X POST \ -H "Authorization: Bearer ${UNBOUND_RELEASE_TOKEN}" \ -H "Content-Type: application/json" \ --data "${BODY}" \