Fail-fast and log HTTP response on PR/issue creation

Previous curl calls ignored exit codes — PR/issue creation was silently
failing (branch got pushed but no PR/issue landed) while the step reported
green. Now each curl captures the response body and HTTP status, prints
both for debugging, and exits non-zero if status != 201.

Also dropped the labels field from the issue payload — Gitea rejects
issue creation when referenced labels don't exist in the repo, which
may have contributed to the silent failure. Labels can be added
manually post-creation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-24 17:45:12 -03:00
parent d9b1bb52a4
commit 2491c38d4b

View File

@@ -100,20 +100,28 @@ jobs:
| sed "s#https://#https://sku-refresh-bot:${GITEA_TOKEN}@#") | sed "s#https://#https://sku-refresh-bot:${GITEA_TOKEN}@#")
git push "$REMOTE" "$BRANCH" git push "$REMOTE" "$BRANCH"
# Open PR via Gitea API # Open PR via Gitea API (fail-fast + log response)
OWNER=$(echo "$GITEA_REPO" | cut -d/ -f1) OWNER=$(echo "$GITEA_REPO" | cut -d/ -f1)
REPO=$(echo "$GITEA_REPO" | cut -d/ -f2) REPO=$(echo "$GITEA_REPO" | cut -d/ -f2)
curl -sS -X POST \ PAYLOAD=$(jq -n \
--arg title "chore(pricing): monthly SKU refresh ${DATE}" \
--arg head "$BRANCH" \
--arg base "main" \
--arg body "$(printf 'Automated refresh — see run artifact for full refresh/discover logs.\n\n```\n%s\n```' \
"$(tail -40 /tmp/refresh.log)")" \
'{title:$title, head:$head, base:$base, body:$body}')
echo "Creating PR ${BRANCH} -> main ..."
RESPONSE=$(curl -sS -w "\nHTTP_STATUS=%{http_code}\n" -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \ -H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
"${GITEA_SERVER}/api/v1/repos/${OWNER}/${REPO}/pulls" \ "${GITEA_SERVER}/api/v1/repos/${OWNER}/${REPO}/pulls" \
-d "$(jq -n \ -d "$PAYLOAD")
--arg title "chore(pricing): monthly SKU refresh ${DATE}" \ echo "$RESPONSE"
--arg head "$BRANCH" \ STATUS=$(echo "$RESPONSE" | grep -oE 'HTTP_STATUS=[0-9]+' | cut -d= -f2)
--arg base "main" \ if [ "$STATUS" != "201" ]; then
--arg body "$(printf 'Automated refresh — [refresh log artifact](../../actions).\n\n```\n%s\n```' \ echo "::error::PR creation failed with HTTP $STATUS"
"$(tail -40 /tmp/refresh.log)")" \ exit 1
'{title:$title, head:$head, base:$base, body:$body}')" fi
- name: Open issue for new SKUs - name: Open issue for new SKUs
if: steps.discover.outputs.new_count != '0' if: steps.discover.outputs.new_count != '0'
@@ -130,14 +138,22 @@ jobs:
BODY=$(printf '## %s new SKUs detected in Oracle API\n\n**Detected:** %s\n\nThese SKUs are present in the Oracle public pricing API but not yet in `kb/pricing/oci-sku-catalog.yaml`. Filter: serviceCategory values already represented in our catalog (so only relevant families show up).\n\n### Full listing\n\n```\n%s\n```\n\n### Next step\n\nReview and add relevant entries to `kb/pricing/oci-sku-catalog.yaml` under the appropriate category block. After merging, prices will be picked up automatically on the next monthly refresh.\n' \ BODY=$(printf '## %s new SKUs detected in Oracle API\n\n**Detected:** %s\n\nThese SKUs are present in the Oracle public pricing API but not yet in `kb/pricing/oci-sku-catalog.yaml`. Filter: serviceCategory values already represented in our catalog (so only relevant families show up).\n\n### Full listing\n\n```\n%s\n```\n\n### Next step\n\nReview and add relevant entries to `kb/pricing/oci-sku-catalog.yaml` under the appropriate category block. After merging, prices will be picked up automatically on the next monthly refresh.\n' \
"$NEW_COUNT" "$DATE" "$(cat /tmp/discover.log)") "$NEW_COUNT" "$DATE" "$(cat /tmp/discover.log)")
curl -sS -X POST \ PAYLOAD=$(jq -n \
--arg title "SKU catalog: ${NEW_COUNT} new SKUs to review (${DATE})" \
--arg body "$BODY" \
'{title:$title, body:$body}')
echo "Creating issue: ${NEW_COUNT} new SKUs..."
RESPONSE=$(curl -sS -w "\nHTTP_STATUS=%{http_code}\n" -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \ -H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
"${GITEA_SERVER}/api/v1/repos/${OWNER}/${REPO}/issues" \ "${GITEA_SERVER}/api/v1/repos/${OWNER}/${REPO}/issues" \
-d "$(jq -n \ -d "$PAYLOAD")
--arg title "SKU catalog: ${NEW_COUNT} new SKUs to review (${DATE})" \ echo "$RESPONSE"
--arg body "$BODY" \ STATUS=$(echo "$RESPONSE" | grep -oE 'HTTP_STATUS=[0-9]+' | cut -d= -f2)
'{title:$title, body:$body, labels:["automation","sku-catalog"]}')" if [ "$STATUS" != "201" ]; then
echo "::error::Issue creation failed with HTTP $STATUS"
exit 1
fi
- name: Summary - name: Summary
if: always() if: always()