From 16a93f02be8a0676f5fc6b003cd52489f4de7f86 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 23 Nov 2026 22:52:02 -0500 Subject: [PATCH] CI: a rerun of a main run no longer fails on its own deploy tag A rerun keeps its run number, so "Tag deployed commit" tried to create deploy-- again, got a conflict, and failed the Deploy job after a successful deploy, which also skipped Deploy worker. The step now accepts an existing tag when it marks the same commit, and fails with the details when it marks another. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/ci.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 2617237..18beb7c 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -319,11 +319,20 @@ jobs: REPO: ${{ github.repository }} run: | TAG="deploy-$(date -u +%Y.%m.%d)-${RUN_NUMBER}" - curl -sf -X POST \ + API="https://code.lotusguild.org/api/v1/repos/${REPO}/tags" + code=$(curl -s -o /tmp/tag.json -w '%{http_code}' -X POST \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"${TAG}\",\"target\":\"${GIT_SHA}\",\"message\":\"Deployed to production\"}" \ - "https://code.lotusguild.org/api/v1/repos/${REPO}/tags" + "$API") + if [ "$code" = 201 ]; then echo "Tagged ${GIT_SHA} as ${TAG}"; exit 0; fi + # A rerun keeps its run number, so the tag can already exist: fine if it is + # this commit's, an error if it names another. + existing=$(curl -sf -H "Authorization: token $GITHUB_TOKEN" "$API/${TAG}" \ + | node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{try{console.log(JSON.parse(d).commit.sha)}catch(e){}})') + if [ "$existing" = "$GIT_SHA" ]; then echo "${TAG} already marks ${GIT_SHA} (a rerun)"; exit 0; fi + echo "Could not tag ${GIT_SHA} as ${TAG} (HTTP ${code}; existing: ${existing:-none})" + cat /tmp/tag.json; exit 1 deploy-worker: name: Deploy worker -- 2.47.3