#!/bin/bash # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 source "$(dirname -- "$0")/../load.sh" || exit 1 require: git git_cleancheckout_DIRTY="\ Vous avez des modifications locales. 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() { 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() { 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 ConfigFile="$MYDIR/pman${MYNAME#_rel}.conf" source "$ConfigFile" fi SrcBranch="$1" [ -n "$SrcBranch" ] || SrcBranch="$CurrentBranch" case "$SrcBranch" in "$UPSTREAM") SrcType=upstream; DestBranch="$DEVELOP";; "$FEATURE"*) SrcType=feature; DestBranch="$DEVELOP";; "$DEVELOP") SrcType=develop; DestBranch="$MAIN";; "$RELEASE"*) SrcType=release; DestBranch="$MAIN";; "$HOTFIX"*) SrcType=hotfix; DestBranch="$MAIN";; "$MAIN") SrcType=main; DestBranch="$DIST";; "$DIST") SrcType=dist; DestBranch=;; *) DestBranch=;; esac } function ensure_branches() { [ -n "$SrcBranch" -a -n "$DestBranch" ] || die "$SrcBranch: Aucune configuration de fusion trouvée pour cette branche" array_contains AllBranches "$SrcBranch" || die "$SrcBranch: branche source introuvable" array_contains AllBranches "$DestBranch" || die "$DestBranch: branche destination introuvable" local branch ReleaseBranch= 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" | 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=( 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 if [ -n "$commits" ]; then einfo "Commits à fusionner $SrcBranch --> $DestBranch" eecho "$commits" fi } ################################################################################ # 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 <>"$script" echo "$comment$(qvals echo "$@")" >>"$script" } function _rscript_add() { [ $# -gt 0 ] && _rscript_echo "$*" cat >>"$script" } function _rscript_start() { >"$script" _rscript_add <"$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" <>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" <VERSION.txt git add VERSION.txt EOF # Enregistrer les changements _rscript_add "* commit" <