Skip to content

Commit 45c8e67

Browse files
authored
Merge pull request #1258 from a-gave/ci_luacheck_shellchek
ci: add linting via luacheck and shellcheck
2 parents 3727a93 + 5b32913 commit 45c8e67

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/lint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
lua:
14+
name: Lua
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
- name: Install Dependencies
19+
run: sudo apt-get -y update && sudo apt-get -y install lua-check
20+
- name: Lint Lua code
21+
run: ./tools/ci/lint/lua.sh
22+
23+
sh:
24+
name: Shell
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v6
28+
- name: Install Dependencies
29+
run: sudo apt-get -y update && sudo apt-get -y install shellcheck
30+
- name: Lint shell code
31+
run: ./tools/ci/lint/sh.sh

tools/ci/lint/lua.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
local="$1"
6+
if [ "$local" != "" ] && { [ -f "$local" ] || [ -d "$local" ]; }; then
7+
luacheck "$local"
8+
return
9+
fi
10+
11+
luacheck packages tests tools

tools/ci/lint/sh.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
# from https://github.com/freifunk-gluon/gluon/blob/main/scripts/lint-sh.sh
3+
4+
set -e
5+
6+
is_scriptfile() {
7+
echo "$1" | grep -q '\.sh$' || head -n1 "$1" | grep -qE '^#!(.*\<bash|/bin/sh)$'
8+
}
9+
10+
is_initscript() {
11+
head -n1 "$1" | grep -qxF '#!/bin/sh /etc/rc.common'
12+
}
13+
14+
local="$1"
15+
if [ "$local" != "" ]; then
16+
if [ -d "./${local}" ]; then
17+
find "./${local}" -type f | while read -r file; do
18+
is_scriptfile "$file" || continue
19+
20+
echo "Checking $file"
21+
shellcheck -f gcc "$file"
22+
done
23+
elif [ -f "./${local}" ]; then
24+
echo "Checking $local"
25+
shellcheck -f gcc "$local"
26+
fi
27+
return
28+
fi
29+
30+
find tools -type f | while read -r file; do
31+
is_scriptfile "$file" || continue
32+
33+
echo "Checking $file"
34+
shellcheck -f gcc "$file"
35+
done
36+
37+
find packages -type f | while read -r file; do
38+
if is_scriptfile "$file"; then
39+
echo "Checking $file"
40+
shellcheck -f gcc -x -s sh -e SC2039,SC3043,SC3037,SC3057 "$file"
41+
elif is_initscript "$file"; then
42+
echo "Checking $file (initscript)"
43+
shellcheck -f gcc -x -s sh -e SC2034,SC2039,SC3043,SC3037,SC3057 "$file"
44+
fi
45+
done
46+
47+
shellcheck -f gcc -x run_tests

0 commit comments

Comments
 (0)