Skip to content

Commit d1cd76d

Browse files
committed
introduce sourceOrDie to avoid the repetition of traceOrDie
1 parent 1786453 commit d1cd76d

15 files changed

+48
-160
lines changed

README.md

Lines changed: 8 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ The scripts are ordered by topic:
138138
- [Parse utils](#parse-utils)
139139
- [Recursive `declare -p`](#recursive-declare--p)
140140
- [Replace Snippets](#replace-snippets)
141-
- [`source` once](#source-once)
141+
- [`source` once/always/or die](#source-utility-functions)
142142
- [Update Documentation](#update-bash-documentation)
143143
144144
# Continuous Integration
@@ -410,24 +410,7 @@ Help:
410410
411411
<!-- auto-generated, do not modify here but in src/releasing/release-files.sh -->
412412
```text
413-
Parameters:
414-
-v The version to release in the format vX.Y.Z(-RC...)
415-
-k|key The GPG private key which shall be used to sign the files
416-
--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)
417-
-b|--branch (optional) The expected branch which is currently checked out -- default: main
418-
--project-dir (optional) The projects directory -- default: .
419-
-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}
420-
-nv|--next-version (optional) the version to use for prepare-next-dev-cycle -- default: is next minor based on version
421-
--prepare-only (optional) defines whether the release shall only be prepared (i.e. no push, no tag, no prepare-next-dev-cycle) -- default: false
422-
--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
423-
--prepare-next-dev-cycle-fn (optional) defines the function which is executed to prepare the next dev cycle -- default: perpareNextDevCycle (per convention defined in scripts/prepareNextDevCycle). The following arguments are passed: -v nextVersion --pattern additionalPattern --project-dir projectsRootDir --before-pr-fn beforePrFn
424-
--after-version-update-hook (optional) if defined, then this function is called after versions were updated and before calling beforePr. The following arguments are passed: -v version --project-dir projectsRootDir and --pattern additionalPattern
425-
426-
--help prints this help
427-
--version prints the version of this script
428413
429-
INFO: Version of release-files.sh is:
430-
v4.3.0-SNAPSHOT
431414
```
432415
433416
</releasing-release-files-help>
@@ -503,18 +486,7 @@ it uses the [prepare next dev cycle template](#prepare-next-dev-cycle-template)
503486
504487
<!-- auto-generated, do not modify here but in src/releasing/prepare-files-next-dev-cycle.sh -->
505488
```text
506-
Parameters:
507-
-v the version for which we prepare the dev cycle
508-
--project-dir (optional) The projects directory -- default: .
509-
-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}
510-
--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
511-
--after-version-update-hook (optional) if defined, then this function is called after versions were updated and before calling beforePr. The following arguments are passed: -v version --project-dir projectsRootDir and --pattern additionalPattern
512489
513-
--help prints this help
514-
--version prints the version of this script
515-
516-
INFO: Version of prepare-files-next-dev-cycle.sh is:
517-
v4.3.0-SNAPSHOT
518490
```
519491
520492
</releasing-prepare-files-next-dev-cycle-help>
@@ -599,23 +571,7 @@ Help:
599571
600572
<!-- auto-generated, do not modify here but in src/releasing/release-template.sh -->
601573
```text
602-
Parameters:
603-
-v The version to release in the format vX.Y.Z(-RC...)
604-
--release-hook performs the main release task such as (run tests) create artifacts, deploy artifacts
605-
-b|--branch (optional) The expected branch which is currently checked out -- default: main
606-
--project-dir (optional) The projects directory -- default: .
607-
-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}
608-
-nv|--next-version (optional) the version to use for prepare-next-dev-cycle -- default: is next minor based on version
609-
--prepare-only (optional) defines whether the release shall only be prepared (i.e. no push, no tag, no prepare-next-dev-cycle) -- default: false
610-
--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
611-
--prepare-next-dev-cycle-fn (optional) defines the function which is executed to prepare the next dev cycle -- default: perpareNextDevCycle (per convention defined in scripts/prepareNextDevCycle). The following arguments are passed: -v nextVersion --pattern additionalPattern --project-dir projectsRootDir --before-pr-fn beforePrFn
612-
--after-version-update-hook (optional) if defined, then this function is called after versions were updated and before calling beforePr. The following arguments are passed: -v version --project-dir projectsRootDir and --pattern additionalPattern
613574
614-
--help prints this help
615-
--version prints the version of this script
616-
617-
INFO: Version of release-template.sh is:
618-
v4.3.0-SNAPSHOT
619575
```
620576
621577
</releasing-release-template-help>
@@ -687,18 +643,7 @@ Help:
687643
688644
<!-- auto-generated, do not modify here but in src/releasing/prepare-next-dev-cycle-template.sh -->
689645
```text
690-
Parameters:
691-
-v the version for which we prepare the dev cycle
692-
--project-dir (optional) The projects directory -- default: .
693-
-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}
694-
--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
695-
--after-version-update-hook (optional) if defined, then this function is called after versions were updated and before calling beforePr. The following arguments are passed: -v version --project-dir projectsRootDir and --pattern additionalPattern
696-
697-
--help prints this help
698-
--version prints the version of this script
699646
700-
INFO: Version of prepare-next-dev-cycle-template.sh is:
701-
v4.3.0-SNAPSHOT
702647
```
703648
704649
</releasing-prepare-next-dev-cycle-template-help>
@@ -765,15 +710,7 @@ Help:
765710
766711
<!-- auto-generated, do not modify here but in src/releasing/pre-release-checks-git.sh -->
767712
```text
768-
Parameters:
769-
-v The version to release in the format vX.Y.Z(-RC...)
770-
-b|--branch (optional) The expected branch which is currently checked out -- default: main
771713
772-
--help prints this help
773-
--version prints the version of this script
774-
775-
INFO: Version of pre-release-checks-git.sh is:
776-
v4.3.0-SNAPSHOT
777714
```
778715
779716
</releasing-pre-release-checks-git-help>
@@ -864,17 +801,7 @@ Help:
864801
865802
<!-- auto-generated, do not modify here but in src/releasing/update-version-common-steps.sh -->
866803
```text
867-
Parameters:
868-
--for-release true if update is for release in which case we hide the sneak-peek banner and toggle sections for release, if false then we show the sneak-peek banner and toggle the section for development
869-
-v The version to release in the format vX.Y.Z(-RC...)
870-
--project-dir (optional) The projects directory -- default: .
871-
-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}
872804
873-
--help prints this help
874-
--version prints the version of this script
875-
876-
INFO: Version of update-version-common-steps.sh is:
877-
v4.3.0-SNAPSHOT
878805
```
879806
880807
</releasing-update-version-common-steps-help>
@@ -942,27 +869,7 @@ Help:
942869
943870
<!-- auto-generated, do not modify here but in src/releasing/update-version-README.sh -->
944871
```text
945-
Parameters:
946-
-v The version to release in the format vX.Y.Z(-RC...)
947-
-f|--file (optional) the file where search & replace shall be done -- default: ./README.md
948-
-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}
949-
950-
--help prints this help
951-
--version prints the version of this script
952-
953-
Examples:
954-
# update version for ./README.md
955-
update-version-README.sh -v v0.1.0
956-
957-
# update version for ./docs/index.md
958-
update-version-README.sh -v v0.1.0 -f ./docs/index.md
959872
960-
# update version for ./README.md
961-
# also replace occurrences of the defined pattern
962-
update-version-README.sh -v v0.1.0 -p "(VERSION=['\"])[^'\"]+(['\"])"
963-
964-
INFO: Version of update-version-README.sh is:
965-
v4.3.0-SNAPSHOT
966873
```
967874
968875
</releasing-update-version-README-help>
@@ -1001,27 +908,7 @@ Help:
1001908
1002909
<!-- auto-generated, do not modify here but in src/releasing/update-version-scripts.sh -->
1003910
```text
1004-
Parameters:
1005-
-v The version to release in the format vX.Y.Z(-RC...)
1006-
-d|--directory (optional) the working directory in which *.sh are searched (also in subdirectories) / you can also specify a file -- default: ./src
1007-
-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}
1008-
1009-
--help prints this help
1010-
--version prints the version of this script
1011-
1012-
Examples:
1013-
# update version to v0.1.0 for all *.sh in ./src and subdirectories
1014-
update-version-scripts.sh -v v0.1.0
1015-
1016-
# update version to v0.1.0 for all *.sh in ./scripts and subdirectories
1017-
update-version-scripts.sh -v v0.1.0 -d ./scripts
1018911
1019-
# update version to v0.1.0 for all *.sh in ./src and subdirectories
1020-
# also replace occurrences of the defined pattern
1021-
update-version-scripts.sh -v v0.1.0 -p "(VERSION=['\"])[^'\"]+(['\"])"
1022-
1023-
INFO: Version of update-version-scripts.sh is:
1024-
v4.3.0-SNAPSHOT
1025912
```
1026913
1027914
</releasing-update-version-scripts-help>
@@ -1060,27 +947,7 @@ Help:
1060947
1061948
<!-- auto-generated, do not modify here but in src/releasing/update-version-issue-templates.sh -->
1062949
```text
1063-
Parameters:
1064-
-v The version to release in the format vX.Y.Z(-RC...)
1065-
-d|--directory (optional) the working directory in which *.y(a)ml are searched (also in subdirectories) / you can also specify a file -- default: ./.github/ISSUE_TEMPLATE
1066-
-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}
1067-
1068-
--help prints this help
1069-
--version prints the version of this script
1070950
1071-
Examples:
1072-
# update version to v0.1.0 for all *.y(a)ml in ./.github/ISSUE_TEMPLATE and subdirectories
1073-
update-version-issue-templates.sh -v v0.1.0
1074-
1075-
# update version to v0.1.0 for all *.y(a)ml in ./tpls and subdirectories
1076-
update-version-issue-templates.sh -v v0.1.0 -d ./tpls
1077-
1078-
# update version to v0.1.0 for all *.y(a)ml in ./.github/ISSUE_TEMPLATE and subdirectories
1079-
# also replace occurrences of the defined pattern
1080-
update-version-issue-templates.sh -v v0.1.0 -p "(VERSION=['\"])[^'\"]+(['\"])"
1081-
1082-
INFO: Version of update-version-issue-templates.sh is:
1083-
v4.3.0-SNAPSHOT
1084951
```
1085952
1086953
</releasing-update-version-issue-templates-help>
@@ -2003,9 +1870,7 @@ cat "$file"
20031870
20041871
</utility-replace-snippet>
20051872
2006-
## Source once
2007-
2008-
Establishes a guard by creating a variable based on the file which shall be sourced.
1873+
## Source utility functions
20091874
20101875
<utility-source-once>
20111876
@@ -2018,7 +1883,12 @@ shopt -s inherit_errexit
20181883
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../lib/tegonal-scripts/src"
20191884
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
20201885
2021-
source "$dir_of_tegonal_scripts/utility/source-once.sh"
1886+
# setup.sh already sources source-once.sh hence no need for the following (as usual):
1887+
# source "$dir_of_tegonal_scripts/utility/source-once.sh"
1888+
1889+
# more or less shortcut for `source ... || traceAndDie "..."
1890+
# will be used by sourceOnce and sourceAlways (although they don't contain ..OrDie in the name)
1891+
sourceOrdie "foo.sh"
20221892
20231893
sourceOnce "foo.sh" # creates a variable named sourceOnceGuard_foo__sh which acts as guard and sources foo.sh
20241894
sourceOnce "foo.sh" # will source nothing as sourceOnceGuard_foo__sh is already defined

scripts/prepare-next-dev-cycle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sourceOnce "$dir_of_tegonal_scripts/releasing/prepare-files-next-dev-cycle.sh"
3131
sourceOnce "$scriptsDir/before-pr.sh"
3232

3333
function prepareNextDevCycle() {
34-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
34+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
3535

3636
# shellcheck disable=SC2034 # they seem unused but are necessary in order that parseArguments doesn't create global readonly vars
3737
local version projectsRootDir additionalPattern beforePrFn

scripts/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function release() {
4343
die "You need to have shellspec installed if you want to create a release."
4444
fi
4545

46-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
46+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
4747

4848
local version
4949
# shellcheck disable=SC2034 # they seem unused but are necessary in order that parseArguments doesn't create global readonly vars

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ 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
49-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
48+
local versionParamPatternLong
49+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
5050

5151
local version branch
5252
# shellcheck disable=SC2034 # is passed by name to parseArguments

src/releasing/prepare-files-next-dev-cycle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ sourceOnce "$dir_of_tegonal_scripts/releasing/prepare-next-dev-cycle-template.sh
7373
function prepareFilesNextDevCycle() {
7474
local versionParamPatternLong projectsRootDirParamPatternLong
7575
local additionalPatternParamPatternLong beforePrFnParamPatternLong afterVersionUpdateHookParamPatternLong
76-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
76+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
7777

7878
local version afterVersionUpdateHook projectsRootDir additionalPattern beforePrFn afterVersionUpdateHook
7979
# shellcheck disable=SC2034 # is passed by name to parseArguments

src/releasing/prepare-next-dev-cycle-template.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ sourceOnce "$dir_of_tegonal_scripts/utility/parse-args.sh"
7373
sourceOnce "$dir_of_tegonal_scripts/releasing/update-version-common-steps.sh"
7474

7575
function prepareNextDevCycleTemplate() {
76-
local versionRegex versionParamPatternLong projectsRootDirParamPatternLong
76+
local versionParamPatternLong projectsRootDirParamPatternLong
7777
local additionalPatternParamPatternLong beforePrFnParamPatternLong afterVersionUpdateHookParamPatternLong
7878
local forReleaseParamPatternLong
79-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
79+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
8080

8181
local version projectsRootDir additionalPattern beforePrFn afterVersionUpdateHook
8282
# shellcheck disable=SC2034 # is passed by name to parseArguments

src/releasing/release-files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function releaseFiles() {
9292
local versionParamPatternLong projectsRootDirParamPatternLong
9393
local additionalPatternParamPatternLong afterVersionUpdateHookParamPatternLong releaseHookParamPatternLong
9494
local findForSigningParamPatternLong beforePrFnParamPatternLong prepareNextDevCycleFnParamPatternLong
95-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
95+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
9696

9797
local version key findForSigning branch projectsRootDir additionalPattern
9898
# shellcheck disable=SC2034 # seems unused but is set in deduce-next-version

src/releasing/release-template.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function releaseTemplate() {
9696
local additionalPatternParamPatternLong prepareOnlyParamPatternLong
9797
local beforePrFnParamPatternLong prepareNextDevCycleFnParamPatternLong afterVersionUpdateHookParamPatternLong
9898
local forReleaseParamPatternLong releaseHookParamPatternLong
99-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
99+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
100100

101101
local version releaseHook branch projectsRootDir additionalPattern nextVersion prepareOnly
102102
local beforePrFn prepareNextDevCycleFn afterVersionUpdateHook

src/releasing/update-version-README.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fi
4141
sourceOnce "$dir_of_tegonal_scripts/utility/parse-args.sh"
4242

4343
function updateVersionReadme() {
44-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
44+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
4545

4646
local version file additionalPattern
4747
# shellcheck disable=SC2034 # is passed by name to parseArguments

src/releasing/update-version-common-steps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ sourceOnce "$dir_of_tegonal_scripts/releasing/update-version-scripts.sh"
7171

7272
function updateVersionCommonSteps() {
7373
local forReleaseParamPatternLong versionParamPatternLong additionalPatternParamPatternLong
74-
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
74+
sourceOrDie "$dir_of_tegonal_scripts/releasing/common-constants.source.sh"
7575

7676
local forRelease version projectsRootDir additionalPattern
7777
# shellcheck disable=SC2034 # is passed by name to parseArguments

0 commit comments

Comments
 (0)