Skip to content

Commit e51af72

Browse files
committed
🐛 FIX: #100 lint-starter-scripts has no success message
1 parent 8ddb1cd commit e51af72

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

.gp/bash/.bash_aliases

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This file is sourced into ~/.bashrc
44
# Add any alias you would like here
55

6-
alias lint-starter-scripts='find "$GITPOD_REPO_ROOT/.gp" -type d \( -name node_modules \) -prune -false -o -name "*.sh" -exec shellcheck -x -P "$GITPOD_REPO_ROOT/.gp" {} \;'
6+
alias lint-starter-scripts='f(){ bash "$GITPOD_REPO_ROOT"/.gp/bash/lint-scripts.sh "$1"; unset -f f; }; f'
77
# Updates all passwords related to phpmyadmin from values set in .starter.env
88
# Requires .starter.env to have all phpmyadmin related keys set with values
99
# Empty string value will break the script

.gp/bash/lint-scripts.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
#
3+
# SPDX-License-Identifier: MIT
4+
# Copyright © 2021 Apolo Pena
5+
#
6+
# lint-scripts.sh
7+
# Description:
8+
# Finds all .sh files that the starter uses, runs them through shellcheck and
9+
# outputs a simple success summary or just the standard output if shellcheck
10+
# finds anything that needs attention.
11+
#
12+
# Note:
13+
# Pass in an optional -v or --verbose if you would like to output a list of the files being checked
14+
15+
path() {
16+
if [[ -z $GITPOD_REPO_ROOT ]]; then
17+
echo '.gp'
18+
else
19+
echo "$GITPOD_REPO_ROOT/.gp"
20+
fi
21+
}
22+
23+
list_all_scripts() {
24+
find "$(path)" -type d \( -name node_modules \) -prune -false -o -name "*.sh"
25+
}
26+
27+
script_total() {
28+
list_all_scripts | wc -l
29+
}
30+
31+
main() {
32+
local total result
33+
if [[ $1 == '-v' || $1 == '--verbose' ]]; then
34+
echo -e "\e[38;5;87mRunning all starter scripts through shellcheck\e[0m"
35+
echo -ne "\e[38;5;45m"
36+
list_all_scripts; echo -ne "\e[0m"
37+
fi
38+
total=$(script_total)
39+
result=$(find "$(path)" -type d \( -name node_modules \) -prune -false -o -name "*.sh" -exec shellcheck -x -P "$(path)" {} \; | tee >(wc -l))
40+
[[ $result == 0 ]] && echo -e "\e[38;5;76mSUCCESS:\e[0m \e[38;5;40mall \e[0;36m$total\e[0m \e[38;5;40mscripts in the system passed the shellcheck.\e[0m" && exit
41+
find "$(path)" -type d \( -name node_modules \) -prune -false -o -name "*.sh" -exec shellcheck -x -P "$(path)" {} \;
42+
}
43+
44+
main "$1"

0 commit comments

Comments
 (0)