Skip to content

Commit 7cb5f06

Browse files
committed
draft param-template
1 parent fccab80 commit 7cb5f06

26 files changed

+460
-104
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,26 @@ 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
30+
- releasing/after-version-update-hook.params.source.sh
31+
- releasing/after-version-update-hook.params-definition.source.sh
3132
- releasing/deduce-next-version.source.sh
33+
- releasing/common-constants.source.sh
3234
- releasing/pre-release-checks-git.sh
3335
- releasing/prepare-files-next-dev-cycle.sh
36+
- releasing/prepare-files-next-dev-cycle.params.source.sh
37+
- releasing/prepare-files-next-dev-cycle.params-definition.source.sh-
3438
- releasing/prepare-next-dev-cycle-template.sh
39+
- releasing/prepare-next-dev-cycle-template.default-args.source.sh
40+
- releasing/prepare-next-dev-cycle-template.params.source.sh
41+
- releasing/prepare-next-dev-cycle-template.params-definition.source.sh
3542
- releasing/release-files.sh
43+
- releasing/release-files.default-args.source.sh
44+
- releasing/release-files.params.source.sh
45+
- releasing/release-files.params-definition.source.sh
3646
- releasing/release-template.sh
47+
- releasing/release-template.default-args.source.sh
48+
- releasing/release-template.params.source.sh
49+
- releasing/release-template.params-definition.source.sh
3750
- releasing/sbt-publish-to-sonatype.sh
3851
- releasing/sneak-peek-banner.sh
3952
- releasing/toggle-sections.sh

scripts/before-pr.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ if ! [[ -v dir_of_tegonal_scripts ]]; then
2323
fi
2424
sourceOnce "$dir_of_tegonal_scripts/utility/checks.sh"
2525
sourceOnce "$dir_of_tegonal_scripts/qa/run-shellspec-if-installed.sh"
26+
sourceOnce "$dir_of_tegonal_scripts/qa/run-shellspec-if-installed.sh"
2627

2728
sourceOnce "$scriptsDir/check-in-bug-template.sh"
2829
sourceOnce "$scriptsDir/cleanup-on-push-to-main.sh"
2930
sourceOnce "$scriptsDir/run-shellcheck.sh"
31+
sourceOnce "$scriptsDir/check-params-and-definition-in-sync.sh"
3032

3133
function beforePr() {
32-
# using && because this function is used on the left side of an || in releaseFiles
33-
# this way we still have fail fast behaviour and don't mask/hide a non-zero exit code
3434
runShellspecIfInstalled --jobs 2 &&
35-
checkInBugTemplate &&
3635
customRunShellcheck &&
36+
checkParamsAndDefinitionInSync &&
37+
checkInBugTemplate &&
3738
cleanupOnPushToMain
3839
}
3940

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_tegonal_scripts.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 -E "^(# )?local" "$paramsFile") || die "could not extract params from params file %s" "$paramsFile"
39+
paramDefinitions=$(
40+
awk '
41+
/^local -ra .*Params=\(/ { in_array=1; next }
42+
/^\)/ { in_array=0 }
43+
in_array && $1 !~ /^"/ && NF { print $1 }
44+
' "$definitionFile"
45+
) || die "could not extract parameter names from parameter definition file %s" "$definitionFile"
46+
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: 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/scripts
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0
8+
# /___/ Please report bugs and contribute back your improvements
9+
#
10+
# Version: v4.9.0-SNAPSHOT
11+
####### Description #############
12+
#
13+
# defines the parameters for afterVersionUpdateHook functions
14+
#
15+
###################################
16+
17+
local -ra afterVersionHookParams=(
18+
version "$versionParamPattern" "$versionParamDocu"
19+
branch "$branchParamPattern" "$branchParamDocu"
20+
projectsRootDir "$projectsRootDirParamPattern" "$projectsRootDirParamDocu"
21+
additionalPattern "$additionalPatternParamPattern" "$additionalPatternParamDocu"
22+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0
8+
# /___/ Please report bugs and contribute back your improvements
9+
#
10+
# Version: v4.9.0-SNAPSHOT
11+
####### Description #############
12+
#
13+
# defines local variables for the params defined in ...params-definition.source.sh
14+
#
15+
###################################
16+
17+
local version branch projectsRootDir additionalPattern

src/releasing/common-constants.source.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,3 @@ local -r afterVersionUpdateHookParamPatternLong='--after-version-update-hook'
6969
local -r afterVersionUpdateHookParamPattern="$afterVersionUpdateHookParamPatternLong"
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"
72-
73-
local -ra afterVersionHookParams=(
74-
version "$versionParamPattern" "$versionParamDocu"
75-
projectsRootDir "$projectsRootDirParamPattern" "$projectsRootDirParamDocu"
76-
additionalPattern "$additionalPatternParamPattern" "$additionalPatternParamDocu"
77-
)

src/releasing/pre-release-checks-git.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sourceOnce "$dir_of_tegonal_scripts/utility/git-utils.sh"
4545
sourceOnce "$dir_of_tegonal_scripts/utility/parse-args.sh"
4646

4747
function preReleaseCheckGit() {
48-
local versionRegex versionParamPatternLong
48+
local versionParamPatternLong
4949
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
5050

5151
local version branch
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0
8+
# /___/ Please report bugs and contribute back your improvements
9+
#
10+
# Version: v4.9.0-SNAPSHOT
11+
####### Description #############
12+
#
13+
# defines default args for ...params-definition.source.sh
14+
#
15+
###################################
16+
17+
# shellcheck disable=SC2154 # it is assumed dir_of_tegonal_scripts is defined where this file is sourced
18+
source "$dir_of_tegonal_scripts/releasing/prepare-next-dev-cycle-template.default-args.source.sh"
19+
20+
# currently prepare-files-next-dev-cycle defines not more optional params than prepare-next-dev-cycle-template, hence the above is enough
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts
6+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
7+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0
8+
# /___/ Please report bugs and contribute back your improvements
9+
#
10+
# Version: v4.9.0-SNAPSHOT
11+
####### Description #############
12+
#
13+
# defines the parameters for xyz.sh in xyz.params-definitions.sh
14+
#
15+
###################################
16+
17+
# shellcheck disable=SC2154 # it is assumed dir_of_tegonal_scripts is defined where this file is sourced
18+
source "$dir_of_tegonal_scripts/releasing/prepare-next-dev-cycle-template.params-definition.source.sh"
19+
20+
# keep in sync with src/releasing/release-files.params.source.sh
21+
local -ra prepareFilesNextDevCycleParams=(
22+
"${prepareNextDevCycleTemplateParams[@]}"
23+
)

0 commit comments

Comments
 (0)