Skip to content

Commit

Permalink
Merge pull request #191 from tegonal/feature/runShellCheckPullHooks
Browse files Browse the repository at this point in the history
runShellcheckPullHooks
  • Loading branch information
robstoll authored Aug 29, 2024
2 parents be6b6bd + 06e59e9 commit bc93756
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ body:
- ci/jelastic/deploy.sh
- ci/jelastic/utils.sh
- qa/run-shellcheck.sh
- qa/run-shellcheck-pull-hooks.sh
- releasing/common-constants.source.sh
- releasing/deduce-next-version.source.sh
- releasing/pre-release-checks-git.sh
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ The scripts are ordered by topic:
- [utils](#jelastic-utils)
- [Quality Assurance](#quality-assurance)
- [runShellcheck](#runshellcheck)
- [runShellcheckPullHooks](#runshellcheck-on-pull-hookssh)
- [Releasing](#releasing)
- [Releasing Files](#release-files)
- [Prepare Files Next Dev Cycle](#prepare-files-next-dev-cycle)
Expand Down Expand Up @@ -329,6 +330,32 @@ runShellcheck dirs "$sourcePath"
</qa-run-shellcheck>
## runShellCheck on pull-hooks.sh
If you are using [gt](https://github.com/tegonal/gt) then you most likely want to be sure that your pull-hook.sh files
don't contain shell issues, you can use the function `runShellCheckPullHooks` which analyses all pull-hook.sh files
in the remotes dir of gt using the $dir_of_tegonal_scripts as source path.
<qa-run-shellcheck-pull-hooks>
<!-- auto-generated, do not modify here but in src/qa/run-shellcheck-pull-hooks.sh.doc -->
```bash
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
# Assumes tegonal's scripts were fetched with gt - adjust location accordingly
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../lib/tegonal-scripts/src"
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
source "$dir_of_tegonal_scripts/qa/run-shellcheck-pull-hooks.sh"
# pass the working directory of gt which usually is .gt in the root of your repository
runShellcheckPullHooks ".gt"
```
</qa-run-shellcheck-pull-hooks>
# Releasing
The scripts under this topic (in directory `releasing`) perform some steps of your release process.
Expand Down
9 changes: 2 additions & 7 deletions scripts/run-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if ! [[ -v dir_of_tegonal_scripts ]]; then
dir_of_tegonal_scripts="$scriptsDir/../src"
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
fi
sourceOnce "$dir_of_tegonal_scripts/qa/run-shellcheck.sh"
sourceOnce "$dir_of_tegonal_scripts/qa/run-shellcheck-pull-hooks.sh"

function customRunShellcheck() {
# shellcheck disable=SC2034 # is passed by name to runShellcheck
Expand All @@ -33,12 +33,7 @@ function customRunShellcheck() {
local sourcePath="$dir_of_tegonal_scripts:$scriptsDir"
runShellcheck dirs "$sourcePath" -not -name "install-*.doc.sh"

local -r gh_commons_dir="$scriptsDir/../.gt/remotes/tegonal-gh-commons"
logInfo "analysing $gh_commons_dir/pull-hook.sh"

# shellcheck disable=SC2034 # is passed by name to runShellcheck
local -ra dirs2=("$gh_commons_dir")
runShellcheck dirs2 "$sourcePath" -name "pull-hook.sh"
runShellcheckPullHooks "$scriptsDir/../.gt"
}

${__SOURCED__:+return}
Expand Down
11 changes: 11 additions & 0 deletions src/qa/run-shellcheck-pull-hooks.doc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
# Assumes tegonal's scripts were fetched with gt - adjust location accordingly
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../lib/tegonal-scripts/src"
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"

source "$dir_of_tegonal_scripts/qa/run-shellcheck-pull-hooks.sh"

# pass the working directory of gt which usually is .gt in the root of your repository
runShellcheckPullHooks ".gt"
56 changes: 56 additions & 0 deletions src/qa/run-shellcheck-pull-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
#
# __ __
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft <[email protected]>
# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0
# /___/ Please report bugs and contribute back your improvements
#
# Version: v3.2.0-SNAPSHOT
####### Description #############
#
# function which analyses pull-hook.sh in the `remotes` directory of the given gt working directory.
# runs shellcheck on each file with predefined settings i.a. sets `-s bash`
#
####### Usage ###################
#
# #!/usr/bin/env bash
# set -euo pipefail
# shopt -s inherit_errexit
# # Assumes tegonal's scripts were fetched with gt - adjust location accordingly
# dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/../lib/tegonal-scripts/src"
# source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
#
# source "$dir_of_tegonal_scripts/qa/run-shellcheck-pull-hooks.sh"
#
# # pass the working directory of gt which usually is .gt in the root of your repository
# runShellcheckPullHooks ".gt"
#
###################################
set -euo pipefail
shopt -s inherit_errexit
unset CDPATH

if ! [[ -v dir_of_tegonal_scripts ]]; then
dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/.."
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
fi
sourceOnce "$dir_of_tegonal_scripts/qa/run-shellcheck.sh"

function runShellcheckPullHooks() {
if ! (($# == 1)); then
logError "Exactly one parameter needs to be passed to runShellcheckPullHooks, given \033[0;36m%s\033[0m\nFollowing a description of the parameters:" "$#"
echo >&2 '1: gt_dir working directory of gt'
printStackTrace
exit 9
fi
local -r gt_dir=$1

local -r gt_remote_dir="$gt_dir/remotes/"
logInfo "analysing $gt_remote_dir/**/pull-hook.sh"

# shellcheck disable=SC2034 # is passed by name to runShellcheck
local -ra dirs2=("$gt_remote_dir")
local sourcePath="$dir_of_tegonal_scripts"
runShellcheck dirs2 "$sourcePath" -name "pull-hook.sh"
}

0 comments on commit bc93756

Please sign in to comment.