Skip to content

Commit e539207

Browse files
authored
Merge pull request #254 from tegonal/feature/deprecation
introduce logDeprecation with TEGONAL_SCRIPTS_ERROR_ON_DEPRECATION
2 parents 41b9795 + 166d613 commit e539207

File tree

12 files changed

+234
-18
lines changed

12 files changed

+234
-18
lines changed

.gt/remotes/tegonal-gh-commons/lib/src/gt/pull-hook-functions.sh renamed to .gt/lib/tegonal-gh-commons/src/gt/pull-hook-functions.sh

File renamed without changes.

.gt/remotes/tegonal-gh-commons/lib/src/gt/tegonal.data.source.sh renamed to .gt/lib/tegonal-gh-commons/src/gt/tegonal.data.source.sh

File renamed without changes.

.gt/remotes/tegonal-gh-commons/pull-hook.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ unset CDPATH
1414
TEGONAL_SCRIPTS_LATEST_VERSION="v4.5.1"
1515

1616
if ! [[ -v dir_of_github_commons ]]; then
17-
dir_of_github_commons="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/lib/src"
17+
dir_of_github_commons="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../../../lib/tegonal-gh-commons/src"
1818
readonly dir_of_github_commons
1919
fi
2020

@@ -23,7 +23,6 @@ if ! [[ -v dir_of_tegonal_scripts ]]; then
2323
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
2424
fi
2525

26-
2726
sourceOnce "$dir_of_github_commons/gt/pull-hook-functions.sh"
2827
sourceOnce "$dir_of_tegonal_scripts/utility/parse-fn-args.sh"
2928

.gt/remotes/tegonal-gh-commons/pulled.tsv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ v2.8.2 src/.github/workflows/cleanup.yml ../.github/workflows/cleanup.yml .* 705
44
v2.8.2 src/.github/dependabot.yml ../.github/dependabot.yml .* 9f631eac687bd929d16f1ac3569fe8ef48ed9263fa2fee11265c4fc27d3b5a9fab1a5c4d63438ccd394fe33ae09003dac4af0094c3ff4fd84f7d8b0aeaa4fbcf
55
v2.8.2 src/.github/CODE_OF_CONDUCT.md ../.github/CODE_OF_CONDUCT.md .* 5dc73021b3972b3200c12fb2754e335321d07c5f7372977368b9964252501b665ddd12bf267939d4a34dc7ee8d3040cef8f4abaf0aed6dd2ce23c865e0300383
66
v2.8.2 src/.github/PULL_REQUEST_TEMPLATE.md ../.github/PULL_REQUEST_TEMPLATE.md .* 9112d1ea1f72ea250cdfe686fc152e63f2e0cdcea9c46935289471d7a3f54c35af8a3f283570f5d863e936c7782939c7b1548cb7d4ccda712bbf9314926f58cb
7-
v2.8.2 src/gt/pull-hook-functions.sh remotes/tegonal-gh-commons/lib/src/gt/pull-hook-functions.sh .* 6190f8d9f1fa9295fc562b0a34d73fec0792753020ed2a19c9b8a3e855a2c453d642763e831eb47aeb20cdbb78ef2aeb7f8d11bf03aae6784843072f05433596
7+
v2.8.2 src/gt/pull-hook-functions.sh lib/tegonal-gh-commons/src/gt/pull-hook-functions.sh .* 6190f8d9f1fa9295fc562b0a34d73fec0792753020ed2a19c9b8a3e855a2c453d642763e831eb47aeb20cdbb78ef2aeb7f8d11bf03aae6784843072f05433596
88
v2.8.2 src/.github/Contributor Agreement.txt ../.github/Contributor Agreement.txt .* 0b9a8a954edf302ca5fe0062b7e283d3da06a6bc0631a812663095a78b3a734cefb43b725ae342694d770be75206124c42a1150e168fac33f28aebea0bda35ec
99
v2.8.2 src/gt/signing-key.public.asc signing-key.public.asc .* 36edec73464b610713fe8ba32b7c8c26d378d74d590883ba00ca3175efc4f1b753b60ae6aa03ddd1038642899c1394861e02038853734a43d4bf845762b91708
1010
v2.8.2 src/gt/signing-key.public.asc.actual_sig signing-key.public.asc.actual_sig .* 50eacd712448066974382e7e05ac4fe42e9026dafd0d963c763b7e402d31a9ceb1d012897b2bc7e69d37d670148d57647d563870e5ca2832d8cdde91c92f55db
1111
v2.8.2 src/dotfiles/.editorconfig ../.editorconfig .* ab20f56af1aa48e8be29e3b43fba449b1401d17ca5aab0b7b4f0ce65621ede33ff3c68144d350cb3a820c4a573218d0af5ecab9458c19701427f9d1c5d15211c
1212
v2.8.2 src/dotfiles/.shellcheckrc ../.shellcheckrc .* 2284b5a0f7d94916bf881b4e1f1ba3cbeb92ad51442b56dd6049bbcf9f4d7da4de3e82c1ae75a70e281cb2fbf390eb7676cbe553a630a1a58cd7895cfd2be2f6
13-
v2.8.2 src/gt/tegonal.data.source.sh remotes/tegonal-gh-commons/lib/src/gt/tegonal.data.source.sh .* 2c6600541c12c35c9a7a202cec91de5b2f01d4a3cb067fa57fb0c21ebb15be2cbe191967fa209bd69a8100c77e6e6df08031824ff43e6d0f81a95476ce6619c8
13+
v2.8.2 src/gt/tegonal.data.source.sh lib/tegonal-gh-commons/src/gt/tegonal.data.source.sh .* 2c6600541c12c35c9a7a202cec91de5b2f01d4a3cb067fa57fb0c21ebb15be2cbe191967fa209bd69a8100c77e6e6df08031824ff43e6d0f81a95476ce6619c8
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env bash
2+
#
3+
# __ __
4+
# / /____ ___ ____ ___ ___ _/ / This file is provided to you by https://github.com/tegonal/github-commons
5+
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <info@tegonal.com>
6+
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Creative Commons Zero v1.0 Universal
7+
# /___/ Please report bugs and contribute back your improvements
8+
#
9+
# Version: v2.8.2
10+
####### Description #############
11+
#
12+
# functions which can be used to update the placeholders in the templates in a gt pull-hook.sh
13+
#
14+
####### Usage ###################
15+
#
16+
# #!/usr/bin/env bash
17+
# set -euo pipefail
18+
# shopt -s inherit_errexit
19+
# MY_PROJECT_LATEST_VERSION="v1.0.0"
20+
#
21+
# # Assumes tegonal's github-commons was fetched with gt and put into repoRoot/lib/tegonal-gh-commons/src
22+
# dir_of_github_commons="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../../../lib/tegonal-gh-commons/src"
23+
#
24+
# if ! [[ -v dir_of_tegonal_scripts ]]; then
25+
# dir_of_tegonal_scripts="$dir_of_github_commons/../../tegonal-scripts/src"
26+
# source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
27+
# fi
28+
#
29+
# source "$dir_of_github_commons/gt/pull-hook-functions.sh"
30+
#
31+
# declare _tag=$1 source=$2 _target=$3
32+
# shift 3 || die "could not shift by 3"
33+
#
34+
# # replaces placeholders in all files github-commons provides with placeholders
35+
# replaceTegonalGhCommonsPlaceholders "$source" "my-project-name" "$MY_PROJECT_LATEST_VERSION" \
36+
# "MyCompanyName, Country" "code-of-conduct@my-company.com" "my-companies-github-name" "my-project-github-name"
37+
#
38+
###################################
39+
set -euo pipefail
40+
shopt -s inherit_errexit
41+
unset CDPATH
42+
43+
if ! [[ -v dir_of_github_commons ]]; then
44+
dir_of_github_commons="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/.."
45+
readonly dir_of_github_commons
46+
fi
47+
48+
if ! [[ -v dir_of_tegonal_scripts ]]; then
49+
dir_of_tegonal_scripts="$dir_of_github_commons/../tegonal-scripts/src"
50+
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
51+
fi
52+
53+
sourceOnce "$dir_of_tegonal_scripts/utility/parse-fn-args.sh"
54+
55+
function replaceTegonalGhCommonsPlaceholders() {
56+
local source projectName version owner ownerEmail ownerGithub projectNameGithub
57+
# shellcheck disable=SC2034 # is passed to parseFnArgs by name
58+
local -ra params=(source projectName version owner ownerEmail ownerGithub projectNameGithub)
59+
parseFnArgs params "$@"
60+
61+
if [[ $source =~ .*/\.github/CODE_OF_CONDUCT.md ]]; then
62+
replacePlaceholdersCodeOfConduct "$source" "$ownerEmail"
63+
elif [[ $source =~ .*/\.github/Contributor[[:space:]]Agreement\.txt ]]; then
64+
replacePlaceholdersContributorsAgreement "$source" "$projectName" "$projectNameGithub" "$owner" "$ownerGithub"
65+
elif [[ $source =~ .*/\.github/PULL_REQUEST_TEMPLATE.md ]]; then
66+
local -r githubUrl="https://github.com/$ownerGithub/$projectNameGithub"
67+
replacePlaceholdersPullRequestTemplate "$source" "$githubUrl" "$version"
68+
fi
69+
}
70+
71+
function replaceTegonalGhCommonsPlaceholders_Tegonal() {
72+
local source projectName version projectNameGithub
73+
# shellcheck disable=SC2034 # is passed to parseFnArgs by name
74+
local -ra params=(source projectName version projectNameGithub)
75+
parseFnArgs params "$@"
76+
77+
local tegonalFullName tegonalEmail tegonalGithubName
78+
source "$dir_of_github_commons/gt/tegonal.data.source.sh" || die "could not source tegonal.data.source.sh"
79+
80+
replaceTegonalGhCommonsPlaceholders "$source" "$projectName" "$version" "$tegonalFullName" "$tegonalEmail" "$tegonalGithubName" "$projectNameGithub"
81+
}
82+
83+
function replacePlaceholdersContributorsAgreement() {
84+
if ! (($# == 5)); then
85+
logError "you need to pass 5 arguments to replacePlaceholdersContributorsAgreement"
86+
echo "1: file represents the 'Contributor Agreement.txt'"
87+
echo "2: projectName the name of the project"
88+
echo "3: projectNameGithub the name of the project on GitHub"
89+
echo "4: owner the owner of the project"
90+
echo "5: ownerGithub the name of the organisation/owner on GitHub"
91+
printStackTrace
92+
exit 9
93+
fi
94+
local -r file=$1
95+
local -r projectName=$2
96+
local -r projectNameGithub=$3
97+
local -r owner=$4
98+
local -r ownerGithub=$5
99+
shift 5 || die "could not shift by 5"
100+
PROJECT_NAME="$projectName" \
101+
PROJECT_NAME_GITHUB="$projectNameGithub" \
102+
OWNER="$owner" \
103+
OWNER_GITHUB="$ownerGithub" \
104+
perl -0777 -i \
105+
-pe 's/<PROJECT_NAME>/$ENV{PROJECT_NAME}/g;' \
106+
-pe 's/<PROJECT_NAME_GITHUB>/$ENV{PROJECT_NAME_GITHUB}/g;' \
107+
-pe 's/<OWNER>/$ENV{OWNER}/g;' \
108+
-pe 's/<OWNER_GITHUB>/$ENV{OWNER_GITHUB}/g;' \
109+
"$file"
110+
}
111+
112+
function replacePlaceholdersPullRequestTemplate() {
113+
if ! (($# == 3)); then
114+
logError "you need to pass three arguments to replacePlaceholdersPullRequestTemplate"
115+
echo "1: file represents the 'PULL_REQUEST_TEMPLATE.md'"
116+
echo "2: url the github url"
117+
echo "3: latestTag latest tag"
118+
printStackTrace
119+
exit 9
120+
fi
121+
local -r file=$1
122+
local -r url=$2
123+
local -r tag=$3
124+
shift 3 || die "could not shift by 3"
125+
TAG="$tag" GITHUB_URL="$url" perl -0777 -i \
126+
-pe 's#<GITHUB_URL>#$ENV{GITHUB_URL}#g;' \
127+
-pe 's#<TAG>#$ENV{TAG}#g;' \
128+
"$file"
129+
}
130+
131+
function replacePlaceholdersCodeOfConduct() {
132+
if ! (($# == 2)); then
133+
logError "you need to pass two arguments to replacePlaceholdersCodeOfConductTemplate"
134+
echo "1: file represents the 'CODE_OF_CONDUCT.md'"
135+
echo "2: owner_email email address which should be contacted in case of a violation"
136+
printStackTrace
137+
exit 9
138+
fi
139+
local -r file=$1
140+
local -r ownerEmail=$2
141+
shift 2 || die "could not shift by 2"
142+
EMAIL="$ownerEmail" perl -0777 -i \
143+
-pe 's/<OWNER_EMAIL>/$ENV{EMAIL}/g;' \
144+
"$file"
145+
}
146+
147+
function replaceTagInPullRequestTemplate() {
148+
if ! (($# == 3)); then
149+
logError "you need to pass three arguments to replaceTagInPullRequestTemplate"
150+
echo "1: file represents the 'PULL_REQUEST_TEMPLATE.md'"
151+
echo "2: url the github url"
152+
echo "3: tag tag to set in url"
153+
printStackTrace
154+
exit 9
155+
fi
156+
local -r file=$1
157+
local -r url=$2
158+
local -r tag=$3
159+
shift 3 || die "could not shift by 3"
160+
161+
perl -0777 -i \
162+
-pe "s#($url/blob/)[^/]+/#\${1}$tag/#;" \
163+
"$file"
164+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034,SC2168,SC2154
3+
#
4+
# __ __
5+
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/github-commons
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+
#
10+
# Version: v2.8.2
11+
####### Description #############
12+
#
13+
# constants intended to be sourced into a function.
14+
#
15+
###################################
16+
17+
local -r tegonalFullName="Tegonal Genossenschaft, Switzerland"
18+
local -r tegonalEmail="info@tegonal.com"
19+
local -r tegonalGithubName="tegonal"

scripts/run-shellcheck.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if ! [[ -v dir_of_tegonal_scripts ]]; then
2121
dir_of_tegonal_scripts="$scriptsDir/../src"
2222
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
2323
fi
24-
sourceOnce "$dir_of_tegonal_scripts/qa/run-shellcheck-pull-hooks.sh"
24+
sourceOnce "$dir_of_tegonal_scripts/qa/run-shellcheck.sh"
2525

2626
function customRunShellcheck() {
2727
# shellcheck disable=SC2034 # is passed by name to runShellcheck

src/qa/run-shellcheck-pull-hooks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sourceOnce "$dir_of_tegonal_scripts/qa/run-shellcheck.sh"
3939

4040
#TODO remove file, runShellcheckPullHooks is no also in run-shellcheck.sh
4141
function runShellcheckPullHooks() {
42-
logWarning "please source run-shellcheck.sh instead of run-shellcheck-pull-hooks.sh -- run-shellcheck-pull-hooks.sh will be removed with v5.0.0"
42+
logDeprecation "runShellcheckPullHooks" "please source run-shellcheck.sh instead of run-shellcheck-pull-hooks.sh -- run-shellcheck-pull-hooks.sh will be removed with v5.0.0"
4343

4444
if (($# != 1)); then
4545
logError "Exactly one parameter needs to be passed to runShellcheckPullHooks, given \033[0;36m%s\033[0m\nFollowing a description of the parameters:" "$#"

src/setup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ set -euo pipefail
3131
shopt -s inherit_errexit
3232
unset CDPATH
3333

34+
# shellcheck disable=SC2034 # global var used in log.sh
35+
declare -A TEGONAL_SCRIPTS_SUPPRESSED_DEPRECATION=()
36+
# shellcheck disable=SC2034 # global var used in log.sh
37+
declare TEGONAL_SCRIPTS_ERROR_ON_DEPRECATION=true
38+
3439
#TODO 5.0.0 rename file to setup_tegonal_scripts.sh -- this way consumers will not run into shellcheck issues when they name a file setup.sh as well
3540

3641
if (($# != 1)); then

src/utility/io.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ fi
5151
sourceOnce "$dir_of_tegonal_scripts/utility/checks.sh"
5252

5353
function withCustomOutputInput() {
54-
if (($# < 3)); then
55-
logError "At least three arguments need to be passed to withCustomOutputInput, given \033[0;36m%s\033[0m\nFollowing a description of the parameters:" "$#"
56-
echo >&2 ' 1: outputNr the file descriptor number for the output (i.e. in which you want to write)'
57-
echo >&2 ' 2: inputNr the file descriptor number for the input (i.e. from which you want to read)'
58-
echo >&2 ' 3: callback the name of the callback function which shall be called'
59-
echo >&2 '...: vararg arguments which are passed to the callback function'
60-
61-
printStackTrace
62-
exit 9
63-
fi
54+
if (($# < 3)); then
55+
logError "At least three arguments need to be passed to withCustomOutputInput, given \033[0;36m%s\033[0m\nFollowing a description of the parameters:" "$#"
56+
echo >&2 ' 1: outputNr the file descriptor number for the output (i.e. in which you want to write)'
57+
echo >&2 ' 2: inputNr the file descriptor number for the input (i.e. from which you want to read)'
58+
echo >&2 ' 3: callback the name of the callback function which shall be called'
59+
echo >&2 '...: vararg arguments which are passed to the callback function'
60+
printStackTrace
61+
exit 9
62+
fi
6463
# prefix variables as the callback function might use variables from an outer scope and we would shadow those
6564
local withCustomOutputInput_outputNr=$1
6665
local withCustomOutputInput_inputNr=$2

0 commit comments

Comments
 (0)