64 lines
2.2 KiB
Bash
64 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
# Usage: ./tag.sh [TAG_NAME]
|
|
# Par défaut, TAG_NAME="dev-test"
|
|
|
|
TAG_NAME="${1:-dev-test}"
|
|
|
|
ROOT_DIR="/home/desk/code/4NK_dev"
|
|
cd "$ROOT_DIR"
|
|
|
|
echo "[tag] repository racine: $(basename "$ROOT_DIR") -> ${TAG_NAME}"
|
|
DEV_HEAD=$(git rev-parse --verify refs/heads/dev)
|
|
if git show-ref --tags --quiet --verify "refs/tags/${TAG_NAME}"; then
|
|
git tag -d "${TAG_NAME}" >/dev/null
|
|
git push origin ":refs/tags/${TAG_NAME}" >/dev/null || true
|
|
fi
|
|
git tag -a "${TAG_NAME}" -m "CI ${TAG_NAME} trigger" "${DEV_HEAD}"
|
|
git push origin "refs/tags/${TAG_NAME}"
|
|
|
|
echo "[tag] lecture des submodules depuis .gitmodules"
|
|
mapfile -t SUBS < <(git config -f .gitmodules --name-only --get-regexp 'submodule\..*\.path' | sed -E 's/\.path$//')
|
|
|
|
for NAME in "${SUBS[@]}"; do
|
|
PATHsm=$(git config -f .gitmodules --get "${NAME}.path" || true)
|
|
URLsm=$(git config -f .gitmodules --get "${NAME}.url" || true)
|
|
BRANCHsm=$(git config -f .gitmodules --get "${NAME}.branch" || echo dev)
|
|
|
|
if [ -z "$PATHsm" ] || [ -z "$URLsm" ]; then
|
|
echo "[tag][warn] entrée incomplète: ${NAME}, ignorée"
|
|
continue
|
|
fi
|
|
|
|
if [ ! -d "$PATHsm" ]; then
|
|
echo "[tag][warn] dossier manquant: $PATHsm, on saute"
|
|
continue
|
|
fi
|
|
|
|
echo "[tag] ${PATHsm} (${URLsm}) -> ${TAG_NAME} sur branche ${BRANCHsm}"
|
|
(
|
|
cd "$PATHsm"
|
|
git fetch --all --prune || true
|
|
# Tente checkout de la branche cible si disponible
|
|
if git rev-parse --verify "origin/${BRANCHsm}" >/dev/null 2>&1; then
|
|
git checkout "${BRANCHsm}" || git checkout -b "${BRANCHsm}" "origin/${BRANCHsm}" || true
|
|
git pull --ff-only || true
|
|
else
|
|
echo "[tag][info] branche ${BRANCHsm} introuvable, utilisation de la branche courante"
|
|
fi
|
|
|
|
# Supprime le tag local/distant si déjà présent
|
|
if git show-ref --tags --quiet --verify "refs/tags/${TAG_NAME}"; then
|
|
git tag -d "${TAG_NAME}" >/dev/null || true
|
|
git push origin ":refs/tags/${TAG_NAME}" >/dev/null || true
|
|
fi
|
|
|
|
HEAD_SHA=$(git rev-parse --verify HEAD)
|
|
git tag -a "${TAG_NAME}" -m "CI ${TAG_NAME} trigger" "${HEAD_SHA}"
|
|
git push origin "refs/tags/${TAG_NAME}"
|
|
) || echo "[tag][warn] échec sur ${PATHsm}, on continue"
|
|
done
|
|
|
|
echo "[tag] terminé: ${TAG_NAME} posé sur le repo racine et submodules accessibles" |