# -*- 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 _/ # branche upstream UPSTREAM= # branches de développement DEVELOP=develop FEATURE=wip/ # branche de préparation de release RELEASE=release- # branche de release MAIN=master TAG_PREFIX= TAG_SUFFIX= # branche de hotfix HOTFIX=hotfix- # branche de distribution DIST= # désactiver les releases automatiques? 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 awk ' BEGIN { tech = 0 } tech == 0 && $0 ~ /^\+.*/ { tech = 1; next } tech == 1 && $0 ~ /^\|/ { next } tech == 1 && $0 ~ /^\+/ { tech = 0 } $0 !~ // { print } ' } 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 --no-decorate "$mergebase..$source" | grep -vF '|\' | grep -vF '|/' | sed -r 's/^(\| )+\* +/| /; s/^\* +/+ /' | _filter_rel } function _scripte() { echo >>"$script" echo "$comment$(qvals "$@")" >>"$script" } function _scripta() { [ $# -gt 0 ] && _scripte einfo "$*" cat >>"$script" } function _script_push_branches() { [ ${#push_branches[*]} -gt 0 ] || return [ -n "$Origin" ] || Origin=origin git_have_remote "$Origin" || return local branch cmd remote rbranch for branch in "${push_branches[@]}"; do if [[ "$branch" == *:* ]]; then cmd="$(qvals git push "$Origin" "$branch")" else setx remote=git_get_branch_remote "$branch" if [ "$remote" == "$Origin" ]; then setx rbranch=git_get_branch_merge "$branch" if [ -n "$rbranch" ]; then # pousser vers la branche distante existante cmd="$(qvals git push "$Origin" "$branch:${rbranch#refs/heads/}")" else # pas de branche distante: pousser et traquer cmd="$(qvals git push -u "$Origin" "$branch:$branch")" fi elif [ -n "$remote" ]; then # pousser vers un remote différent cmd="$(qvals git push "$Origin" "$branch:$branch")" else # pas de remote: pousser et traquer cmd="$(qvals git push -u "$Origin" "$branch:$branch")" fi fi _scripta <<<"$comment$cmd$or_die" done } function _script_push_tags() { local origin tag _scripte einfo "push tags" for tag in "${push_tags[@]}"; do origin="$Origin" [ -n "$origin" ] || origin=origin _scripta <"$ConfigFile" 2>/dev/null [ -s "$ConfigFile" ] || die "$ConfigBranch: aucune configuration trouvée sur cette branche" || return source "$ConfigFile" fi elif [ -f .pman.conf ]; then ConfigFile="$(pwd)/.pman.conf" source "$ConfigFile" elif [ -n "$1" -a -n "${MYNAME#$1}" ]; then ConfigFile="$NULIBDIR/bash/src/pman${MYNAME#$1}.conf.sh" source "$ConfigFile" else ConfigFile="$NULIBDIR/bash/src/pman.conf.sh" fi # S'assurer que nulib est dans le PATH pour que les scripts utilisateurs # puissent utiliser les outils fournis export PATH="$NULIBDIR/bin:$PATH" } ################################################################################ # Divers function _push_branches() { [ ${#push_branches[*]} -gt 0 ] || return [ -n "$Origin" ] || Origin=origin git_have_remote "$Origin" || return local -a cmds; local branch cmd remote rbranch for branch in "${push_branches[@]}"; do if [[ "$branch" == *:* ]]; then cmds+=("$(qvals git push "$Origin" "$branch")") else setx remote=git_get_branch_remote "$branch" if [ "$remote" == "$Origin" ]; then setx rbranch=git_get_branch_merge "$branch" if [ -n "$rbranch" ]; then # pousser vers la branche distante existante cmds+=("$(qvals git push "$Origin" "$branch:${rbranch#refs/heads/}")") else # pas de branche distante: pousser et traquer cmds+=("$(qvals git push -u "$Origin" "$branch:$branch")") fi elif [ -n "$remote" ]; then # pousser vers un remote différent cmds+=("$(qvals git push "$Origin" "$branch:$branch")") else # pas de remote: pousser et traquer cmds+=("$(qvals git push -u "$Origin" "$branch:$branch")") fi fi done [ -n "$Push" ] || enote "L'option --no-push étant utilisée, les opérations à effectuer sont simplement affichées" for cmd in "${cmds[@]}"; do einfo "$cmd" if [ -n "$Push" ]; then if ! eval "$cmd"; then ewarn "Une erreur s'est produite, les opérations seront simplement affichées" Push= fi fi done } ################################################################################ # Merge function _mscript_start() { >"$script" _scripta <"$script" _scripta <>"$changelog" "\ ## Release $Tag du $date " _list_commits | _filter_changes | _format_md >>"$changelog" if [ -s CHANGES.md ]; then echo >>"$changelog" cat CHANGES.md >>"$changelog" fi "${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 _scripta "create branch $ReleaseBranch" <CHANGES.md git add CHANGES.md EOF # mettre à jour la version _scripta "update VERSION.txt" <VERSION.txt git add VERSION.txt EOF # Enregistrer les changements _scripta "commit" <Init changelog & version $Tag") EOF } function _rscript_merge_release_branch() { local dest="$1" tag="$2" # basculer sur la branche _scripta "switch to branch $dest" <Intégration de la branche $ReleaseBranch" --no-ff)$or_die EOF array_addu push_branches "$dest" # tagger la release if [ -n "$tag" ]; then _scripta "create tag $tag" <