@@ -104,13 +104,15 @@ The scripts are ordered by topic:
104104- [ CI] ( #continuous-integration )
105105 - [install shellcheck](#install-shellcheck)
106106 - [install shellspec](#install-shellspec)
107+ - [install shfmt](#install-shfmt)
107108 - [Jelastic](#jelastic)
108109 - [deploy](#deploy-to-jelastic)
109110 - [utils](#jelastic-utils)
110111- [ Quality Assurance] ( #quality-assurance )
111112 - [runShellcheck](#runshellcheck)
112113 - [runShellcheckPullHooks](#runshellcheck-on-pull-hookssh)
113114 - [runShellspecIfInstalled](#runshellspecifinstalled)
115+ - [runShfmt](#runshfmt)
114116- [ Releasing] ( #releasing )
115117 - [Releasing Files](#release-files)
116118 - [Prepare Files Next Dev Cycle](#prepare-files-next-dev-cycle)
@@ -194,6 +196,28 @@ jobs:
194196
195197</ci-install-shellspec >
196198
199+
200+ ## Install shfmt
201+
202+ <ci-install-shfmt >
203+
204+ <!-- auto-generated, do not modify here but in src/ci/install-shfmt.sh.doc -->
205+ ``` bash
206+ # run the install-shfmt.sh in your github/gitlab workflow
207+ # for instance, assuming you fetched this file via gt and remote name is tegonal-scripts
208+ # then in a github workflow you would have
209+
210+ jobs:
211+ steps:
212+ - name: install shfmt
213+ run: ./lib/tegonal-scripts/src/ci/install-shfmt.sh
214+ # and most likely as well
215+ - name: run shfmt
216+ run: ./scripts/run-shfmt.sh
217+ ```
218+
219+ </ci-install-shfmt >
220+
197221## Jelastic
198222
199223The scripts under this topic (in directory ` ci/jelastic ` ) help out when dealing with jelastic cli
@@ -306,9 +330,9 @@ The scripts under this topic (in directory `qa`) perform checks or execute qa to
306330
307331## runShellcheck
308332
309- A function which expects the name of an array of dirs as first argument and a source path as second argument (which is
310- passed to shellcheck via -P parameter). It then executes shellcheck for each * .sh in these directories with predefined
311- settings for shellcheck.
333+ A function which expects the name of an array of dirs as first argument, a source path as second argument (which is
334+ passed to ` shellcheck ` via ` -P ` parameter) and optionally additional arguments which are passed to the ` find ` command.
335+ It then executes shellcheck for each * .sh in these directories with predefined settings for shellcheck.
312336
313337<qa-run-shellcheck >
314338
@@ -370,6 +394,39 @@ runShellspecIfInstalled --jobs 2
370394
371395</qa-run-shellspec-if-installed >
372396
397+ ## runShfmt
398+
399+ A function which expects the name of an array of dirs as first argument and optionally additional arguments which
400+ are passed to the ` find ` command. It then executes shfmt for each * .sh in these directories.
401+
402+ <qa-run-shfmt >
403+
404+ <!-- auto-generated, do not modify here but in src/qa/run-shfmt.sh.doc -->
405+ ``` bash
406+ #! /usr/bin/env bash
407+ set -euo pipefail
408+ shopt -s inherit_errexit || { echo >&2 " please update to bash 5, see errors above" && exit 1; }
409+ # Assumes tegonal's scripts were fetched with gt - adjust location accordingly
410+ dir_of_tegonal_scripts=" $( cd -- " $( dirname -- " ${BASH_SOURCE[0]:- $0 } " ) " > /dev/null && pwd 2> /dev/null) /../lib/tegonal-scripts/src"
411+ source " $dir_of_tegonal_scripts /setup.sh" " $dir_of_tegonal_scripts "
412+
413+ source " $dir_of_tegonal_scripts /qa/run-shfmt.sh"
414+
415+ # shellcheck disable=SC2034 # is passed by name to runShfmt
416+ declare -a dirs=(
417+ " $dir_of_tegonal_scripts "
418+ " $dir_of_tegonal_scripts /../scripts"
419+ " $dir_of_tegonal_scripts /../spec"
420+ )
421+ runShfmt dirs -not -name sh-to-exclude.sh
422+
423+ # pass the working directory of gt which usually is .gt in the root of your repository
424+ # this will run shfmt on all pull-hook.sh files
425+ runShfmtPullHooks " .gt"
426+ ```
427+
428+ </qa-run-shfmt >
429+
373430# Releasing
374431
375432The scripts under this topic (in directory ` releasing ` ) perform some steps of your release process.
@@ -523,7 +580,7 @@ sourceOnce "$scriptsDir/before-pr.sh"
523580# prepare dev cycle for version v0.2.0, assumes a function beforePr is in scope which we sourced above
524581" $dir_of_tegonal_scripts /releasing/prepare-files-next-dev-cycle.sh" -v v0.2.0
525582
526- function specialBeforePr(){
583+ function specialBeforePr() {
527584 beforePr && echo " imagine some additional work"
528585}
529586# make the function visible to release-files.sh / not necessary if you source prepare-files-next-dev-cycle.sh, see further below
@@ -701,7 +758,6 @@ shopt -s inherit_errexit || { echo >&2 "please update to bash 5, see errors abov
701758dir_of_tegonal_scripts=" $( cd -- " $( dirname -- " ${BASH_SOURCE[0]:- $0 } " ) " > /dev/null && pwd 2> /dev/null) /../lib/tegonal-scripts/src"
702759source " $dir_of_tegonal_scripts /setup.sh" " $dir_of_tegonal_scripts "
703760
704-
705761function prepareNextAfterVersionUpdateHook() {
706762 # some additional version bumps e.g. using perl
707763 perl -0777 -i # ...
@@ -1362,10 +1418,10 @@ function foo() {
13621418 local -r version=$4
13631419
13641420 # resolves arr recursively via recursiveDeclareP and check that is a non-associative array
1365- checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line
1366- checkArgIsFunction " $fn " 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line
1367- checkArgIsBoolean " $bool " 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line
1368- checkArgIsVersion " $version " 4 # same as exitIfArgIsNotVersion if set -e has an effect on this line
1421+ checkArgIsArray arr 1 # same as exitIfArgIsNotArray if set -e has an effect on this line
1422+ checkArgIsFunction " $fn " 2 # same as exitIfArgIsNotFunction if set -e has an effect on this line
1423+ checkArgIsBoolean " $bool " 3 # same as exitIfArgIsNotBoolean if set -e has an effect on this line
1424+ checkArgIsVersion " $version " 4 # same as exitIfArgIsNotVersion if set -e has an effect on this line
13691425
13701426 # shellcheck disable=SC2329 # is passed by name to checkArgIsArrayWithTuples
13711427 function describeTriple() {
@@ -1447,15 +1503,15 @@ timestampToDate 1662981524 # outputs 2022-09-12
14471503# (usually as defined by the user in the system settings)
14481504timestampToDateInUserFormat 1662981524 # outputs 12.09.2022 for ch_DE
14491505
1450- dateToTimestamp " 2024-03-01" # outputs 1709247600
1506+ dateToTimestamp " 2024-03-01" # outputs 1709247600
14511507dateToTimestamp " 2022-09-12T13:18:44" # outputs 1662981524
14521508
14531509# outputs a timestamp in ms
14541510startTimestampInMs=" $( timestampInMs) "
14551511
1456- formatMsToSeconds 12 # outputs 0.012
1457- formatMsToSeconds 1234 # outputs 1.234
1458- formatMsToSeconds -123 # outputs -0.123
1512+ formatMsToSeconds 12 # outputs 0.012
1513+ formatMsToSeconds 1234 # outputs 1.234
1514+ formatMsToSeconds -123 # outputs -0.123
14591515# note that formatMsToSeconds does not check if you pass a number
14601516
14611517# outputs the time passed since the given timestamp in ms formatted as seconds
@@ -1648,7 +1704,6 @@ function readFile() {
16481704# executes readFile and closes the file descriptors again
16491705withCustomOutputInput 3 4 readFile " my-file.txt"
16501706
1651-
16521707# First tries to set chmod 777 to the directory and all files within it and then deletes the directory
16531708deleteDirChmod777 " .git"
16541709```
@@ -1832,7 +1887,7 @@ function myFunctionWithVarargs() {
18321887 parseFnArgs params " $@ " || return $?
18331888
18341889 # use varargs in another script
1835- echo " command: $command , dir: $dir , varargs: ${varargs* } "
1890+ echo " command: $command , dir: $dir , varargs: ${varargs[*] } "
18361891}
18371892```
18381893
@@ -1986,7 +2041,7 @@ source "$dir_of_tegonal_scripts/utility/replace-snippet.sh"
19862041
19872042declare file
19882043file=$( mktemp)
1989- echo " <my-script></my-script>" > " $file "
2044+ echo " <my-script></my-script>" > " $file "
19902045
19912046declare dir fileName output
19922047dir=$( dirname " $file " )
@@ -2067,10 +2122,10 @@ source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
20672122
20682123source " $dir_of_tegonal_scripts /utility/source-once.sh"
20692124
2070- sourceOnce " foo.sh" # creates a variable named sourceOnceGuard_foo__sh which acts as guard and sources foo.sh
2071- sourceOnce " foo.sh" # will source nothing as sourceOnceGuard_foo__sh is already defined
2072- unset sourceOnceGuard_foo__sh # unsets the guard
2073- sourceOnce " foo.sh" # is sourced again and the guard established
2125+ sourceOnce " foo.sh" # creates a variable named sourceOnceGuard_foo__sh which acts as guard and sources foo.sh
2126+ sourceOnce " foo.sh" # will source nothing as sourceOnceGuard_foo__sh is already defined
2127+ unset sourceOnceGuard_foo__sh # unsets the guard
2128+ sourceOnce " foo.sh" # is sourced again and the guard established
20742129# you can also use sourceAlways instead of unsetting and using sourceOnce.
20752130sourceAlways " foo.sh"
20762131
0 commit comments