maj projet

This commit is contained in:
Jephté Clain 2025-02-25 15:51:46 +04:00
parent 1b6afc3584
commit 13d1704cb2
13 changed files with 273 additions and 285 deletions

View File

@ -1,6 +1,8 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
# branche upload ## configuration par défaut
# branche upstream
UPSTREAM= UPSTREAM=
# branches de développement # branches de développement
DEVELOP=develop DEVELOP=develop

225
bash/src/pman.sh Normal file
View File

@ -0,0 +1,225 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
# configuration par défaut
# doit être identique au contenu de pman.conf
# les branches sont mergées dans cet ordre:
# upstream --> develop --> [release -->] main --> dist
# feature _/ hotfix _/
UPSTREAM=
DEVELOP=develop
FEATURE=wip/
RELEASE=release-
MAIN=master
TAG_PREFIX=
TAG_SUFFIX=
HOTFIX=hotfix-
DIST=
NOAUTO=
CONFIG_VARS=(
UPSTREAM DEVELOP FEATURE RELEASE MAIN TAG_PREFIX TAG_SUFFIX HOTFIX DIST NOAUTO
)
function _init_changelog() {
setx date=date +%d/%m/%Y-%H:%M
ac_set_tmpfile changelog
echo >"$changelog" "\
Vérifiez et complétez la liste des changements le cas échéant.
Un fichier vide annule l'opération
Ces lignes ne seront pas incluses dans le fichier destination
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"
}
function _filter_rel() {
# enlever les commits "techniques" générés par ce script
grep -v "Intégration de la branche $RELEASE" |
grep -v "Branche $DEVELOP en version .*-SNAPSHOT"
}
function _filter_changes() {
# enlever les commits "inutiles" pour générer le fichier CHANGES.md
grep -vE '^([+|] )?[0-9a-f]+ modifs\.mineures sans commentaires$' |
grep -vE '^([+|] )?[0-9a-f]+ (cosmetic|typo|bug|fix|maj projet|maj deps)\$'
}
function _format_md() {
awk '
$0 == "" || $0 ~ /^#/ { print; next }
$1 == "+" {
$1 = "*"
$2 = "`" $2 "`"
print; next
}
$1 == "|" {
$1 = " *"
$2 = "`" $2 "`"
print; next
}
{
$1 = "* `" $1 "`"
print; next
}
'
}
function _list_commits() {
local source="${1:-$SrcBranch}" dest="${2:-$DestBranch}" mergebase
setx mergebase=git merge-base "$dest" "$source"
git log --oneline --graph "$mergebase..$source" |
grep -vF '|\' | grep -vF '|/' | sed 's/\* //; s/^ /+ /' |
_filter_rel
}
function _script_echo() {
echo >>"$script"
echo "$comment$(qvals echo "$@")" >>"$script"
}
function _script_add() {
[ $# -gt 0 ] && _script_echo "$*"
cat >>"$script"
}
function _push_branches() {
local origin branch
_rscript_echo "* push branches"
for branch in "${push_branches[@]}"; do
origin="$Origin"
[ -n "$origin" ] || setx origin=git_get_branch_remote "$branch"
[ -n "$origin" ] || origin=origin
setx rbranch=git_get_branch_rbranch "$branch" "$origin"
if [ -n "$rbranch" ]; then
rbranch="${rbranch#refs/remotes/$origin/}"
_rscript_add <<EOF
$comment$(qvals git push "$origin" "$branch:$rbranch")$or_die
EOF
else
_rscript_add <<EOF
$comment$(qvals git push --set-upstream "$origin" "$branch")$or_die
EOF
fi
done
}
function _push_tags() {
local origin tag
_rscript_echo "* push tags"
for tag in "${push_tags[@]}"; do
origin="$Origin"
[ -n "$origin" ] || origin=origin
_rscript_add <<EOF
$comment$(qvals git push --force "$origin" tag "$tag")$or_die
EOF
done
}
################################################################################
# Merge
function _mscript_start() {
>"$script"
_script_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"
}
################################################################################
# Release
function _rscript_start() {
>"$script"
_script_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"
}
function _create_release_branch() {
local date changelog
_init_changelog
echo >>"$changelog" "\
## Release $Version du $date
"
_list_commits | _filter_changes | _format_md >>"$changelog"
"${EDITOR:-nano}" +7 "$changelog"
[ -s "$changelog" ] || exit_with ewarn "Création de la release annulée"
# créer la branche de release et basculer dessus
_script_add "* create branch $ReleaseBranch" <<EOF
$(qvals git checkout -b "$ReleaseBranch" "$SrcBranch")$or_die
EOF
# créer le changelog
_script_add "* update CHANGES.md" <<EOF
[ -s CHANGES.md ] && echo >>CHANGES.md
$(qvals echo "$(awk <"$changelog" '
BEGIN { p = 0 }
p == 0 && $0 == "" { p = 1; next }
p == 1 { gsub(/\$/, "\\$", $0); print }
')") >>CHANGES.md
git add CHANGES.md
EOF
# mettre à jour la version
_script_add "* update VERSION.txt" <<EOF
$(qvals echo "$Version") >VERSION.txt
git add VERSION.txt
EOF
# Enregistrer les changements
_script_add "* commit" <<EOF
$(qvals git commit -m "Init changelog & version $Version")
EOF
}
function _merge_release_branch() {
local dest="$1" tag="$2"
# basculer sur la branche
_script_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
$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
$comment$(qvals git tag --force "$tag")$or_die
EOF
array_addu push_tags "$tag"
fi
}
function _delete_release_branch() {
_script_add "* delete branch $ReleaseBranch" <<EOF
$comment$(qvals git branch -D "$ReleaseBranch")$or_die
EOF
}

15
bash/src/pman74.conf.sh Normal file
View File

@ -0,0 +1,15 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
## configuration de la branche 7.4 d'un projet PHP multiversion
# il s'agit d'un projet avec deux branches parallèles: 7.4 et 8.2, les
# modifications de la 7.4 étant incluses dans la branche 8.2
UPSTREAM=
DEVELOP=dev74
FEATURE=wip74/
RELEASE=rel74-
MAIN=dist74
TAG_SUFFIX=p74
HOTFIX=hotf74-
DIST=
NOAUTO=

15
bash/src/pman82.conf.sh Normal file
View File

@ -0,0 +1,15 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
## configuration de la branche 8.2 d'un projet PHP multiversion
# il s'agit d'un projet avec deux branches parallèles: 7.4 et 8.2, les
# modifications de la 7.4 étant incluses dans la branche 8.2
UPSTREAM=dev74
DEVELOP=dev82
FEATURE=wip82/
RELEASE=rel82-
MAIN=dist82
TAG_SUFFIX=p82
HOTFIX=hotf82-
DIST=
NOAUTO=

View File

@ -1,29 +1,5 @@
#!/bin/bash #!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
source "$(dirname -- "$0")/../load.sh" || exit 1 source "$(dirname -- "$0")/../load.sh" || exit 1
require: git
eval "$(source "$MYDIR/_rel74.conf"; echo_setv Source="$DEVELOP")" exec "$MYDIR/prel" -bdev82 dev74 "$@"
eval "$(source "$MYDIR/_rel82.conf"; echo_setv Dest="$DEVELOP")"
Remote=
args=(
"fusionner la branche $Source dans $Dest"
-d:,--chdir:BASEDIR chdir= "répertoire dans lequel se placer avant de lancer les opérations"
-o:,--remote Remote= "++spécifier le remote vers lequel pousser les branches"
)
parse_args "$@"; set -- "${args[@]}"
if [ -n "$chdir" ]; then
cd "$chdir" || die
fi
git_check_gitvcs || die "\
$(ppath "$(pwd)" ~): ce répertoire n'est pas un dépôt git"
git_check_cleancheckout || die "\
Impossible de fusionner car il y a des modifications locales.
Enregistrer les modifications et réessayez"
setx branch=git_get_branch
estep "Merge $Source --> $Dest"

View File

@ -1 +0,0 @@
_rel

View File

@ -1 +0,0 @@
_rel

View File

View File

@ -1,11 +0,0 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
UPSTREAM=
DEVELOP=dev74
FEATURE=wip74/
RELEASE=rel74-
MAIN=dist74
TAG_SUFFIX=p74
HOTFIX=hotf74-
DIST=
NOAUTO=

View File

@ -1,11 +0,0 @@
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
UPSTREAM=
DEVELOP=dev82
FEATURE=wip82/
RELEASE=rel82-
MAIN=dist82
TAG_SUFFIX=p82
HOTFIX=hotf82-
DIST=
NOAUTO=

View File

View File

@ -1,24 +1,12 @@
#!/bin/bash #!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
source "$(dirname -- "$0")/../load.sh" || exit 1 source "$(dirname -- "$0")/../load.sh" || exit 1
require: git require: git pman pman.conf
git_cleancheckout_DIRTY="\ git_cleancheckout_DIRTY="\
Vous avez des modifications locales. Vous avez des modifications locales.
Enregistrez ces modifications avant de créer une release" Enregistrez ces modifications avant de créer une release"
# configuration par défaut
UPSTREAM=
DEVELOP=develop
FEATURE=wip/
RELEASE=release-
MAIN=master
TAG_PREFIX=
TAG_SUFFIX=
HOTFIX=hotfix-
DIST=
NOAUTO=
function load_branches() { function load_branches() {
setx CurrentBranch=git_get_branch setx CurrentBranch=git_get_branch
setx -a LocalBranches=git_list_branches setx -a LocalBranches=git_list_branches
@ -41,8 +29,7 @@ function load_config() {
ConfigFile=.pman.conf ConfigFile=.pman.conf
source "$ConfigFile" source "$ConfigFile"
else else
ConfigFile="$MYDIR/pman${MYNAME#_rel}.conf" require pman${MYNAME#prel}.conf
source "$ConfigFile"
fi fi
SrcBranch="$1" SrcBranch="$1"
@ -90,51 +77,11 @@ function init_action() {
# Informations # Informations
################################################################################ ################################################################################
function _filter_rel() {
# enlever les commits "techniques" générés par ce script
grep -v "Intégration de la branche $RELEASE" |
grep -v "Branche $DEVELOP en version .*-SNAPSHOT"
}
function _filter_changes() {
# enlever les commits "inutiles" pour générer le fichier CHANGES.md
grep -vE '^([+|] )?[0-9a-f]+ modifs\.mineures sans commentaires$' |
grep -vE '^([+|] )?[0-9a-f]+ (cosmetic|typo|bug|fix|maj projet|maj deps)\$'
}
function _format_md() {
awk '
$0 == "" || $0 ~ /^#/ { print; next }
$1 == "+" {
$1 = "*"
$2 = "`" $2 "`"
print; next
}
$1 == "|" {
$1 = " *"
$2 = "`" $2 "`"
print; next
}
{
$1 = "* `" $1 "`"
print; next
}
'
}
function _list_commits() {
local source="${1:-$SrcBranch}" dest="${2:-$DestBranch}" mergebase
setx mergebase=git merge-base "$dest" "$source"
git log --oneline --graph "$mergebase..$source" |
grep -vF '|\' | grep -vF '|/' | sed 's/\* //; s/^ /+ /' |
_filter_rel
}
DUMP_VARS=( DUMP_VARS=(
ConfigBranch ConfigBranch
ConfigFile ConfigFile
--Configuration --Configuration
UPSTREAM DEVELOP FEATURE RELEASE MAIN TAG_PREFIX TAG_SUFFIX HOTFIX DIST NOAUTO "${CONFIG_VARS[@]}"
--Paramètres --Paramètres
CurrentBranch CurrentBranch
SrcType SrcBranch SrcType SrcBranch
@ -164,33 +111,6 @@ function show_action() {
# Fusion de branche # Fusion de branche
################################################################################ ################################################################################
function _mscript_echo() {
echo >>"$script"
echo "$comment$(qvals echo "$@")" >>"$script"
}
function _mscript_add() {
[ $# -gt 0 ] && _mscript_echo "$*"
cat >>"$script"
}
function _mscript_start() {
>"$script"
_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() { function merge_action() {
local script=".git/rel-merge.sh" local script=".git/rel-merge.sh"
local -a push_branches local -a push_branches
@ -205,24 +125,24 @@ Ce script va
local comment= local comment=
local or_die=" || exit 1" local or_die=" || exit 1"
_rscript_start _mscript_start
_rscript_add <<EOF _script_add <<EOF
################################################################################ ################################################################################
# merge # merge
if [ -n "\$merge" ]; then if [ -n "\$merge" ]; then
EOF EOF
_merge_any_branch "$DestBranch" _merge_any_branch "$DestBranch"
_rscript_add <<EOF _script_add <<EOF
fi fi
EOF EOF
_rscript_add <<EOF _script_add <<EOF
################################################################################ ################################################################################
# push # push
if [ -n "\$push" ]; then if [ -n "\$push" ]; then
EOF EOF
_push_branches _push_branches
_rscript_add <<EOF _script_add <<EOF
fi fi
EOF EOF
@ -253,147 +173,6 @@ function release_dist_action() {
# Création et gestion des releases # 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"
}
function _init_changelog() {
setx date=date +%d/%m/%Y-%H:%M
ac_set_tmpfile changelog
echo >"$changelog" "\
Vérifiez et complétez la liste des changements le cas échéant.
Un fichier vide annule la création de la release
Ces lignes ne seront pas incluses dans le fichier destination
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"
}
function _create_release_branch() {
local date changelog
_init_changelog
echo >>"$changelog" "\
## Release $Version du $date
"
_list_commits | _filter_changes | _format_md >>"$changelog"
"${EDITOR:-nano}" +7 "$changelog"
[ -s "$changelog" ] || exit_with ewarn "Création de la release annulée"
# créer la branche de release et basculer dessus
_rscript_add "* create branch $ReleaseBranch" <<EOF
$(qvals git checkout -b "$ReleaseBranch" "$SrcBranch")$or_die
EOF
# créer le changelog
_rscript_add "* update CHANGES.md" <<EOF
[ -s CHANGES.md ] && echo >>CHANGES.md
$(qvals echo "$(awk <"$changelog" '
BEGIN { p = 0 }
p == 0 && $0 == "" { p = 1; next }
p == 1 { gsub(/\$/, "\\$", $0); print }
')") >>CHANGES.md
git add CHANGES.md
EOF
# mettre à jour la version
_rscript_add "* update VERSION.txt" <<EOF
$(qvals echo "$Version") >VERSION.txt
git add VERSION.txt
EOF
# Enregistrer les changements
_rscript_add "* commit" <<EOF
$(qvals git commit -m "Init changelog & version $Version")
EOF
}
function _merge_release_branch() {
local dest="$1" tag="$2"
# basculer sur la branche
_rscript_add "* switch to branch $dest" <<EOF
$comment$(qvals git checkout "$dest")$or_die
EOF
# fusionner la branche de release
_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
_rscript_add "* create tag $tag" <<EOF
$comment$(qvals git tag --force "$tag")$or_die
EOF
array_addu push_tags "$tag"
fi
}
function _delete_release_branch() {
_rscript_add "* delete branch $ReleaseBranch" <<EOF
$comment$(qvals git branch -D "$ReleaseBranch")$or_die
EOF
}
function _push_branches() {
local origin branch
_rscript_echo "* push branches"
for branch in "${push_branches[@]}"; do
origin="$Origin"
[ -n "$origin" ] || setx origin=git_get_branch_remote "$branch"
[ -n "$origin" ] || origin=origin
setx rbranch=git_get_branch_rbranch "$branch" "$origin"
if [ -n "$rbranch" ]; then
rbranch="${rbranch#refs/remotes/$origin/}"
_rscript_add <<EOF
$comment$(qvals git push "$origin" "$branch:$rbranch")$or_die
EOF
else
_rscript_add <<EOF
$comment$(qvals git push --set-upstream "$origin" "$branch")$or_die
EOF
fi
done
}
function _push_tags() {
local origin tag
_rscript_echo "* push tags"
for tag in "${push_tags[@]}"; do
origin="$Origin"
[ -n "$origin" ] || origin=origin
_rscript_add <<EOF
$comment$(qvals git push --force "$origin" tag "$tag")$or_die
EOF
done
}
function release_develop_action() { function release_develop_action() {
local script=".git/rel-release.sh" local script=".git/rel-release.sh"
local -a push_branches push_tags local -a push_branches push_tags
@ -428,17 +207,17 @@ Vous devrez:
local comment= local comment=
local or_die=" || exit 1" local or_die=" || exit 1"
_rscript_start _rscript_start
_rscript_add <<EOF _script_add <<EOF
################################################################################ ################################################################################
# create # create
if [ -n "\$create" ]; then if [ -n "\$create" ]; then
EOF EOF
_create_release_branch _create_release_branch
_rscript_add <<EOF _script_add <<EOF
fi fi
EOF EOF
_rscript_add <<EOF _script_add <<EOF
################################################################################ ################################################################################
# merge # merge
if [ -n "\$merge" ]; then if [ -n "\$merge" ]; then
@ -446,18 +225,18 @@ EOF
_merge_release_branch "$DestBranch" "$TAG_PREFIX$Version$TAG_SUFFIX" _merge_release_branch "$DestBranch" "$TAG_PREFIX$Version$TAG_SUFFIX"
_merge_release_branch "$SrcBranch" _merge_release_branch "$SrcBranch"
_delete_release_branch _delete_release_branch
_rscript_add <<EOF _script_add <<EOF
fi fi
EOF EOF
_rscript_add <<EOF _script_add <<EOF
################################################################################ ################################################################################
# push # push
if [ -n "\$push" ]; then if [ -n "\$push" ]; then
EOF EOF
_push_branches _push_branches
_push_tags _push_tags
_rscript_add <<EOF _script_add <<EOF
fi fi
EOF EOF

View File