Compare commits
No commits in common. "c3c54ba5d5ea3a95b6730540bd21d7edcf7d3c86" and "5186ffb7c83e4538925d340f0315a07415161415" have entirely different histories.
c3c54ba5d5
...
5186ffb7c8
1 changed files with 40 additions and 42 deletions
|
|
@ -15,16 +15,10 @@
|
||||||
# the secret table). Bumping to Forgejo v16 should fix it; until then,
|
# the secret table). Bumping to Forgejo v16 should fix it; until then,
|
||||||
# the runner-provided token keeps the workflow operational.
|
# the runner-provided token keeps the workflow operational.
|
||||||
#
|
#
|
||||||
# Why bash + jq + curl, no third-party actions: the runner's docker
|
# Why bash + curl, no third-party actions: the runner's docker label
|
||||||
# label points at pazof/yavsc-build-env, a Debian image with jq but
|
# points at pazof/yavsc-build-env, a Debian image without Node.js. Any
|
||||||
# without Node.js or python3. Any action like actions/checkout,
|
# action like actions/checkout, rasterstate/forgejo-release-action, etc.
|
||||||
# rasterstate/forgejo-release-action, etc. fails with "executable
|
# fails with "executable file not found in $PATH". Same constraint as
|
||||||
# file not found in $PATH". jq is shipped in the image from
|
|
||||||
# debian12-dotnet10-android36-v2 onward; earlier tags fell back to
|
|
||||||
# hand-rolled JSON building via sed, which was fragile (cf. PR #30:
|
|
||||||
# sed greedy + head -3 still matched author.id instead of the
|
|
||||||
# release id on the minified JSON this instance returns, PATCH
|
|
||||||
# /releases/1 → 404). Same constraint as
|
|
||||||
# .forgejo/workflows/buildAndTest.yml.
|
# .forgejo/workflows/buildAndTest.yml.
|
||||||
#
|
#
|
||||||
# This workflow complements .github/workflows/docker-publish-android.yml
|
# This workflow complements .github/workflows/docker-publish-android.yml
|
||||||
|
|
@ -228,22 +222,31 @@ jobs:
|
||||||
API_BASE="${GITHUB_API_URL%/}"
|
API_BASE="${GITHUB_API_URL%/}"
|
||||||
API_BASE="${API_BASE%/api/v1}"
|
API_BASE="${API_BASE%/api/v1}"
|
||||||
|
|
||||||
# Construction des bodies JSON et extraction de champs via
|
# Pas de python3, pas de jq dans l'image runner. On génère
|
||||||
# jq. L'image runner pazof/yavsc-build-env installe jq
|
# le JSON à la main : escaping minimal des caractères
|
||||||
# (>= 1.7) depuis debian12-dotnet10-android36-v2. La
|
# spéciaux JSON dans les chaînes (\\, \", \n, \r, \t).
|
||||||
# chaîne de construction --arg/--argjson garantit un
|
# Suffisant pour un CHANGELOG.md bien formé.
|
||||||
# escaping correct (backslashes, guillemets, newlines,
|
json_escape() {
|
||||||
# caractères de contrôle Unicode) sans avoir à le
|
local s="$1"
|
||||||
# reproduire à la main.
|
s="${s//\\/\\\\}"
|
||||||
#
|
s="${s//\"/\\\"}"
|
||||||
# json_escape et json_field à base de sed ont vécu : le
|
s="${s//$'\n'/\\n}"
|
||||||
# sed greedy matche la dernière occurrence d'un champ
|
s="${s//$'\r'/\\r}"
|
||||||
# dans la ligne, et l'API renvoie sur cette instance un
|
s="${s//$'\t'/\\t}"
|
||||||
# JSON minifié d'une seule ligne où l'id de l'auteur
|
printf '%s' "$s"
|
||||||
# (1, premier user du repo) suit l'id de la release
|
}
|
||||||
# (10706). PATCH /releases/<sed-captured-id> tombait
|
|
||||||
# alors en 404 "The target couldn't be found". jq
|
# Extraction d'un champ JSON scalaire de premier niveau depuis un
|
||||||
# résout les deux problèmes en une fois.
|
# fichier. On ne lit que les premières lignes pour éviter de
|
||||||
|
# matcher un champ homonyme dans un objet imbriqué (par ex.
|
||||||
|
# le champ "id" de l'auteur d'une release Forgejo, qui vaut
|
||||||
|
# typiquement 1 pour le premier user du repo). Sans cette
|
||||||
|
# restriction, le PATCH sur /releases/<id extrait> tombe en
|
||||||
|
# 404 "The target couldn't be found".
|
||||||
|
json_field() {
|
||||||
|
local file="$1" field="$2"
|
||||||
|
head -3 "$file" | sed -n "s/.*\"$field\"[[:space:]]*:[[:space:]]*\"\?\([0-9][0-9]*\)\"\?.*/\1/p" | head -1
|
||||||
|
}
|
||||||
|
|
||||||
# 1. Vérifier si la release existe déjà pour ce tag.
|
# 1. Vérifier si la release existe déjà pour ce tag.
|
||||||
echo "::group::Check existing release for tag $TAG"
|
echo "::group::Check existing release for tag $TAG"
|
||||||
|
|
@ -254,7 +257,7 @@ jobs:
|
||||||
echo "GET releases/tags/$TAG -> HTTP $HTTP"
|
echo "GET releases/tags/$TAG -> HTTP $HTTP"
|
||||||
EXISTING_ID=""
|
EXISTING_ID=""
|
||||||
if [[ "$HTTP" == "200" ]]; then
|
if [[ "$HTTP" == "200" ]]; then
|
||||||
EXISTING_ID=$(jq -r '.id // empty' /tmp/existing.json)
|
EXISTING_ID=$(json_field /tmp/existing.json id)
|
||||||
echo "Existing release id: ${EXISTING_ID:-none}"
|
echo "Existing release id: ${EXISTING_ID:-none}"
|
||||||
fi
|
fi
|
||||||
echo "::endgroup::"
|
echo "::endgroup::"
|
||||||
|
|
@ -262,35 +265,30 @@ jobs:
|
||||||
# 2. Créer ou mettre à jour la release.
|
# 2. Créer ou mettre à jour la release.
|
||||||
if [[ -n "$EXISTING_ID" ]]; then
|
if [[ -n "$EXISTING_ID" ]]; then
|
||||||
echo "::group::Update release id=$EXISTING_ID"
|
echo "::group::Update release id=$EXISTING_ID"
|
||||||
jq -n \
|
BODY=$(printf '{"body":"%s","prerelease":%s}' \
|
||||||
--arg body "$RELEASE_BODY" \
|
"$(json_escape "$RELEASE_BODY")" "$IS_PRERELEASE")
|
||||||
--argjson prerelease "$IS_PRERELEASE" \
|
|
||||||
'{body: $body, prerelease: $prerelease}' \
|
|
||||||
> /tmp/patch.json
|
|
||||||
HTTP=$(curl -sS -o /tmp/release.json -w '%{http_code}' \
|
HTTP=$(curl -sS -o /tmp/release.json -w '%{http_code}' \
|
||||||
-X PATCH \
|
-X PATCH \
|
||||||
-H "Authorization: token $GITHUB_TOKEN" \
|
-H "Authorization: token $GITHUB_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
--data-binary @/tmp/patch.json \
|
--data-binary "$BODY" \
|
||||||
"$API_BASE/api/v1/repos/$GITHUB_REPOSITORY/releases/$EXISTING_ID")
|
"$API_BASE/api/v1/repos/$GITHUB_REPOSITORY/releases/$EXISTING_ID")
|
||||||
echo "PATCH release -> HTTP $HTTP"
|
echo "PATCH release -> HTTP $HTTP"
|
||||||
echo "::endgroup::"
|
echo "::endgroup::"
|
||||||
else
|
else
|
||||||
echo "::group::Create release"
|
echo "::group::Create release"
|
||||||
jq -n \
|
BODY=$(printf '{"tag_name":"%s","name":"%s","body":"%s","prerelease":%s}' \
|
||||||
--arg tag "$TAG" \
|
"$(json_escape "$TAG")" \
|
||||||
--arg name "$TAG" \
|
"$(json_escape "$TAG")" \
|
||||||
--arg body "$RELEASE_BODY" \
|
"$(json_escape "$RELEASE_BODY")" \
|
||||||
--argjson prerelease "$IS_PRERELEASE" \
|
"$IS_PRERELEASE")
|
||||||
'{tag_name: $tag, name: $name, body: $body, prerelease: $prerelease}' \
|
|
||||||
> /tmp/post.json
|
|
||||||
HTTP=$(curl -sS -o /tmp/release.json -w '%{http_code}' \
|
HTTP=$(curl -sS -o /tmp/release.json -w '%{http_code}' \
|
||||||
-X POST \
|
-X POST \
|
||||||
-H "Authorization: token $GITHUB_TOKEN" \
|
-H "Authorization: token $GITHUB_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
--data-binary @/tmp/post.json \
|
--data-binary "$BODY" \
|
||||||
"$API_BASE/api/v1/repos/$GITHUB_REPOSITORY/releases")
|
"$API_BASE/api/v1/repos/$GITHUB_REPOSITORY/releases")
|
||||||
echo "POST release -> HTTP $HTTP"
|
echo "POST release -> HTTP $HTTP"
|
||||||
echo "::endgroup::"
|
echo "::endgroup::"
|
||||||
|
|
@ -302,7 +300,7 @@ jobs:
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RELEASE_ID=$(jq -r '.id' /tmp/release.json)
|
RELEASE_ID=$(json_field /tmp/release.json id)
|
||||||
echo "Release id=$RELEASE_ID"
|
echo "Release id=$RELEASE_ID"
|
||||||
|
|
||||||
# 3. Upload l'APK en asset.
|
# 3. Upload l'APK en asset.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue