Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/cleanup-on-push-to-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/releasing/common-constants.source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <info@tegonal.com>
# \__/\__/\_, /\___/_//_/\_,_/_/ 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions src/releasing/prepare-files-next-dev-cycle-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand Down
13 changes: 7 additions & 6 deletions src/releasing/prepare-next-dev-cycle-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
Expand Down
7 changes: 4 additions & 3 deletions src/releasing/release-files-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 8 additions & 9 deletions src/releasing/release-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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 $?
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/releasing/update-version-README.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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 $?
Expand Down
6 changes: 4 additions & 2 deletions src/releasing/update-version-common-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions src/releasing/update-version-issue-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/releasing/update-version-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/utility/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading