CI: a rerun of a main run no longer fails on its own deploy tag #89

Merged
jared merged 1 commits from deploy-tag-idempotent into main 2026-11-23 22:57:53 -05:00
Showing only changes of commit 16a93f02be - Show all commits
+11 -2
View File
@@ -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