diff --git a/.github/workflows/release-guard.yml b/.github/workflows/release-guard.yml index 65ef5d5..f225958 100644 --- a/.github/workflows/release-guard.yml +++ b/.github/workflows/release-guard.yml @@ -10,8 +10,9 @@ name: Release guard # # IT DRAFTS RATHER THAN DELETES. Deleting is what was done by hand and it worked, but as an # automatism the blast radius is wrong: one false positive destroys a legitimate release and its tag. -# Drafting removes it from the public list and from Packagist, is reversible with one click, and -# leaves the trace of why. A gate you can undo is the only kind you dare install everywhere. +# Drafting removes it from the public list of releases, is reversible with one click, and leaves +# the trace of why. It does not take the version off Packagist, which reads tags, not releases. +# A gate you can undo is the only kind you dare install everywhere. on: release: @@ -34,8 +35,9 @@ jobs: REPO: ${{ github.repository }} run: | set -uo pipefail - # Actions runs this step under `bash -e`. Every call that can fail sits inside a condition, so a - # failed read is handled here instead of ending the step before anyone is told. + # Actions runs this step under `bash -e`. Every read and the draft sit inside a condition, so a + # failed call is handled here instead of ending the step before anyone is told. Only the last + # call, opening the issue, can end the step; the step is red either way. # NO PODER VER NO ES ESTAR VERDE. A commit with no check runs at all is drafted too: a # release published from a tree nobody ever tested is exactly the case this exists for. @@ -85,6 +87,12 @@ jobs: break fi + # Red is red. Once no relevant check is pending and one of them did not pass, the verdict is + # already a draft; waiting for other runs would only keep a red release public longer. + if [ "$seen" = yes ] && [ "$pending" -eq 0 ] && [ "$not_green" -gt 0 ]; then + break + fi + if [ "$waits" -ge "$max_waits" ]; then if [ "$seen" = yes ]; then echo "::warning::Timed out after $((max_waits * wait_seconds)) seconds: $pending relevant check(s) and $running workflow run(s) still going" @@ -117,15 +125,37 @@ jobs: motivo="sin una lectura completa de sus checks en $((max_waits * wait_seconds)) segundos" fi echo "::error::$TAG apunta a un commit que no pasó: $motivo" - gh release edit "$TAG" --repo "$REPO" --draft + + # A failed draft must still reach a person: three tries, and the issue says if all of them failed. + drafted=no + for attempt in 1 2 3; do + if gh release edit "$TAG" --repo "$REPO" --draft; then + drafted=yes + break + fi + if [ "$attempt" -lt 3 ]; then + sleep "$wait_seconds" + fi + done + + if [ "$drafted" = yes ]; then + titulo="Release $TAG pasado a borrador: su commit no está verde" + accion="Se pasó a **borrador** en vez de borrarlo: sale de la lista pública de releases y de \`releases/latest\`, y se deshace con un clic si esto es un falso positivo." + else + echo "::error::No se pudo pasar $TAG a borrador en 3 intentos: sigue publicado" + titulo="Release $TAG sigue publicado: su commit no está verde y no se pudo pasar a borrador" + accion="**No se pudo pasar a borrador** en 3 intentos: sigue publicado. Hay que pasarlo a borrador a mano." + fi cuerpo=$(printf '%s\n' \ "\`$TAG\` apunta a \`${sha:-?}\`, $motivo." \ "" \ - "Se pasó a **borrador** en vez de borrarlo: sale de la lista pública y de Packagist, y se deshace con un clic si esto es un falso positivo." \ + "$accion" \ + "" \ + "El tag sigue existiendo y Packagist lee tags, no releases: la versión se sigue pudiendo instalar. Si no debe instalarse, hay que borrar el tag." \ "" \ "Publicar no pasa por la protección de rama — greenhouse evidence/0171.") gh issue create --repo "$REPO" \ - --title "Release $TAG pasado a borrador: su commit no está verde" \ + --title "$titulo" \ --body "$cuerpo" exit 1