scripts/publish.sh : publication vérifiée (commit+tag+push+ls-remote) — constat du push refspec ambigu du 22/11
This commit is contained in:
parent
2c99ca51cd
commit
ad3ecda8ae
167
scripts/publish.sh
Executable file
167
scripts/publish.sh
Executable file
@ -0,0 +1,167 @@
|
||||
#!/bin/sh
|
||||
# publish.sh — publication d'une release lost-sector-port sur gitea.
|
||||
#
|
||||
# Usage :
|
||||
# scripts/publish.sh [--message "msg"] [--tag vX.Y.Z] [--dry-run]
|
||||
#
|
||||
# Rôle : enchaîner commit → tag → push → VÉRIFICATION remote, sans laisser
|
||||
# le modèle (ou l'humain) deviner les refspecs. Constat du 22/11 : le
|
||||
# modèle avait commité correctement puis lancé `git push origin v0.17.0`
|
||||
# — le refspec résolvait vers le TAG, la branche master remote restait 1
|
||||
# commit derrière. Ce script rend l'erreur impossible :
|
||||
# - il pousse TOUJOURS la branche explicitement (master) ;
|
||||
# - il VÉRIFIE avec git ls-remote que le SHA local figure sur le remote
|
||||
# (branche ET tag) avant de déclarer succès ;
|
||||
# - il refuse tout scénario ambigu : arbre sale sans --message, retard
|
||||
# ou divergence sur origin/master, tag déjà existant, format de tag
|
||||
# invalide.
|
||||
#
|
||||
# Prérequis : master = branche de publication ; credentials HTTPS gitea
|
||||
# dans le trousseau macOS (git credential fill — cf. AGENTS.md).
|
||||
#
|
||||
# Sortie : étapes numérotées, PUBLIÉ/VÉRIFIÉ par cible, code retour 1 au
|
||||
# moindre échec (l'agent doit s'arrêter, pas improviser).
|
||||
#
|
||||
# Validation : shellcheck + shfmt (cf. skill shell-tools).
|
||||
|
||||
set -eu
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
BRANCH="master"
|
||||
MSG=""
|
||||
TAG=""
|
||||
DRY_RUN=0
|
||||
|
||||
usage() {
|
||||
echo "usage : scripts/publish.sh [--message \"msg\"] [--tag vX.Y.Z] [--dry-run]" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--message)
|
||||
[ $# -ge 2 ] || usage
|
||||
MSG="$2"
|
||||
shift 2
|
||||
;;
|
||||
--tag)
|
||||
[ $# -ge 2 ] || usage
|
||||
TAG="$2"
|
||||
shift 2
|
||||
;;
|
||||
--dry-run)
|
||||
DRY_RUN=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "== 1/5 état du dépôt =="
|
||||
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
||||
if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then
|
||||
echo "ERREUR : branche courante '$CURRENT_BRANCH' ≠ '$BRANCH' — placer sur $BRANCH d'abord." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIRTY="$(git status --porcelain)"
|
||||
if [ -n "$DIRTY" ]; then
|
||||
if [ -z "$MSG" ]; then
|
||||
echo "ERREUR : arbre sale et --message absent. Committer d'abord, ou relancer avec --message." >&2
|
||||
echo "$DIRTY" | head -5 >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "arbre sale → commit unique demandé"
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[dry-run] git add -A && git commit -m \"$MSG\""
|
||||
else
|
||||
git add -A
|
||||
git commit -m "$MSG"
|
||||
fi
|
||||
else
|
||||
echo "arbre propre"
|
||||
[ -n "$MSG" ] && echo "NOTE : --message ignoré (rien à committer)"
|
||||
fi
|
||||
|
||||
echo "== 2/5 synchronisation avec origin =="
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[dry-run] git fetch origin + comparaison master"
|
||||
else
|
||||
git fetch origin
|
||||
fi
|
||||
LOCAL_HEAD="$(git rev-parse HEAD)"
|
||||
REMOTE_HEAD="$(git rev-parse origin/"$BRANCH" 2>/dev/null || echo absent)"
|
||||
if [ "$REMOTE_HEAD" = "$LOCAL_HEAD" ]; then
|
||||
if [ -z "$TAG" ]; then
|
||||
echo "déjà à jour (origin/$BRANCH = $LOCAL_HEAD) et pas de tag demandé — rien à publier"
|
||||
exit 0
|
||||
fi
|
||||
echo "branche déjà à jour ; seul le tag reste à publier"
|
||||
elif git merge-base --is-ancestor "$LOCAL_HEAD" "$REMOTE_HEAD" 2>/dev/null; then
|
||||
echo "ERREUR : local est DERRIÈRE origin/$BRANCH — faire 'git pull --rebase' d'abord." >&2
|
||||
exit 1
|
||||
elif ! git merge-base --is-ancestor "$REMOTE_HEAD" "$LOCAL_HEAD" 2>/dev/null; then
|
||||
echo "ERREUR : divergence entre local et origin/$BRANCH — publier à la main ou réconcilier." >&2
|
||||
exit 1
|
||||
else
|
||||
echo "avance locale : $REMOTE_HEAD..$LOCAL_HEAD (fast-forward OK)"
|
||||
fi
|
||||
|
||||
echo "== 3/5 tag =="
|
||||
if [ -n "$TAG" ]; then
|
||||
case "$TAG" in
|
||||
v[0-9]*.[0-9]*.[0-9]*) ;;
|
||||
*)
|
||||
echo "ERREUR : '$TAG' ne respecte pas le format vX.Y.Z" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null 2>&1; then
|
||||
echo "ERREUR : le tag $TAG existe déjà localement — incrémenter la version." >&2
|
||||
exit 1
|
||||
fi
|
||||
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q "$TAG"; then
|
||||
echo "ERREUR : le tag $TAG existe déjà sur origin — incrémenter la version." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[dry-run] git tag -a $TAG -m \"$TAG\" + push du tag"
|
||||
else
|
||||
git tag -a "$TAG" -m "$TAG"
|
||||
echo "tag $TAG créé sur $LOCAL_HEAD"
|
||||
fi
|
||||
else
|
||||
echo "pas de tag demandé"
|
||||
fi
|
||||
|
||||
echo "== 4/5 push =="
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[dry-run] git push origin $BRANCH$([ -n "$TAG" ] && echo " + refs/tags/$TAG")"
|
||||
exit 0
|
||||
fi
|
||||
git push origin "$BRANCH"
|
||||
if [ -n "$TAG" ]; then
|
||||
git push origin "refs/tags/$TAG"
|
||||
fi
|
||||
|
||||
echo "== 5/5 vérification remote =="
|
||||
REMOTE_CHECK="$(git ls-remote origin "refs/heads/$BRANCH" | cut -f1)"
|
||||
if [ "$REMOTE_CHECK" != "$LOCAL_HEAD" ]; then
|
||||
echo "ERREUR : origin/$BRANCH = $REMOTE_CHECK ≠ local $LOCAL_HEAD — publication NON vérifiée." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "VÉRIFIÉ : origin/$BRANCH = $REMOTE_CHECK"
|
||||
if [ -n "$TAG" ]; then
|
||||
REMOTE_TAG="$(git ls-remote origin "refs/tags/$TAG" | head -n1 | cut -f1)"
|
||||
if [ -z "$REMOTE_TAG" ]; then
|
||||
echo "ERREUR : le tag $TAG n'est pas sur origin — publication du tag NON vérifiée." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "VÉRIFIÉ : origin tag $TAG présent ($REMOTE_TAG)"
|
||||
fi
|
||||
|
||||
echo "PUBLIÉ : $BRANCH ($LOCAL_HEAD)$([ -n "$TAG" ] && echo " + tag $TAG") sur origin"
|
||||
Loading…
x
Reference in New Issue
Block a user