feat(ci): tag all repos (root + submodules) with optional tag (default dev-test)
This commit is contained in:
parent
bfd833cc5b
commit
3cd729bb71
@ -1,20 +1,64 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
# Usage: ./tag.sh [TAG_NAME]
|
# Usage: ./tag.sh [TAG_NAME]
|
||||||
# Par défaut, TAG_NAME="dev-test"
|
# Par défaut, TAG_NAME="dev-test"
|
||||||
|
|
||||||
TAG_NAME="${1:-dev-test}"
|
TAG_NAME="${1:-dev-test}"
|
||||||
|
|
||||||
cd /home/desk/code/4NK_dev
|
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)
|
DEV_HEAD=$(git rev-parse --verify refs/heads/dev)
|
||||||
|
|
||||||
# Supprime le tag local/distant si déjà présent, puis recrée et pousse
|
|
||||||
if git show-ref --tags --quiet --verify "refs/tags/${TAG_NAME}"; then
|
if git show-ref --tags --quiet --verify "refs/tags/${TAG_NAME}"; then
|
||||||
git tag -d "${TAG_NAME}" >/dev/null
|
git tag -d "${TAG_NAME}" >/dev/null
|
||||||
git push origin ":refs/tags/${TAG_NAME}" >/dev/null || true
|
git push origin ":refs/tags/${TAG_NAME}" >/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git tag -a "${TAG_NAME}" -m "CI ${TAG_NAME} trigger" "${DEV_HEAD}"
|
git tag -a "${TAG_NAME}" -m "CI ${TAG_NAME} trigger" "${DEV_HEAD}"
|
||||||
git push origin "refs/tags/${TAG_NAME}"
|
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"
|
||||||
Loading…
x
Reference in New Issue
Block a user