diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 0876fcad..5ff28f97 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -45,6 +45,7 @@ body: - releasing/update-version-README.sh - releasing/update-version-scripts.sh - releasing/update-version-issue-templates.sh + - releasing/params/after-version-update-hook.default-args.source.sh - releasing/params/after-version-update-hook.params.source.sh - releasing/params/after-version-update-hook.params-definition.source.sh - releasing/params/prepare-files-next-dev-cycle.default-args.source.sh diff --git a/scripts/cleanup-on-push-to-main.sh b/scripts/cleanup-on-push-to-main.sh index 00642077..78aa926e 100755 --- a/scripts/cleanup-on-push-to-main.sh +++ b/scripts/cleanup-on-push-to-main.sh @@ -49,9 +49,9 @@ function cleanupOnPushToMain() { releasing/sneak-peek-banner releasing/toggle-sections releasing/update-version-common-steps + releasing/update-version-issue-templates releasing/update-version-README releasing/update-version-scripts - releasing/update-version-issue-templates ) for script in "${scriptsWithHelp[@]}"; do diff --git a/src/releasing/common-constants.source.sh b/src/releasing/common-constants.source.sh index 1237c3e1..5562913a 100644 --- a/src/releasing/common-constants.source.sh +++ b/src/releasing/common-constants.source.sh @@ -39,6 +39,7 @@ local -r projectsRootDirParamDocu='(optional) The projects directory -- default: local -r additionalPatternParamPatternLong='--pattern' local -r additionalPatternParamPattern="-p|$additionalPatternParamPatternLong" local -r additionalPatternParamDocu='(optional) pattern which is used in a perl command (separator /) to search & replace additional occurrences. It should define two match groups and the replace operation looks as follows: '"\\\${1}\$version\\\${2}" +local -r additionalPatternDefaultArg='' local -r nextVersionParamPatternLong='--next-version' local -r nextVersionParamPattern="-nv|$nextVersionParamPatternLong" diff --git a/src/releasing/params/after-version-update-hook.default-args.source.sh b/src/releasing/params/after-version-update-hook.default-args.source.sh new file mode 100644 index 00000000..bf552f88 --- /dev/null +++ b/src/releasing/params/after-version-update-hook.default-args.source.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2034,SC2168 +# +# __ __ +# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts +# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft +# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 +# /___/ Please report bugs and contribute back your improvements +# +# Version: v5.2.0-SNAPSHOT +####### Description ############# +# +# Defines default args for ...params-definition.source.sh for files which use the same arguments but allow optional +# parameters (the afterVersionUpdateHook as such should not) +# +################################### + +if ! [[ -v projectsRootDir ]]; then projectsRootDir=$(realpath ".") || die "could not determine realpath of ."; fi +# shellcheck disable=SC2154 # defined in common-constants which we assume is sourced when this file is sourced +if ! [[ -v additionalPattern ]]; then additionalPattern="$additionalPatternDefaultArg"; fi diff --git a/src/releasing/params/prepare-next-dev-cycle-template.default-args.source.sh b/src/releasing/params/prepare-next-dev-cycle-template.default-args.source.sh index 42e31a9b..a29070bd 100644 --- a/src/releasing/params/prepare-next-dev-cycle-template.default-args.source.sh +++ b/src/releasing/params/prepare-next-dev-cycle-template.default-args.source.sh @@ -15,8 +15,8 @@ ################################### { # shellcheck disable=SC2154 # it is assumed dir_of_tegonal_scripts is defined where this file is sourced - source "$dir_of_tegonal_scripts/releasing/params/update-version-common-steps.default-args.source.sh" || - traceAndDie "could not source update-version-common-steps.default-args.source.sh" + source "$dir_of_tegonal_scripts/releasing/params/after-version-update-hook.default-args.source.sh" || + traceAndDie "could not source after-version-update-hook.default-args.source.sh" } # Note, it is used in release-template.default-args.source.sh, if you should add default args which are only relevant diff --git a/src/releasing/params/update-version-common-steps.default-args.source.sh b/src/releasing/params/update-version-common-steps.default-args.source.sh index d1665541..a027c947 100644 --- a/src/releasing/params/update-version-common-steps.default-args.source.sh +++ b/src/releasing/params/update-version-common-steps.default-args.source.sh @@ -14,9 +14,10 @@ # parameters (the afterVersionUpdateHook as such should not) # ################################### +{ + # shellcheck disable=SC2154 # it is assumed dir_of_tegonal_scripts is defined where this file is sourced + source "$dir_of_tegonal_scripts/releasing/params/after-version-update-hook.default-args.source.sh" || + traceAndDie "could not source after-version-update-hook.default-args.source.sh" +} -# Note, it is used in prepare-next-dev-cycle-template.default-args.source.sh, if you should add default args -# which are only relevant for update-version-common-steps then don't re-use in -# prepare-next-dev-cycle-template.default-args.source.sh any more. -if ! [[ -v projectsRootDir ]]; then projectsRootDir=$(realpath ".") || die "could not determine realpath of ."; fi -if ! [[ -v additionalPattern ]]; then additionalPattern="^$"; fi +# nothing in addition for now diff --git a/src/releasing/prepare-files-next-dev-cycle-template.sh b/src/releasing/prepare-files-next-dev-cycle-template.sh index 9dfada88..47a0bd44 100755 --- a/src/releasing/prepare-files-next-dev-cycle-template.sh +++ b/src/releasing/prepare-files-next-dev-cycle-template.sh @@ -82,6 +82,9 @@ function prepareFilesNextDevCycleTemplate() { local -a prepareNextDevCycleTemplateArgs addLocalVarMatchingParamNamesToArgs prepareNextDevCycleTemplateParams prepareNextDevCycleTemplateArgs + local -a afterVersionHookArgs + addLocalVarMatchingParamNamesToArgs afterVersionHookParams afterVersionHookArgs + # those variables are used in local functions further below which will be called from releaseTemplate. # The problem: in case releaseTemplate defines a variable with the same name, then we would use those # variables instead of the one we define here, hence we prefix them to avoid this problem @@ -93,15 +96,16 @@ function prepareFilesNextDevCycleTemplate() { parseArguments afterVersionHookParams "" "$TEGONAL_SCRIPTS_VERSION" "$@" || return $? exitIfNotAllArgumentsSet afterVersionHookParams "" "$TEGONAL_SCRIPTS_VERSION" + local -a afterVersionHookArgs + addLocalVarMatchingParamNamesToArgs afterVersionHookParams afterVersionHookArgs + updateVersionScripts \ "$versionParamPatternLong" "$version-SNAPSHOT" \ "$additionalPatternParamPatternLong" "$additionalPattern" \ -d "$projectsRootDir/src" || return $? executeIfFunctionNameDefined "$prepare_files_next_dev_afterVersionUpdateHook" "$afterVersionUpdateHookParamPatternLong" \ - "$versionParamPatternLong" "$version" \ - "$projectsRootDirParamPatternLong" "$projectsRootDir" \ - "$additionalPatternParamPatternLong" "$additionalPattern" + "${afterVersionHookArgs[@]}" } prepareNextDevCycleTemplate \ diff --git a/src/releasing/prepare-next-dev-cycle-template.sh b/src/releasing/prepare-next-dev-cycle-template.sh index 58ec81df..522e8b9e 100755 --- a/src/releasing/prepare-next-dev-cycle-template.sh +++ b/src/releasing/prepare-next-dev-cycle-template.sh @@ -79,23 +79,24 @@ function prepareNextDevCycleTemplate() { exitIfNotAllArgumentsSet prepareNextDevCycleTemplateParams "" "$TEGONAL_SCRIPTS_VERSION" exitIfArgIsNotVersion "$version" "$versionParamPatternLong" exitIfArgIsNotFunction "$beforePrFn" "$beforePrFnParamPatternLong" + exitIfPathNamedIsOutsideOfCurrentDir "$projectsRootDir" "$projectsRootDirParamPatternLong" exitIfGitHasChanges + local -a afterVersionHookArgs + addLocalVarMatchingParamNamesToArgs afterVersionHookParams afterVersionHookArgs + logInfo "prepare next dev cycle for version $version" local -r devVersion="$version-SNAPSHOT" updateVersionCommonSteps \ "$forReleaseParamPatternLong" false \ - "$versionParamPatternLong" "$devVersion" \ - "$projectsRootDirParamPatternLong" "$projectsRootDir" \ - "$additionalPatternParamPatternLong" "$additionalPattern" + "${afterVersionHookArgs[@]}" \ + "$versionParamPatternLong" "$devVersion" executeIfFunctionNameDefined "$afterVersionUpdateHook" "$afterVersionUpdateHookParamPatternLong" \ - "$versionParamPatternLong" "$version" \ - "$projectsRootDirParamPatternLong" "$projectsRootDir" \ - "$additionalPatternParamPatternLong" "$additionalPattern" + "${afterVersionHookArgs[@]}" # check if we accidentally have broken something, run formatting or whatever is done in beforePr "$beforePrFn" || return $? diff --git a/src/releasing/release-files-template.sh b/src/releasing/release-files-template.sh index 50dfc9dc..ecfe96c8 100755 --- a/src/releasing/release-files-template.sh +++ b/src/releasing/release-files-template.sh @@ -115,15 +115,16 @@ function releaseFilesTemplate() { parseArguments afterVersionHookParams "" "$TEGONAL_SCRIPTS_VERSION" "$@" || return $? exitIfNotAllArgumentsSet afterVersionHookParams "" "$TEGONAL_SCRIPTS_VERSION" + local -a afterVersionHookArgs + addLocalVarMatchingParamNamesToArgs afterVersionHookParams afterVersionHookArgs + updateVersionScripts \ "$versionParamPatternLong" "$version" \ "$additionalPatternParamPatternLong" "$additionalPattern" \ -d "$projectsRootDir/src" || return $? executeIfFunctionNameDefined "$release_files_afterVersionUpdateHook" "$afterVersionUpdateHookParamPatternLong" \ - "$versionParamPatternLong" "$version" \ - "$projectsRootDirParamPatternLong" "$projectsRootDir" \ - "$additionalPatternParamPatternLong" "$additionalPattern" + "${afterVersionHookArgs[@]}" } function releaseFilesTemplate_releaseHook() { diff --git a/src/releasing/release-template.sh b/src/releasing/release-template.sh index e906ac77..3b39cea3 100755 --- a/src/releasing/release-template.sh +++ b/src/releasing/release-template.sh @@ -102,6 +102,10 @@ function releaseTemplate() { exitIfArgIsNotFunction "$releaseHook" "$releaseHookParamPatternLong" exitIfArgIsNotFunction "$beforePrFn" "$beforePrFnParamPatternLong" exitIfArgIsNotFunction "$prepareNextDevCycleFn" "$prepareNextDevCycleFnParamPatternLong" + exitIfPathNamedIsOutsideOfCurrentDir "$projectsRootDir" "$projectsRootDirParamPatternLong" + + local -a afterVersionHookArgs + addLocalVarMatchingParamNamesToArgs afterVersionHookParams afterVersionHookArgs preReleaseCheckGit \ "$versionParamPatternLong" "$version" \ @@ -112,14 +116,10 @@ function releaseTemplate() { updateVersionCommonSteps \ "$forReleaseParamPatternLong" true \ - "$versionParamPatternLong" "$version" \ - "$projectsRootDirParamPatternLong" "$projectsRootDir" \ - "$additionalPatternParamPatternLong" "$additionalPattern" + "${afterVersionHookArgs[@]}" executeIfFunctionNameDefined "$afterVersionUpdateHook" "$afterVersionUpdateHookParamPatternLong" \ - "$versionParamPatternLong" "$version" \ - "$projectsRootDirParamPatternLong" "$projectsRootDir" \ - "$additionalPatternParamPatternLong" "$additionalPattern" + "${afterVersionHookArgs[@]}" # run again since we made changes "$beforePrFn" || return $? @@ -138,12 +138,11 @@ function releaseTemplate() { fi logInfo "Release completed, going to prepare next development cycle for %s by calling %s" "$nextVersion" \ - "$prepareNextDevCycleFn $versionParamPatternLong $nextVersion $additionalPatternParamPatternLong $additionalPattern $projectsRootDirParamPatternLong $projectsRootDir $beforePrFnParamPatternLong $beforePrFn" + "${afterVersionHookArgs[*]} $versionParamPatternLong $nextVersion $beforePrFnParamPatternLong $beforePrFn" "$prepareNextDevCycleFn" \ + "${afterVersionHookArgs[@]}" \ "$versionParamPatternLong" "$nextVersion" \ - "$additionalPatternParamPatternLong" "$additionalPattern" \ - "$projectsRootDirParamPatternLong" "$projectsRootDir" \ "$beforePrFnParamPatternLong" "$beforePrFn" || die "could not prepare next dev cycle for version %s" "$nextVersion" git push origin "$version" || die "could not push tag %s to origin" "$version" diff --git a/src/releasing/update-version-README.sh b/src/releasing/update-version-README.sh index 6994a95b..9b0b42bf 100755 --- a/src/releasing/update-version-README.sh +++ b/src/releasing/update-version-README.sh @@ -67,10 +67,10 @@ function updateVersionReadme() { parseArguments params "$examples" "$TEGONAL_SCRIPTS_VERSION" "$@" || return $? if ! [[ -v file ]]; then file="./README.md"; fi - if ! [[ -v additionalPattern ]]; then additionalPattern=""; fi + if ! [[ -v additionalPattern ]]; then additionalPattern="$additionalPatternDefaultArg"; fi exitIfNotAllArgumentsSet params "$examples" "$TEGONAL_SCRIPTS_VERSION" - echo "set version $version for Download badges and sneak peek banner in $file" + logInfo "set version $version for Download badges and sneak peek banner in $file" local -r versionWithoutLeadingV="${version:1}" @@ -81,7 +81,7 @@ function updateVersionReadme() { "$file" || returnDying "was not able to update the version in download badges and in the sneak peek banner" || return $? if [[ -n $additionalPattern ]]; then - echo "also going to search for $additionalPattern and replace with \${1}$version\${2}" + logInfo "also going to search for $additionalPattern and replace with \${1}$version\${2}" perl -0777 -i \ -pe "s/$additionalPattern/\${1}$version\${2}/g;" \ "$file" || returnDying "error during the additional replacement, see above" || return $? diff --git a/src/releasing/update-version-common-steps.sh b/src/releasing/update-version-common-steps.sh index d243dc6e..2220abad 100755 --- a/src/releasing/update-version-common-steps.sh +++ b/src/releasing/update-version-common-steps.sh @@ -75,7 +75,6 @@ function updateVersionCommonSteps() { parseArguments updateVersionCommonStepsParams "" "$TEGONAL_SCRIPTS_VERSION" "$@" || return $? source "$dir_of_tegonal_scripts/releasing/params/update-version-common-steps.default-args.source.sh" || traceAndDie "could not source update-version-common-steps.default-args.source.sh" exitIfNotAllArgumentsSet updateVersionCommonStepsParams "" "$TEGONAL_SCRIPTS_VERSION" - exitIfArgIsNotBoolean "$forRelease" "$forReleaseParamPatternLong" local -r projectsScriptsDir="$projectsRootDir/scripts" @@ -108,7 +107,10 @@ function updateVersionCommonSteps() { local -r templateDir="$projectsRootDir/./.github/ISSUE_TEMPLATE" if [[ -d "$templateDir" ]]; then - updateVersionIssueTemplates "$versionParamPatternLong" "$version" -d "$templateDir" + updateVersionIssueTemplates \ + "$versionParamPatternLong" "$version" \ + "$additionalPatternParamPatternLong" "$additionalPattern" \ + -d "$templateDir" || return $? fi fi } diff --git a/src/releasing/update-version-issue-templates.sh b/src/releasing/update-version-issue-templates.sh index 768685cb..732f30e0 100755 --- a/src/releasing/update-version-issue-templates.sh +++ b/src/releasing/update-version-issue-templates.sh @@ -69,6 +69,7 @@ function updateVersionIssueTemplates() { if ! [[ -v directory ]]; then directory="./.github/ISSUE_TEMPLATE"; fi if ! [[ -v additionalPattern ]]; then additionalPattern=""; fi exitIfNotAllArgumentsSet params "$examples" "$TEGONAL_SCRIPTS_VERSION" + exitIfArgIsNotVersion "$version" "$versionParamPatternLong" local where if [[ -f $directory ]]; then @@ -81,17 +82,17 @@ function updateVersionIssueTemplates() { echo "also going to search for $additionalPattern and replace with \${1}$version\${2}" fi - local script + local yaml find "$directory" '(' -name "*.yml" -o -name "*.yaml" ')' -print0 | - while read -r -d $'\0' script; do + while read -r -d $'\0' yaml; do perl -0777 -i \ -pe "s/(label:\s*Affected Version[\S\s]+placeholder:\s*)\"[^\"]+\"/\${1}\"$version\"/g;" \ - "$script" || returnDying "was not able to update the version in the issue templates" || return $? + "$yaml" || returnDying "was not able to update the version in the issue templates" || return $? if [[ -n $additionalPattern ]]; then perl -0777 -i \ -pe "s/$additionalPattern/\${1}$version\${2}/g;" \ - "$script" || returnDying "error during the additional replacement, see above" || return $? + "$yaml" || returnDying "error during the additional replacement, see above" || return $? fi done } diff --git a/src/releasing/update-version-scripts.sh b/src/releasing/update-version-scripts.sh index 3961ed41..b6bd4400 100755 --- a/src/releasing/update-version-scripts.sh +++ b/src/releasing/update-version-scripts.sh @@ -67,7 +67,7 @@ function updateVersionScripts() { parseArguments params "$examples" "$TEGONAL_SCRIPTS_VERSION" "$@" || return $? if ! [[ -v directory ]]; then directory="./src"; fi - if ! [[ -v additionalPattern ]]; then additionalPattern=""; fi + if ! [[ -v additionalPattern ]]; then additionalPattern="$additionalPatternDefaultArg"; fi exitIfNotAllArgumentsSet params "$examples" "$TEGONAL_SCRIPTS_VERSION" local where @@ -76,7 +76,7 @@ function updateVersionScripts() { else where="directory $directory (and subdirectories)" fi - echo "set version $version in bash headers in $where" + logInfo "set version $version in bash headers in $where" if [[ -n $additionalPattern ]]; then echo "also going to search for $additionalPattern and replace with \${1}$version\${2}" fi diff --git a/src/utility/checks.sh b/src/utility/checks.sh index 933431f5..a3d59f16 100644 --- a/src/utility/checks.sh +++ b/src/utility/checks.sh @@ -359,6 +359,15 @@ function exitIfPathNamedIsOutsideOf() { checkPathNamedIsInsideOf "$@" || exit $? } +function exitIfPathNamedIsOutsideOfCurrentDir() { + if ! [[ -v currentDir ]]; then + local currentDir + currentDir=$(pwd) || die "could not determine currentDir, maybe it does not exist anymore?" + local -r currentDir + fi + checkPathNamedIsInsideOf "$@" "$currentDir" || exit $? +} + getCallerFuncNameButIgnore() { local -a skipNames=("$@") # 0 is getCallerFuncNameButIgnore itself, 1 is its caller and we want to get the caller of the caller