Skip to content

Commit

Permalink
Optional shellcheck and chart lint (#368)
Browse files Browse the repository at this point in the history
* Fix typo in pre-commit script shebang

Also add quotes in git hook setup script as
per shellcheck

* Add optional chart-lint and shellcheck

* Use warning for missing tools

* Add shell scripts in demo dir

* Appease shellcheck but ignore demo.sh

* fix inifinite loop with shellcheck
  • Loading branch information
KevinMGranger authored Feb 14, 2022
1 parent 37218c9 commit 4a11c5f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
33 changes: 31 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ ifeq ($(PYTHON_VER), False)
and <= $(PYTHON_VER_MAX))
endif

CHART_TEST=$(shell which ct)

SHELLCHECK=$(shell which shellcheck)
SHELL_SCRIPTS=./scripts/pre-commit ./scripts/setup-pre-commit-hook ./demo/demo-tekton


.PHONY: default
default: \
Expand Down Expand Up @@ -93,18 +98,42 @@ isort-check: $(PELORUS_VENV)

# Linting

.PHONY: lint pylava chart-lint
lint: pylava # TODO: not using chart-lint until we can automate installing it or at least conditionally run it
.PHONY: lint pylava chart-lint chart-lint-optional shellcheck shellcheck-optional
lint: pylava chart-lint-optional shellcheck-optional

pylava: $(PELORUS_VENV)
@echo 🐍 🌋 Linting with pylava
. ${PELORUS_VENV}/bin/activate && \
pylava

# chart-lint allows us to fail properly when run from CI,
# while chart-lint-optional allows graceful degrading when
# devs don't have it installed.

# shellcheck follows a similar pattern, but is not currently set up for CI.

chart-lint: $(PELORUS_VENV)
. ${PELORUS_VENV}/bin/activate && \
./scripts/chart-lint

ifneq (, $(CHART_TEST))
chart-lint-optional: chart-lint
else
chart-lint-optional:
$(warning chart test (ct) not installed, skipping)
endif

shellcheck:
@echo "🐚 📋 Linting shell scripts with shellcheck"
$(SHELLCHECK) $(SHELL_SCRIPTS)

ifneq (, $(SHELLCHECK))
shellcheck-optional: shellcheck
else
shellcheck-optional:
$(warning 🐚 ⏭ Shellcheck not found, skipping)
endif


# Cleanup

Expand Down
8 changes: 4 additions & 4 deletions demo/demo-tekton
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ done
if ! [[ $all_cmds_found ]]; then exit 1; fi


tekton_setup_dir="$(dirname $BASH_SOURCE)/tekton-demo-setup"
python_example_txt="$(dirname $BASH_SOURCE)/python-example/response.txt"
tekton_setup_dir="$(dirname "${BASH_SOURCE[0]}")/tekton-demo-setup"
python_example_txt="$(dirname "${BASH_SOURCE[0]}")/python-example/response.txt"

echo "Setting up resources:"

echo "1. Installing tekton operator"
oc apply -f "$tekton_setup_dir/01-tekton-operator.yaml"

echo "2. Setting up python tekton project"
if ! project_setup_output="$(oc apply -f $tekton_setup_dir/02-project.yaml 2>&1)"; then
if ! project_setup_output="$(oc apply -f "$tekton_setup_dir/02-project.yaml" 2>&1)"; then
if echo "$project_setup_output" | grep -q "AlreadyExists"; then
echo "Project already exists"
else
Expand Down Expand Up @@ -61,7 +61,7 @@ while true; do
echo "The pipeline and first run of the demo app has started. When it has finished, you may rerun (with commits) or quit now."
echo "1. Rerun with Commit"
echo "2. Quit"
read -p "Type 1 or 2: " -n 1 a
read -r -p "Type 1 or 2: " -n 1 a
echo ""
case $a in
1* )
Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/usr/bin/env bash
#!/usr/bin/env bash

failed=0

Expand Down
2 changes: 1 addition & 1 deletion scripts/setup-pre-commit-hook
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ desired_link_path=../../scripts/pre-commit
if [[ -h $target_hook_path ]]; then
link_path="$(readlink $target_hook_path)"

if [[ $link_path = $desired_link_path ]]; then
if [[ $link_path = "$desired_link_path" ]]; then
echo "pre-commit hook already set up"
else
echo "warning: pre-commit hook pointing to unknown location $link_path, should be $desired_link_path" >&2
Expand Down

0 comments on commit 4a11c5f

Please sign in to comment.