Skip to content

Commit 48235bb

Browse files
authored
Add language-specific linting and shellcheck to format.sh (#5689)
1 parent f87f4dd commit 48235bb

File tree

6 files changed

+65
-37
lines changed

6 files changed

+65
-37
lines changed

.github/workflows/lint.yml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ jobs:
1313
uses: ./.github/actions/install_runner
1414
- run: source venv/bin/activate
1515
shell: bash
16-
- name: Black, pylint, tailing whitespaces, and yaml checks
16+
- name: Install node
17+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
18+
with:
19+
node-version: 20
20+
- name: Black, pylint, tailing whitespaces, yaml, shellcheck, and language-specific checks
1721
shell: bash
1822
run: ./format.sh --check
1923
- if: ${{ failure() }}
@@ -24,25 +28,3 @@ jobs:
2428
exit 1
2529
2630
'
27-
- name: 'Install shellcheck'
28-
shell: bash
29-
run: sudo apt-get install -y shellcheck
30-
- name: 'Run shellcheck'
31-
shell: bash
32-
run: ./utils/scripts/shellcheck.sh
33-
- name: Install node
34-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
35-
with:
36-
node-version: 20
37-
- name: 'Run nodejs express lint'
38-
shell: bash
39-
working-directory: ./utils/build/docker/nodejs/express
40-
run: |
41-
npm install
42-
npm run lint
43-
- name: 'Run nodejs fastify lint'
44-
shell: bash
45-
working-directory: ./utils/build/docker/nodejs/fastify
46-
run: |
47-
npm install
48-
npm run lint

.shellcheck

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ TODO=(
3333
utils/interfaces/schemas/serve.sh
3434
build.sh
3535
format.sh
36+
*node_modules*
3637
)

format.sh

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ if ! mypy --config pyproject.toml; then
4444
exit 1
4545
fi
4646

47-
echo "Running ruff checks..."
48-
if ! which ruff > /dev/null; then
49-
echo "ruff is not installed, installing it (ETA 5s)"
50-
./build.sh -i runner > /dev/null
51-
fi
52-
5347
echo "Running ruff formatter..."
5448
if [ "$COMMAND" == "fix" ]; then
5549
ruff format
@@ -133,11 +127,6 @@ else
133127
fi
134128
135129
echo "Running yamllint checks..."
136-
if ! which ./venv/bin/yamllint > /dev/null; then
137-
echo "yamllint is not installed, installing it (ETA 60s)"
138-
./build.sh -i runner > /dev/null
139-
fi
140-
141130
if ! ./venv/bin/yamllint -s manifests/; then
142131
echo "yamllint checks failed. Please fix the errors above. 💥 💔 💥"
143132
exit 1
@@ -149,5 +138,29 @@ if ! python ./manifests/parser/core.py; then
149138
exit 1
150139
fi
151140
141+
echo "Running shellcheck checks..."
142+
if ! ./utils/scripts/shellcheck.sh; then
143+
echo "shellcheck checks failed. Please fix the errors above. 💥 💔 💥"
144+
exit 1
145+
fi
146+
147+
echo "Running language-specific linters..."
148+
# This will not run if npm is not installed as written and there is no "install" step today
149+
# TODO: Install node as part of this script
150+
if which npm > /dev/null; then
151+
echo "Running Node.js linters"
152+
153+
# currently only fastify requires linting
154+
# this can be added later
155+
nodejs_dirs=("express" "fastify")
156+
157+
for dir in "${nodejs_dirs[@]}"; do
158+
if ! NODE_NO_WARNINGS=1 npm --prefix ./utils/build/docker/nodejs/"$dir" install --silent && npm --prefix ./utils/build/docker/nodejs/"$dir" run --silent lint; then
159+
echo "$dir linter failed. Please fix the errors above. 💥 💔 💥"
160+
exit 1
161+
fi
162+
done
163+
fi
164+
152165
153166
echo "All good, the system-tests CI will be happy! ✨ 🍰 ✨"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ruff==0.8.1
3636
scp==0.14.5
3737
semantic-version==2.10.0
3838
setuptools==75.8.0
39+
shellcheck-py==0.11.0.1
3940
types-aiofiles==24.1.0.20241221
4041
types-protobuf==5.29.1.20241207
4142
types-python-dateutil==2.9.0.20241206

utils/build/docker/nodejs/express/package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/scripts/shellcheck.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function has() {
99
shift
1010

1111
local e
12-
for e; do [[ "${e}" == "${needle}" ]] && return 0; done
13-
12+
# shellcheck disable=SC2053 # explicitly allow glob matching
13+
for e in "$@"; do [[ $needle == $e ]] && return 0; done
1414
return 1
1515
}
1616

@@ -43,7 +43,7 @@ function lint() {
4343
files+=("$f")
4444
done < <( find utils -name '*.sh'; ls -1 -- *.sh )
4545

46-
shellcheck "${files[@]}"
46+
./venv/bin/shellcheck "${files[@]}"
4747
}
4848

4949
function root() {

0 commit comments

Comments
 (0)