Skip to content

Commit 892cb7e

Browse files
committed
draft param-template
1 parent fccab80 commit 892cb7e

23 files changed

+393
-84
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ body:
2727
- qa/run-shellcheck.sh
2828
- qa/run-shellcheck-pull-hooks.sh
2929
- qa/run-shellspec-if-installed.sh
30-
- releasing/common-constants.source.sh
31-
- releasing/deduce-next-version.source.sh
3230
- releasing/pre-release-checks-git.sh
3331
- releasing/prepare-files-next-dev-cycle.sh
3432
- releasing/prepare-next-dev-cycle-template.sh

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ Help:
399399
```text
400400
Parameters:
401401
-v The version to release in the format vX.Y.Z(-RC...)
402-
-k|key The GPG private key which shall be used to sign the files
403-
--sign-fn Function which is called to determine what files should be signed. It should be based find and allow to pass further arguments (we will i.a. pass -print0)
402+
--release-hook performs the main release task such as (run tests) create artifacts, deploy artifacts
404403
-b|--branch (optional) The expected branch which is currently checked out -- default: main
405404
--project-dir (optional) The projects directory -- default: .
406405
-p|--pattern (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}
@@ -675,7 +674,8 @@ Help:
675674
<!-- auto-generated, do not modify here but in src/releasing/prepare-next-dev-cycle-template.sh -->
676675
```text
677676
Parameters:
678-
-v the version for which we prepare the dev cycle
677+
-v The version for which we prepare the dev cycle
678+
-b|--branch (optional) The branch on which we develop the next version
679679
--project-dir (optional) The projects directory -- default: .
680680
-p|--pattern (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}
681681
--before-pr-fn (optional) defines the function which is executed before preparing the release (to see if we should release) and after preparing the release -- default: beforePr (per convention defined in scripts/before-pr.sh). No arguments are passed

scripts/before-pr.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ sourceOnce "$dir_of_tegonal_scripts/qa/run-shellspec-if-installed.sh"
2727
sourceOnce "$scriptsDir/check-in-bug-template.sh"
2828
sourceOnce "$scriptsDir/cleanup-on-push-to-main.sh"
2929
sourceOnce "$scriptsDir/run-shellcheck.sh"
30+
sourceOnce "$scriptsDir/check-params-and-definition-in-sync.sh"
3031

3132
function beforePr() {
3233
# using && because this function is used on the left side of an || in releaseFiles
3334
# this way we still have fail fast behaviour and don't mask/hide a non-zero exit code
3435
runShellspecIfInstalled --jobs 2 &&
35-
checkInBugTemplate &&
3636
customRunShellcheck &&
37+
checkParamsAndDefinitionInSync &&
38+
checkInBugTemplate &&
3739
cleanupOnPushToMain
3840
}
3941

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
#
3+
# __ __
4+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts
5+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
6+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0
7+
# /___/ Please report bugs and contribute back your improvements
8+
#
9+
# Version: v3.2.0-SNAPSHOT
10+
###################################
11+
set -euo pipefail
12+
shopt -s inherit_errexit
13+
unset CDPATH
14+
15+
if ! [[ -v scriptsDir ]]; then
16+
scriptsDir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)"
17+
readonly scriptsDir
18+
fi
19+
20+
if ! [[ -v dir_of_tegonal_scripts ]]; then
21+
dir_of_tegonal_scripts="$scriptsDir/../src"
22+
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
23+
fi
24+
25+
function checkParamsAndDefinitionInSync() {
26+
local foundErrors=0
27+
local numOfFiles=0
28+
29+
while read -r -d $'\0' paramsFile; do
30+
numOfFiles=$((numOfFiles + 1))
31+
local definitionFile="${paramsFile//.params.source/.params-definition.source}"
32+
if ! [[ -f "$definitionFile" ]]; then
33+
((++foundErrors))
34+
logError "definition file %s does not exist" "$definitionFile"
35+
continue
36+
fi
37+
local params paramDefinitions
38+
params=$(grep "^local" "$paramsFile") || die "could not grep params file %s" "$paramsFile"
39+
local contentDefinitionFile
40+
contentDefinitionFile=$(cat "$definitionFile")
41+
local regex="local -ra [a-zA-Z0-9_]+Params=\(([^\)]+\n)\)"
42+
if [[ $contentDefinitionFile =~ $regex ]]; then
43+
paramDefinitions="$(awk 'NF && /^\s+[a-zA-Z_].+/ {print $1}' <<<"${BASH_REMATCH[1]}" )"
44+
else
45+
die "could not extract parameter definitions from file %s" "$definitionFile"
46+
fi
47+
for param in $params; do
48+
if ! [[ $param == "local" || $param == "#" ]]; then
49+
if ! grep "$param" <<<"$paramDefinitions" >/dev/null; then
50+
((++foundErrors))
51+
logError "could not find param \033[0;36m%s\033[0m in definition file %s" "$param" "$definitionFile"
52+
fi
53+
fi
54+
done
55+
for param in $paramDefinitions; do
56+
if ! grep "$param" <<<"$params" >/dev/null; then
57+
((++foundErrors))
58+
logError "could not find param \033[0;36m%s\033[0m in source file %s" "$param" "$definitionFile"
59+
fi
60+
done
61+
done \
62+
< <(
63+
# using find here instead of find ... | while so that we can write foundErrors
64+
# we cannot do this when using the pipe approach as it will use a subshell for while
65+
find "$dir_of_tegonal_scripts" -name "*.params.source.sh" \
66+
-print0 ||
67+
# `while read` will fail because there is no \0
68+
true
69+
)
70+
71+
if [[ $foundErrors -eq 0 ]]; then
72+
logSuccess "%s params.source.sh files in sync with their params-definition.source.sh" "$numOfFiles"
73+
else
74+
returnDying "%s params.source.sh files are not in sync with their definition, see errors above (%s are in sync)" "$foundErrors" "$((numOfFiles - foundErrors))"
75+
fi
76+
}
77+
78+
${__SOURCED__:+return}
79+
checkParamsAndDefinitionInSync "$@"

spec/utility/parse-commands_spec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function my_lib_login() {
1818
echo "called my_lib_login"
1919
}
2020
function my_lib_self_update() {
21-
echo "called my_lib_self_updatelogin"
21+
echo "called my_lib_self_update"
2222
}
2323

2424
Describe 'parse-commands.sh'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/gt
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under European Union Public License 1.2
8+
# /___/ Please report bugs and contribute back your improvements
9+
# Version: v3.2.0-SNAPSHOT
10+
####### Description #############
11+
#
12+
# defines the parameters for afterVersionUpdateHook functions
13+
#
14+
###################################
15+
16+
local -ra afterVersionHookParams=(
17+
version "$versionParamPattern" "$versionParamDocu"
18+
branch "$branchParamPattern" "$branchParamDocu"
19+
projectsRootDir "$projectsRootDirParamPattern" "$projectsRootDirParamDocu"
20+
additionalPattern "$additionalPatternParamPattern" "$additionalPatternParamDocu"
21+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/gt
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under European Union Public License 1.2
8+
# /___/ Please report bugs and contribute back your improvements
9+
# Version: v3.2.0-SNAPSHOT
10+
####### Description #############
11+
#
12+
# defines local variables for the params defined in after-version-update-hook.params-definition.source.sh
13+
#
14+
###################################
15+
16+
local version branch projectsRootDir additionalPattern

src/releasing/common-constants.source.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,5 @@ local -r afterVersionUpdateHookParamPattern="$afterVersionUpdateHookParamPattern
7070
local -r afterVersionUpdateHookParamDocu="(optional) if defined, then this function is called after versions were updated and before calling beforePr. \
7171
The following arguments are passed: $versionParamPatternLong version $projectsRootDirParamPatternLong projectsRootDir and $additionalPatternParamPatternLong additionalPattern"
7272

73-
local -ra afterVersionHookParams=(
74-
version "$versionParamPattern" "$versionParamDocu"
75-
projectsRootDir "$projectsRootDirParamPattern" "$projectsRootDirParamDocu"
76-
additionalPattern "$additionalPatternParamPattern" "$additionalPatternParamDocu"
77-
)
73+
# shellcheck disable=SC2154 # it is assumed dir_of_tegonal_scripts is defined where this file is sourced
74+
source "$dir_of_tegonal_scripts/releasing/prepare-files-next-dev-cycle.params-definition.source.sh"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/gt
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under European Union Public License 1.2
8+
# /___/ Please report bugs and contribute back your improvements
9+
# Version: v3.2.0-SNAPSHOT
10+
####### Description #############
11+
#
12+
# defines the parameters for release-files.sh
13+
#
14+
###################################
15+
16+
# shellcheck disable=SC2154 # it is assumed dir_of_tegonal_scripts is defined where this file is sourced
17+
source "$dir_of_tegonal_scripts/releasing/release-files.params-definition.source.sh"
18+
19+
# keep in sync with src/releasing/release-files.params.source.sh
20+
local -ra prepareFilesNextDevCycleParams=(
21+
"${releaseTemplateParams[@]:0:3}"
22+
key "$keyParamPattern" "$keyParamDocu"
23+
findForSigning "$findForSigningParamPattern" "$findForSigningParamDocu"
24+
"${releaseTemplateParams[@]:6}"
25+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/gt
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under European Union Public License 1.2
8+
# /___/ Please report bugs and contribute back your improvements
9+
# Version: v3.2.0-SNAPSHOT
10+
####### Description #############
11+
#
12+
# deduces nextVersion from version if set and initialises default arguments for params defined in
13+
#
14+
###################################
15+
16+
# Note, it is used in release-template.default-args.source.sh, if you should add default args which are only relevant
17+
# for prepare-next then don't re-use in release-template.default-args any more.
18+
if ! [[ -v branch ]]; then branch="main"; fi
19+
if ! [[ -v projectsRootDir ]]; then projectsRootDir=$(realpath "."); fi
20+
if ! [[ -v additionalPattern ]]; then additionalPattern="^$"; fi
21+
if ! [[ -v beforePrFn ]]; then beforePrFn='beforePr'; fi
22+
if ! [[ -v afterVersionUpdateHook ]]; then afterVersionUpdateHook=''; fi

0 commit comments

Comments
 (0)