Skip to content

Commit e629d78

Browse files
Interactive mode requires -s when -e is used (#378)
* Require -s with -e in interactive mode * Add similar checks for CI-local experiments * Add release notes for 2.3.2 * Rename validate_required_config to validate_required_args * Improve symmetry of CI~Local experiments execute function * Move validation of required arguments to a common location * Add call to print_bl before validate_required_args * Add hook for processing additional script arguments * Move original process arguments logic to its own function * Replace _arguments with _args in all places --------- Co-authored-by: Etienne Studer <[email protected]>
1 parent c6168d2 commit e629d78

11 files changed

+83
-91
lines changed

components/scripts/gradle/01-validate-incremental-building.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ main() {
5353
}
5454

5555
execute() {
56-
print_bl
57-
validate_required_config
58-
5956
make_experiment_dir
6057
git_checkout_project "build_${project_name}"
6158

@@ -75,7 +72,6 @@ execute() {
7572
}
7673

7774
wizard_execute() {
78-
print_bl
7975
print_introduction
8076

8177
if [[ "${build_scan_publishing_mode}" == "on" ]]; then
@@ -365,5 +361,5 @@ EOF
365361
echo -n "${text}"
366362
}
367363

368-
process_arguments "$@"
364+
process_args "$@"
369365
main

components/scripts/gradle/02-validate-local-build-caching-same-location.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ main() {
5353
}
5454

5555
execute() {
56-
print_bl
57-
validate_required_config
58-
5956
make_experiment_dir
6057
make_local_cache_dir
6158
git_checkout_project "build_${project_name}"
@@ -76,7 +73,6 @@ execute() {
7673
}
7774

7875
wizard_execute() {
79-
print_bl
8076
print_introduction
8177

8278
if [[ "${build_scan_publishing_mode}" == "on" ]]; then
@@ -345,5 +341,5 @@ EOF
345341
echo -n "${text}"
346342
}
347343

348-
process_arguments "$@"
344+
process_args "$@"
349345
main

components/scripts/gradle/03-validate-local-build-caching-different-locations.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ main() {
5353
}
5454

5555
execute() {
56-
print_bl
57-
validate_required_config
58-
5956
make_experiment_dir
6057
make_local_cache_dir
6158
git_checkout_project "first-build_${project_name}"
@@ -77,7 +74,6 @@ execute() {
7774
}
7875

7976
wizard_execute() {
80-
print_bl
8177
print_introduction
8278

8379
if [[ "${build_scan_publishing_mode}" == "on" ]]; then
@@ -384,5 +380,5 @@ EOF
384380
}
385381

386382

387-
process_arguments "$@"
383+
process_args "$@"
388384
main

components/scripts/gradle/04-validate-remote-build-caching-ci-ci.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ main() {
5151
}
5252

5353
execute() {
54-
print_bl
55-
validate_required_args
56-
5754
fetch_build_scans
5855
make_experiment_dir
5956

@@ -62,7 +59,6 @@ execute() {
6259
}
6360

6461
wizard_execute() {
65-
print_bl
6662
print_introduction
6763

6864
print_bl
@@ -103,17 +99,20 @@ wizard_execute() {
10399
explain_and_print_summary
104100
}
105101

102+
# Overrides config.sh#validate_required_args
106103
validate_required_args() {
107-
if [ -z "${_arg_first_build_ci}" ]; then
108-
_PRINT_HELP=yes die "ERROR: Missing required argument: --first-build-ci" "${INVALID_INPUT}"
109-
fi
104+
if [ "${interactive_mode}" == "off" ]; then
105+
if [ -z "${_arg_first_build_ci}" ]; then
106+
_PRINT_HELP=yes die "ERROR: Missing required argument: --first-build-ci" "${INVALID_INPUT}"
107+
fi
110108

111-
if [ -z "${_arg_second_build_ci}" ]; then
112-
_PRINT_HELP=yes die "ERROR: Missing required argument: --second-build-ci" "${INVALID_INPUT}"
113-
fi
109+
if [ -z "${_arg_second_build_ci}" ]; then
110+
_PRINT_HELP=yes die "ERROR: Missing required argument: --second-build-ci" "${INVALID_INPUT}"
111+
fi
114112

115-
build_scan_urls+=("${_arg_first_build_ci}")
116-
build_scan_urls+=("${_arg_second_build_ci}")
113+
build_scan_urls+=("${_arg_first_build_ci}")
114+
build_scan_urls+=("${_arg_second_build_ci}")
115+
fi
117116
}
118117

119118
fetch_build_scans() {
@@ -319,5 +318,5 @@ EOF
319318
print_interactive_text "${text}"
320319
}
321320

322-
process_arguments "$@"
321+
process_args "$@"
323322
main

components/scripts/gradle/05-validate-remote-build-caching-ci-local.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ remote_build_cache_url=''
4343
mapping_file=''
4444

4545
main() {
46-
process_script_arguments
4746
if [ "${interactive_mode}" == "on" ]; then
4847
wizard_execute
4948
else
@@ -54,8 +53,6 @@ main() {
5453
}
5554

5655
execute() {
57-
print_bl
58-
validate_required_args
5956
fetch_build_params_from_build_scan
6057
validate_build_config
6158

@@ -74,7 +71,6 @@ execute() {
7471
}
7572

7673
wizard_execute() {
77-
print_bl
7874
print_introduction
7975

8076
print_bl
@@ -137,15 +133,22 @@ wizard_execute() {
137133
explain_and_print_summary
138134
}
139135

140-
process_script_arguments() {
136+
map_additional_script_args() {
141137
ci_build_scan_url="${_arg_first_build_ci}"
142138
remote_build_cache_url="${_arg_remote_build_cache_url}"
143139
mapping_file="${_arg_mapping_file}"
144140
}
145141

142+
# Overrides config.sh#validate_required_args
146143
validate_required_args() {
147-
if [ -z "${ci_build_scan_url}" ]; then
148-
_PRINT_HELP=yes die "ERROR: Missing required argument: --first-build-ci" "${INVALID_INPUT}"
144+
if [ "${interactive_mode}" == "off" ]; then
145+
if [ -z "${ci_build_scan_url}" ]; then
146+
_PRINT_HELP=yes die "ERROR: Missing required argument: --first-build-ci" "${INVALID_INPUT}"
147+
fi
148+
fi
149+
150+
if [[ "${enable_ge}" == "on" && -z "${ge_server}" ]]; then
151+
_PRINT_HELP=yes die "ERROR: Missing required argument when enabling Gradle Enterprise on a project not already connected: --gradle-enterprise-server" "${INVALID_INPUT}"
149152
fi
150153
}
151154

@@ -187,10 +190,6 @@ validate_build_config() {
187190
if [ -z "${git_commit_id}" ]; then
188191
_PRINT_HELP=yes die "ERROR: Git commit id was not found in the build scan. Specify missing argument: --git-commit-id" "${INVALID_INPUT}"
189192
fi
190-
191-
if [[ "${enable_ge}" == "on" && -z "${ge_server}" ]]; then
192-
_PRINT_HELP=yes die "ERROR: Missing required argument when enabling Gradle Enterprise on a project not already connected: --gradle-enterprise-server" "${INVALID_INPUT}"
193-
fi
194193
}
195194

196195
execute_build() {
@@ -513,5 +512,5 @@ EOF
513512
print_interactive_text "${text}"
514513
}
515514

516-
process_arguments "$@"
515+
process_args "$@"
517516
main

components/scripts/lib/config.sh

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/usr/bin/env bash
22

3-
# shellcheck disable=SC2034 # not all of the variables set in this function are used by all scripts
4-
process_arguments() {
3+
process_args() {
54
parse_commandline "$@"
5+
map_common_script_args
6+
map_additional_script_args
7+
print_bl
8+
validate_required_args
9+
}
610

11+
map_common_script_args() {
712
if [ -n "${_arg_git_repo+x}" ]; then
813
git_repo="${_arg_git_repo}"
914
project_name="$(basename -s .git "${git_repo}")"
@@ -25,13 +30,11 @@ process_arguments() {
2530
project_dir="${_arg_project_dir}"
2631
fi
2732

28-
# shellcheck disable=SC2154
2933
if [ -n "${_arg_tasks+x}" ]; then
3034
tasks="${_arg_tasks}"
3135
remove_clean_from_tasks
3236
fi
3337

34-
# shellcheck disable=SC2154
3538
if [ -n "${_arg_goals+x}" ]; then
3639
tasks="${_arg_goals}"
3740
remove_clean_from_tasks
@@ -41,7 +44,6 @@ process_arguments() {
4144
extra_args="${_arg_args}"
4245
fi
4346

44-
#shellcheck disable=SC2154
4547
if [ -n "${_arg_mapping_file+x}" ]; then
4648
mapping_file="${_arg_mapping_file}"
4749
fi
@@ -50,7 +52,6 @@ process_arguments() {
5052
ge_server="${_arg_gradle_enterprise_server}"
5153
fi
5254

53-
#shellcheck disable=SC2154
5455
if [ -n "${_arg_enable_gradle_enterprise+x}" ]; then
5556
enable_ge="${_arg_enable_gradle_enterprise}"
5657
fi
@@ -75,16 +76,29 @@ process_arguments() {
7576
fi
7677
}
7778

78-
validate_required_config() {
79-
if [ -z "${git_repo}" ]; then
80-
_PRINT_HELP=yes die "ERROR: Missing required argument: --git-repo" "${INVALID_INPUT}"
81-
fi
79+
# Some experiments may require additional arguments, in which case this function
80+
# should be overridden for that experiment.
81+
map_additional_script_args() {
82+
true
83+
}
8284

83-
if [ -z "${tasks}" ]; then
84-
if [[ "${BUILD_TOOL}" == "Maven" ]]; then
85-
_PRINT_HELP=yes die "ERROR: Missing required argument: --goals" "${INVALID_INPUT}"
86-
else
87-
_PRINT_HELP=yes die "ERROR: Missing required argument: --tasks" "${INVALID_INPUT}"
85+
# This function performs common validation relevant for most experiments.
86+
# Some experiments may have a different set of required arguments, in which case
87+
# this function should be overridden for that experiment.
88+
validate_required_args() {
89+
# In non-interactive mode, these arguments are required.
90+
# In interactive mode, the user will be prompted to enter any missing config.
91+
if [ "${interactive_mode}" == "off" ]; then
92+
if [ -z "${git_repo}" ]; then
93+
_PRINT_HELP=yes die "ERROR: Missing required argument: --git-repo" "${INVALID_INPUT}"
94+
fi
95+
96+
if [ -z "${tasks}" ]; then
97+
if [[ "${BUILD_TOOL}" == "Maven" ]]; then
98+
_PRINT_HELP=yes die "ERROR: Missing required argument: --goals" "${INVALID_INPUT}"
99+
else
100+
_PRINT_HELP=yes die "ERROR: Missing required argument: --tasks" "${INVALID_INPUT}"
101+
fi
88102
fi
89103
fi
90104

components/scripts/maven/01-validate-local-build-caching-same-location.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ main() {
5252
}
5353

5454
execute() {
55-
print_bl
56-
validate_required_config
57-
5855
make_experiment_dir
5956
make_local_cache_dir
6057
git_checkout_project "build_${project_name}"
@@ -75,7 +72,6 @@ execute() {
7572
}
7673

7774
wizard_execute() {
78-
print_bl
7975
print_introduction
8076

8177
if [[ "${build_scan_publishing_mode}" == "on" ]]; then
@@ -346,5 +342,5 @@ EOF
346342
echo -n "${text}"
347343
}
348344

349-
process_arguments "$@"
345+
process_args "$@"
350346
main

components/scripts/maven/02-validate-local-build-caching-different-locations.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ main() {
5252
}
5353

5454
execute() {
55-
print_bl
56-
validate_required_config
57-
5855
make_experiment_dir
5956
make_local_cache_dir
6057
git_checkout_project "first-build_${project_name}"
@@ -75,7 +72,6 @@ execute() {
7572
}
7673

7774
wizard_execute() {
78-
print_bl
7975
print_introduction
8076

8177
if [[ "${build_scan_publishing_mode}" == "on" ]]; then
@@ -382,5 +378,5 @@ EOF
382378
echo -n "${text}"
383379
}
384380

385-
process_arguments "$@"
381+
process_args "$@"
386382
main

components/scripts/maven/03-validate-remote-build-caching-ci-ci.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ main() {
4949
}
5050

5151
execute() {
52-
print_bl
53-
validate_required_args
54-
5552
fetch_build_scans
5653
make_experiment_dir
5754

@@ -60,7 +57,6 @@ execute() {
6057
}
6158

6259
wizard_execute() {
63-
print_bl
6460
print_introduction
6561

6662
print_bl
@@ -101,17 +97,20 @@ wizard_execute() {
10197
explain_and_print_summary
10298
}
10399

100+
# Overrides config.sh#validate_required_args
104101
validate_required_args() {
105-
if [ -z "${_arg_first_build_ci}" ]; then
106-
_PRINT_HELP=yes die "ERROR: Missing required argument: --first-build-ci" "${INVALID_INPUT}"
107-
fi
102+
if [ "${interactive_mode}" == "off" ]; then
103+
if [ -z "${_arg_first_build_ci}" ]; then
104+
_PRINT_HELP=yes die "ERROR: Missing required argument: --first-build-ci" "${INVALID_INPUT}"
105+
fi
108106

109-
if [ -z "${_arg_second_build_ci}" ]; then
110-
_PRINT_HELP=yes die "ERROR: Missing required argument: --second-build-ci" "${INVALID_INPUT}"
111-
fi
107+
if [ -z "${_arg_second_build_ci}" ]; then
108+
_PRINT_HELP=yes die "ERROR: Missing required argument: --second-build-ci" "${INVALID_INPUT}"
109+
fi
112110

113-
build_scan_urls+=("${_arg_first_build_ci}")
114-
build_scan_urls+=("${_arg_second_build_ci}")
111+
build_scan_urls+=("${_arg_first_build_ci}")
112+
build_scan_urls+=("${_arg_second_build_ci}")
113+
fi
115114
}
116115

117116
fetch_build_scans() {
@@ -317,5 +316,5 @@ EOF
317316
print_interactive_text "${text}"
318317
}
319318

320-
process_arguments "$@"
319+
process_args "$@"
321320
main

0 commit comments

Comments
 (0)