Skip to content

Commit 2e0dd87

Browse files
committed
Add sh linter; improve Makefile(s)
1 parent 5028c50 commit 2e0dd87

23 files changed

Lines changed: 623 additions & 591 deletions

File tree

.github/workflows/pre-main.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Shell Format Check
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.sh'
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- '**/*.sh'
12+
13+
jobs:
14+
shfmt:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Install shfmt
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y shfmt
24+
25+
- name: Run shfmt check
26+
run: |
27+
find . -type f -name '*.sh' -print0 | xargs -0 shfmt -d -i 2

hack/install-markdownlint.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
cat /etc/redhat-release || echo "No /etc/redhat-release"
55

66
if grep -q 'Red Hat Enterprise Linux' /etc/redhat-release; then
7-
# install the config file for the RPM repository with node 14
8-
# steps taken from https://rpm.nodesource.com/setup_14.x
9-
yum module disable -y nodejs
10-
curl -sL -o '/tmp/nodesource.rpm' 'https://rpm.nodesource.com/pub_14.x/el/8/x86_64/nodesource-release-el8-1.noarch.rpm'
11-
rpm -i --nosignature --force /tmp/nodesource.rpm
12-
yum -y install nodejs
7+
# install the config file for the RPM repository with node 14
8+
# steps taken from https://rpm.nodesource.com/setup_14.x
9+
yum module disable -y nodejs
10+
curl -sL -o '/tmp/nodesource.rpm' 'https://rpm.nodesource.com/pub_14.x/el/8/x86_64/nodesource-release-el8-1.noarch.rpm'
11+
rpm -i --nosignature --force /tmp/nodesource.rpm
12+
yum -y install nodejs
1313
else
14-
# Fedora has a module we can use
15-
dnf -y module enable nodejs:16
16-
dnf -y install nodejs
14+
# Fedora has a module we can use
15+
dnf -y module enable nodejs:16
16+
dnf -y install nodejs
1717
fi
1818

1919
npm install -g markdownlint@v0.25.1 markdownlint-cli2@v0.4.0

hack/markdownlint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
trap 'handle_exit $?' EXIT
66

77
function handle_exit {
8-
# If the exit code we were given indicates an error, suggest that
9-
# the author run the linter locally.
10-
if [ "$1" != "0" ]; then
8+
# If the exit code we were given indicates an error, suggest that
9+
# the author run the linter locally.
10+
if [ "$1" != "0" ]; then
1111
cat - <<EOF
1212
To run the linter on a Linux system with podman, run "make markdownlint"
1313
after committing your changes locally.
1414
EOF
15-
fi
15+
fi
1616
}
1717

1818
markdownlint-cli2 '**/*.md' !'vendor/**/*.md'

telco-core/configuration/compare.sh

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ function compare_cr {
2525
local exclusionfile=$3
2626
local status=0
2727

28-
read_dir "$rendered_dir" |grep yaml > rendered_file
29-
read_dir "$source_dir" |grep yaml > source_file
28+
read_dir "$rendered_dir" | grep yaml >rendered_file
29+
read_dir "$source_dir" | grep yaml >source_file
3030

3131
local source_cr rendered
3232
while IFS= read -r source_cr; do
3333
while IFS= read -r rendered; do
3434
if [ "${source_cr##*/}" = "${rendered##*/}" ]; then
35-
echo "$source_cr" >> same_file
35+
echo "$source_cr" >>same_file
3636
fi
37-
done < rendered_file
38-
done < source_file
37+
done <rendered_file
38+
done <source_file
3939

4040
# Filter out files with a source-cr/reference match from the full list of potentiol source-crs/reference files
4141
while IFS= read -r file; do
4242
[[ ${file::1} != "#" ]] || continue # Skip any comment lines in the exclusionfile
43-
[[ -n ${file} ]] || continue # Skip empty lines
43+
[[ -n ${file} ]] || continue # Skip empty lines
4444
sed -i "/${file##*/}/d" source_file
4545
sed -i "/${file##*/}/d" rendered_file
4646
done < <(cat same_file "$exclusionfile")
@@ -55,103 +55,103 @@ function compare_cr {
5555
}
5656

5757
sync_cr() {
58-
local rendered_dir=$1
59-
local source_dir=$2
60-
local exclusionfile=$3
61-
local status=0
58+
local rendered_dir=$1
59+
local source_dir=$2
60+
local exclusionfile=$3
61+
local status=0
6262

63-
local -a renderedFiles
64-
readarray -t renderedFiles < <(read_dir "$rendered_dir" | grep yaml)
63+
local -a renderedFiles
64+
readarray -t renderedFiles < <(read_dir "$rendered_dir" | grep yaml)
6565

66-
local -a sourceFiles
67-
readarray -t sourceFiles < <(read_dir "$source_dir" | grep yaml)
66+
local -a sourceFiles
67+
readarray -t sourceFiles < <(read_dir "$source_dir" | grep yaml)
6868

69-
local -a excludedFiles
70-
readarray -t excludedFiles < <(grep -v '^#' "$exclusionfile" | grep -v '^$')
69+
local -a excludedFiles
70+
readarray -t excludedFiles < <(grep -v '^#' "$exclusionfile" | grep -v '^$')
7171

72-
local source rendered excluded found
73-
for rendered in "${renderedFiles[@]}"; do
74-
found=0
75-
for source in "${sourceFiles[@]}"; do
76-
if [ "${source##*/}" = "${rendered##*/}" ]; then
77-
# Match found!
78-
found=1
79-
break
80-
fi
81-
done
82-
if [[ $found == 0 ]]; then
83-
source="$source_dir/${rendered##*/}"
84-
fi
85-
86-
# Replace the CR with the rendered copy (minus the helm-rendered heading)
87-
tail -n +3 "$rendered" >"$source"
88-
git add "$source"
72+
local source rendered excluded found
73+
for rendered in "${renderedFiles[@]}"; do
74+
found=0
75+
for source in "${sourceFiles[@]}"; do
76+
if [ "${source##*/}" = "${rendered##*/}" ]; then
77+
# Match found!
78+
found=1
79+
break
80+
fi
8981
done
82+
if [[ $found == 0 ]]; then
83+
source="$source_dir/${rendered##*/}"
84+
fi
9085

91-
for source in "${sourceFiles[@]}"; do
92-
found=0
93-
for rendered in "${renderedFiles[@]}"; do
94-
if [ "${source##*/}" = "${rendered##*/}" ]; then
95-
# Match found!
96-
found=1
97-
break
98-
fi
99-
done
100-
for excluded in "${excludedFiles[@]}"; do
101-
if [ "${source##*/}" = "${excluded##*/}" ]; then
102-
# Match found!
103-
found=1
104-
break
105-
fi
106-
done
107-
if [[ $found == 0 ]]; then
108-
git rm -f "$source"
109-
fi
86+
# Replace the CR with the rendered copy (minus the helm-rendered heading)
87+
tail -n +3 "$rendered" >"$source"
88+
git add "$source"
89+
done
90+
91+
for source in "${sourceFiles[@]}"; do
92+
found=0
93+
for rendered in "${renderedFiles[@]}"; do
94+
if [ "${source##*/}" = "${rendered##*/}" ]; then
95+
# Match found!
96+
found=1
97+
break
98+
fi
11099
done
100+
for excluded in "${excludedFiles[@]}"; do
101+
if [ "${source##*/}" = "${excluded##*/}" ]; then
102+
# Match found!
103+
found=1
104+
break
105+
fi
106+
done
107+
if [[ $found == 0 ]]; then
108+
git rm -f "$source"
109+
fi
110+
done
111111

112-
git diff --cached --stat --exit-code
112+
git diff --cached --stat --exit-code
113113
}
114114

115115
usage() {
116-
echo "$(basename "$0") [--sync] sourceDir renderDir"
117-
echo
118-
echo "Compares the rendered reference-based CRs to the CRs in the compare directory"
116+
echo "$(basename "$0") [--sync] sourceDir renderDir"
117+
echo
118+
echo "Compares the rendered reference-based CRs to the CRs in the compare directory"
119119
}
120120

121121
DOSYNC=0
122122
for arg in "$@"; do
123-
case "$arg" in
124-
-h | --help)
125-
usage
126-
exit 0
127-
;;
128-
--sync)
129-
DOSYNC=1
130-
shift
131-
;;
132-
esac
123+
case "$arg" in
124+
-h | --help)
125+
usage
126+
exit 0
127+
;;
128+
--sync)
129+
DOSYNC=1
130+
shift
131+
;;
132+
esac
133133
done
134134
SOURCEDIR=$1
135135
if [[ ! -d $SOURCEDIR ]]; then
136-
echo "No such source directory $SOURCEDIR"
137-
usage
138-
exit 1
136+
echo "No such source directory $SOURCEDIR"
137+
usage
138+
exit 1
139139
fi
140140
RENDERDIR=$2
141141
if [[ ! -d $RENDERDIR ]]; then
142-
echo "No such source directory $RENDERDIR"
143-
usage
144-
exit 1
142+
echo "No such source directory $RENDERDIR"
143+
usage
144+
exit 1
145145
fi
146146
IGNORE=$3
147147
if [[ ! -f $IGNORE ]]; then
148-
echo "No such ignorefile $IGNORE"
149-
usage
150-
exit 1
148+
echo "No such ignorefile $IGNORE"
149+
usage
150+
exit 1
151151
fi
152152

153153
if [[ $DOSYNC == 1 ]]; then
154-
sync_cr "$RENDERDIR" "$SOURCEDIR" "$IGNORE"
154+
sync_cr "$RENDERDIR" "$SOURCEDIR" "$IGNORE"
155155
else
156-
compare_cr "$RENDERDIR" "$SOURCEDIR" "$IGNORE"
156+
compare_cr "$RENDERDIR" "$SOURCEDIR" "$IGNORE"
157157
fi

0 commit comments

Comments
 (0)