modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2025-02-25 12:20:16 +04:00
parent 7c5fb1829a
commit 1b6afc3584

338
wip/_rel
View File

@ -13,20 +13,38 @@ DEVELOP=develop
FEATURE=wip/
RELEASE=release-
MAIN=master
TAG_PREFIX=
TAG_SUFFIX=
HOTFIX=hotfix-
DIST=
NOAUTO=
function load_branches() {
setx CurrentBranch=git_get_branch
setx -a LocalBranches=git_list_branches
setx -a RemoteBranches=git_list_rbranches "$Origin"
setx -a AllBranches=git_list_pbranches "$Origin"
}
function load_config() {
[ -z "$Config" -a -f .pman.conf ] && Config=.pman.conf
if [ -n "$Config" ]; then
source "$Config"
if [ -n "$ConfigFile" ]; then
source "$ConfigFile" || die
elif [ -n "$ConfigBranch" ]; then
if ! array_contains LocalBranches "$ConfigBranch"; then
die "$ConfigBranch: branche de configuration introuvable"
else
local config="$(git show "$ConfigBranch:.pman.conf" 2>/dev/null)"
[ -n "$config" ] || die "$ConfigBranch: aucune configuration trouvée sur cette branche"
eval "$config"
fi
elif [ -f .pman.conf ]; then
ConfigFile=.pman.conf
source "$ConfigFile"
else
source "$MYDIR/pman${MYNAME#_rel}.conf"
ConfigFile="$MYDIR/pman${MYNAME#_rel}.conf"
source "$ConfigFile"
fi
setx CurrentBranch=git_get_branch
SrcBranch="$1"
[ -n "$SrcBranch" ] || SrcBranch="$CurrentBranch"
case "$SrcBranch" in
@ -45,23 +63,33 @@ function ensure_branches() {
[ -n "$SrcBranch" -a -n "$DestBranch" ] ||
die "$SrcBranch: Aucune configuration de fusion trouvée pour cette branche"
setx -a Branches=git_list_pbranches "$Origin"
array_contains Branches "$SrcBranch" || die "$SrcBranch: branche source introuvable"
array_contains Branches "$DestBranch" || die "$DestBranch: branche destination introuvable"
array_contains AllBranches "$SrcBranch" || die "$SrcBranch: branche source introuvable"
array_contains AllBranches "$DestBranch" || die "$DestBranch: branche destination introuvable"
local branch
ReleaseBranch=
for branch in "${Branches[@]}"; do
HotfixBranch=
for branch in "${AllBranches[@]}"; do
if [[ "$branch" == "$RELEASE"* ]]; then
ReleaseBranch="$branch"
elif [[ "$branch" == "$HOTFIX"* ]]; then
HotfixBranch="$branch"
fi
done
}
################################################################################
# Initialisation
################################################################################
function init_action() {
:
}
################################################################################
# Informations
################################################################################
function _filter_rel() {
# enlever les commits "techniques" générés par ce script
grep -v "Intégration de la branche $RELEASE" |
@ -102,6 +130,27 @@ function _list_commits() {
_filter_rel
}
DUMP_VARS=(
ConfigBranch
ConfigFile
--Configuration
UPSTREAM DEVELOP FEATURE RELEASE MAIN TAG_PREFIX TAG_SUFFIX HOTFIX DIST NOAUTO
--Paramètres
CurrentBranch
SrcType SrcBranch
DestBranch
)
function dump_action() {
for var in "${DUMP_VARS[@]}"; do
if [ "${var#--}" != "$var" ]; then
estep "${var#--}"
else
echo_setv "$var=${!var}"
fi
done
}
function show_action() {
local commits
setx commits=_list_commits
@ -111,24 +160,124 @@ function show_action() {
fi
}
function merge_action() {
die "action non implémentée"
}
################################################################################
# Fusion de branche
################################################################################
function _script_echo() {
function _mscript_echo() {
echo >>"$script"
echo "$comment$(qvals echo "$@")" >>"$script"
}
function _script_add() {
[ $# -gt 0 ] && _script_echo "$*"
function _mscript_add() {
[ $# -gt 0 ] && _mscript_echo "$*"
cat >>"$script"
}
function _script_start() {
function _mscript_start() {
>"$script"
_script_add <<EOF
_mscript_add <<EOF
#!/bin/bash
merge=
push=
for arg in "\$@"; do
case "\$arg" in
merge) merge=1;;
push) push=1;;
esac
done
EOF
chmod +x "$script"
}
function merge_action() {
local script=".git/rel-merge.sh"
local -a push_branches
[ -n "$Merge" ] || exit_with edebug "La fusion est désactivée. Ce script va s'arrêter"
enote "\
Ce script va
- fusionner la branche ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE} dans ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}${Push:+
- pousser les branches modifiées}"
ask_yesno "Voulez-vous continuer?" O || die
local comment=
local or_die=" || exit 1"
_rscript_start
_rscript_add <<EOF
################################################################################
# merge
if [ -n "\$merge" ]; then
EOF
_merge_any_branch "$DestBranch"
_rscript_add <<EOF
fi
EOF
_rscript_add <<EOF
################################################################################
# push
if [ -n "\$push" ]; then
EOF
_push_branches
_rscript_add <<EOF
fi
EOF
if ! "$script" ${Merge:+merge} ${Push:+push}; then
eimportant "Veuillez consulter le script $script pour le détail des opérations qui n'ont pas pu êtres effectuées"
elif [ -z "$_KeepScript" ]; then
rm "$script"
fi
}
function release_upstream_action() {
merge_action "$@"
}
function release_feature_action() {
merge_action "$@"
}
function release_main_action() {
merge_action "$@"
}
function release_dist_action() {
merge_action "$@"
}
################################################################################
# Création et gestion des releases
################################################################################
function _rscript_echo() {
echo >>"$script"
echo "$comment$(qvals echo "$@")" >>"$script"
}
function _rscript_add() {
[ $# -gt 0 ] && _rscript_echo "$*"
cat >>"$script"
}
function _rscript_start() {
>"$script"
_rscript_add <<EOF
#!/bin/bash
create=
merge=
push=
for arg in "\$@"; do
case "\$arg" in
create) create=1;;
merge) merge=1;;
push) push=1;;
esac
done
EOF
chmod +x "$script"
}
@ -144,39 +293,6 @@ Ces lignes ne seront pas incluses dans le fichier destination
"
}
function release_action() {
local script=".git/rel-release.sh"
local release="${RELEASE}$Version"
local date changelog
local -a push_branches push_tags
case "$SrcType" in
hotfix)
enote "\
Vous allez intégrer la branche de hotfix ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE}
dans la branche destination ${COULEUR_VERTE}$DestBranch${COULEUR_NORMALE}"
ask_yesno "Voulez-vous continuer?" O || die
_init_changelog
echo "## Hotfix $Version du $date" >>"$changelog"
;;
release)
enote "\
Vous allez intégrer la branche de release ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE}
dans la branche destination ${COULEUR_VERTE}$DestBranch${COULEUR_NORMALE}"
ask_yesno "Voulez-vous continuer?" O || die
;;
esac
}
function release_upstream_action() {
merge_action "$@"
}
function release_feature_action() {
merge_action "$@"
}
function _create_release_branch() {
local date changelog
@ -188,15 +304,13 @@ function _create_release_branch() {
"${EDITOR:-nano}" +7 "$changelog"
[ -s "$changelog" ] || exit_with ewarn "Création de la release annulée"
_script_start
# créer la branche de release et basculer dessus
_script_add "* create branch $ReleaseBranch" <<EOF
_rscript_add "* create branch $ReleaseBranch" <<EOF
$(qvals git checkout -b "$ReleaseBranch" "$SrcBranch")$or_die
EOF
# créer le changelog
_script_add "* update CHANGES.md" <<EOF
_rscript_add "* update CHANGES.md" <<EOF
[ -s CHANGES.md ] && echo >>CHANGES.md
$(qvals echo "$(awk <"$changelog" '
BEGIN { p = 0 }
@ -207,42 +321,34 @@ git add CHANGES.md
EOF
# mettre à jour la version
_script_add "* update VERSION.txt" <<EOF
_rscript_add "* update VERSION.txt" <<EOF
$(qvals echo "$Version") >VERSION.txt
git add VERSION.txt
EOF
# Enregistrer les changements
_script_add "* commit" <<EOF
_rscript_add "* commit" <<EOF
$(qvals git commit -m "Init changelog & version $Version")
EOF
}
function _set_active() {
if [ -n "$1" ]; then
comment=; or_die=" || exit 1"
else
comment="#"; or_die=
fi
}
function _merge_release_branch() {
local dest="$1" tag="$2"
# basculer sur la branche
_script_add "* switch to branch $dest" <<EOF
_rscript_add "* switch to branch $dest" <<EOF
$comment$(qvals git checkout "$dest")$or_die
EOF
# fusionner la branche de release
_script_add "* merge branch $ReleaseBranch" <<EOF
_rscript_add "* merge branch $ReleaseBranch" <<EOF
$comment$(qvals git merge "$ReleaseBranch" -m "Intégration de la branche $ReleaseBranch" --no-ff)$or_die
EOF
array_addu push_branches "$dest"
# tagger la release
if [ -n "$tag" ]; then
_script_add "* create tag $tag" <<EOF
_rscript_add "* create tag $tag" <<EOF
$comment$(qvals git tag --force "$tag")$or_die
EOF
array_addu push_tags "$tag"
@ -250,14 +356,14 @@ EOF
}
function _delete_release_branch() {
_script_add "* delete branch $ReleaseBranch" <<EOF
_rscript_add "* delete branch $ReleaseBranch" <<EOF
$comment$(qvals git branch -D "$ReleaseBranch")$or_die
EOF
}
function _push_branches() {
local origin branch
_script_echo "* push branches"
_rscript_echo "* push branches"
for branch in "${push_branches[@]}"; do
origin="$Origin"
[ -n "$origin" ] || setx origin=git_get_branch_remote "$branch"
@ -265,11 +371,11 @@ function _push_branches() {
setx rbranch=git_get_branch_rbranch "$branch" "$origin"
if [ -n "$rbranch" ]; then
rbranch="${rbranch#refs/remotes/$origin/}"
_script_add <<EOF
_rscript_add <<EOF
$comment$(qvals git push "$origin" "$branch:$rbranch")$or_die
EOF
else
_script_add <<EOF
_rscript_add <<EOF
$comment$(qvals git push --set-upstream "$origin" "$branch")$or_die
EOF
fi
@ -278,12 +384,12 @@ EOF
function _push_tags() {
local origin tag
_script_echo "* push tags"
_rscript_echo "* push tags"
for tag in "${push_tags[@]}"; do
origin="$Origin"
[ -n "$origin" ] || origin=origin
_script_add <<EOF
$comment$(qvals git push "$origin" tag "$tag")$or_die
_rscript_add <<EOF
$comment$(qvals git push --force "$origin" tag "$tag")$or_die
EOF
done
}
@ -293,9 +399,14 @@ function release_develop_action() {
local -a push_branches push_tags
if [ -n "$ReleaseBranch" ]; then
Version="${ReleaseBranch#$RELEASE}"
release_release_action "$@"; return $?
elif [ -n "$HotfixBranch" ]; then
Version="${HotfixBranch#$HOTFIX}"
release_hotfix_action "$@"; return $?
fi
[ -n "$Version" ] || die "Vous devez spécifier la version de la release"
ReleaseBranch="${RELEASE}$Version"
if [ -n "$Merge" ]; then
enote "\
@ -314,20 +425,45 @@ Vous devrez:
fi
ask_yesno "Voulez-vous continuer?" O || die
local comment or_die
_set_active 1
local comment=
local or_die=" || exit 1"
_rscript_start
_rscript_add <<EOF
################################################################################
# create
if [ -n "\$create" ]; then
EOF
_create_release_branch
_set_active "$Merge"
_merge_release_branch "$DestBranch" "$Version"
_rscript_add <<EOF
fi
EOF
_rscript_add <<EOF
################################################################################
# merge
if [ -n "\$merge" ]; then
EOF
_merge_release_branch "$DestBranch" "$TAG_PREFIX$Version$TAG_SUFFIX"
_merge_release_branch "$SrcBranch"
_delete_release_branch
_set_active "$Push"
_rscript_add <<EOF
fi
EOF
_rscript_add <<EOF
################################################################################
# push
if [ -n "\$push" ]; then
EOF
_push_branches
_push_tags
_rscript_add <<EOF
fi
EOF
if ! "$script"; then
if ! "$script" create ${Merge:+merge} ${Push:+push}; then
eimportant "Veuillez consulter le script $script pour le détail des opérations qui n'ont pas pu êtres effectuées"
else
elif [ -z "$_KeepScript" ]; then
rm "$script"
fi
}
@ -341,36 +477,42 @@ Vous allez:
}
function release_hotfix_action() {
release_action "$@"
enote "\
Vous allez intégrer la branche de hotfix ${COULEUR_JAUNE}$HotfixBranch${COULEUR_NORMALE}
dans la branche destination ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}"
ask_yesno "Voulez-vous continuer?" O || die
}
function release_main_action() {
merge_action "$@"
}
function release_dist_action() {
merge_action "$@"
}
################################################################################
# Programme principal
################################################################################
chdir=
Config=
Origin=
ConfigBranch=
ConfigFile=
Action=release
Merge=1
Push=1
Version=
_KeepScript=
args=(
"faire une nouvelle release à partir de la branche source"
" -gv VERSION [source]"
-d:,--chdir:BASEDIR chdir= "répertoire dans lequel se placer avant de lancer les opérations"
-c:,--config:CONFIG Config= "++\
fichier de configuration des branches.
par défaut, utiliser le fichier .pman.conf dans le répertoire du dépôt s'il existe"
-o:,--origin Origin= "++\
origine à partir de laquelle les branches distantes sont considérées"
-b:,--config-branch ConfigBranch= "++\
branche à partir de laquelle charger la configuration"
-c:,--config-file:CONFIG ConfigFile= "++\
fichier de configuration des branches. cette option est prioritaire sur --config-branch
par défaut, utiliser le fichier .pman.conf dans le répertoire du dépôt s'il existe"
--keep-script _KeepScript=1 "++option non documentée"
--init Action=init "++\
initialiser les branches $DEVELOP et $MAIN
le nom des branches peut différer si un fichier de configuration est fourni"
--dump-config Action=dump "++\
afficher la configuration chargée"
-s,--show Action=show "\
lister les modifications qui seraient intégrées dans la release"
--release Action=release "créer la release. c'est l'action par défaut"
@ -400,6 +542,7 @@ setx gitdir=git_get_toplevel
cd "$gitdir" || die
# charger la configuration
load_branches
load_config "$1"
if [ -n "$Merge" -a -n "$NOAUTO" ]; then
ewarn "L'option --no-merge a été forcée puisque ce dépôt ne supporte pas les releases automatiques"
@ -409,9 +552,8 @@ fi
# puis faire l'action que l'on nous demande
case "$Action" in
init)
init_action "$@"
;;
init) init_action "$@";;
dump) dump_action "$@";;
show)
git_check_cleancheckout || ewarn "$git_cleancheckout_DIRTY"
ensure_branches
@ -420,10 +562,6 @@ show)
release)
git_ensure_cleancheckout
ensure_branches
[ -n "$Version" ] || die "Vous devez spécifier la version de la release"
# Ici, les variables suivantes sont disponibles: CurrentBranch, Branches,
# SrcBranch, SrcType, DestBranch, ReleaseBranch
"release_${SrcType}_action" "$@"
;;
esac