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