fix(ci): release Gitea idempotente (réutilise le tag existant, remplace l'APK)
Release / release-apk (push) Successful in 8m27s
Release / release-docker (push) Successful in 3m33s
CI / docker (push) Successful in 7s
CI / lint-backend (push) Successful in 1m41s
CI / lint-mobile (push) Successful in 19m44s
CI / test-backend (push) Successful in 1m50s
CI / test-mobile (push) Successful in 8m27s
CI / build-backend (push) Successful in 45s
Release / release-apk (push) Successful in 8m27s
Release / release-docker (push) Successful in 3m33s
CI / docker (push) Successful in 7s
CI / lint-backend (push) Successful in 1m41s
CI / lint-mobile (push) Successful in 19m44s
CI / test-backend (push) Successful in 1m50s
CI / test-mobile (push) Successful in 8m27s
CI / build-backend (push) Successful in 45s
This commit is contained in:
@@ -86,20 +86,35 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
VERSION="$(cat VERSION)"
|
VERSION="$(cat VERSION)"
|
||||||
|
TAG="v${VERSION}"
|
||||||
API="https://${API_HOST}/api/v1"
|
API="https://${API_HOST}/api/v1"
|
||||||
AUTH="Authorization: token ${RELEASE_API_TOKEN:?RELEASE_API_TOKEN manquant (PAT scope write:repository)}"
|
AUTH="Authorization: token ${RELEASE_API_TOKEN:?RELEASE_API_TOKEN manquant (PAT scope write:repository)}"
|
||||||
NOTES_JSON="$(python3 -c 'import json;print(json.dumps(open("CHANGELOG.md", encoding="utf-8").read()))')"
|
NOTES_JSON="$(python3 -c 'import json;print(json.dumps(open("CHANGELOG.md", encoding="utf-8").read()))')"
|
||||||
PAYLOAD_JSON="$(TAG="v${VERSION}" BODY="$NOTES_JSON" python3 -c 'import json,os;print(json.dumps({"tag_name":os.environ["TAG"],"name":"Kazier "+os.environ["TAG"],"body":json.loads(os.environ["BODY"])}))')"
|
# Idempotent : si la release du tag existe déjà (re-tag, retry du job),
|
||||||
|
# la réutiliser au lieu d'échouer en 409.
|
||||||
|
if RELEASE_JSON="$(curl -sSf -H "${AUTH}" "${API}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" 2>/dev/null)"; then
|
||||||
|
echo "Release ${TAG} existante — réutilisation."
|
||||||
|
else
|
||||||
|
PAYLOAD_JSON="$(TAG="${TAG}" BODY="$NOTES_JSON" python3 -c 'import json,os;print(json.dumps({"tag_name":os.environ["TAG"],"name":"Kazier "+os.environ["TAG"],"body":json.loads(os.environ["BODY"])}))')"
|
||||||
RELEASE_JSON="$(curl -sSf -X POST "${API}/repos/${GITHUB_REPOSITORY}/releases" \
|
RELEASE_JSON="$(curl -sSf -X POST "${API}/repos/${GITHUB_REPOSITORY}/releases" \
|
||||||
-H "${AUTH}" \
|
-H "${AUTH}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "${PAYLOAD_JSON}")"
|
-d "${PAYLOAD_JSON}")"
|
||||||
|
fi
|
||||||
RELEASE_ID="$(printf '%s' "${RELEASE_JSON}" | python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')"
|
RELEASE_ID="$(printf '%s' "${RELEASE_JSON}" | python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')"
|
||||||
: "${RELEASE_ID:?id de release introuvable dans la réponse API}"
|
: "${RELEASE_ID:?id de release introuvable dans la réponse API}"
|
||||||
|
# Asset idempotent : remplace l'APK existant de même nom s'il y en a un.
|
||||||
|
APK_PATH="mobile-kotlin/app/build/outputs/apk/release/app-release.apk"
|
||||||
|
EXISTING_ASSET_ID="$(curl -sSf -H "${AUTH}" "${API}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets" \
|
||||||
|
| python3 -c 'import json,sys;assets=json.load(sys.stdin);print(next((str(a["id"]) for a in assets if a.get("name")=="app-release.apk"),""))')"
|
||||||
|
if [ -n "${EXISTING_ASSET_ID}" ]; then
|
||||||
|
echo "Asset existant ${EXISTING_ASSET_ID} — suppression avant re-upload."
|
||||||
|
curl -sSf -X DELETE -H "${AUTH}" "${API}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets/${EXISTING_ASSET_ID}" > /dev/null
|
||||||
|
fi
|
||||||
curl -sSf -X POST \
|
curl -sSf -X POST \
|
||||||
"${API}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=app-release.apk" \
|
"${API}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=app-release.apk" \
|
||||||
-H "${AUTH}" \
|
-H "${AUTH}" \
|
||||||
-F "attachment=@mobile-kotlin/app/build/outputs/apk/release/app-release.apk"
|
-F "attachment=@${APK_PATH}"
|
||||||
|
|
||||||
release-docker:
|
release-docker:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
|
|||||||
Reference in New Issue
Block a user