Skip to content

Commit 956f748

Browse files
committed
Add check for non-executable scripts to "Check Shell" workflow
Since Windows doesn't have the concept of an executable file mode, and shell scripts not considered executable by Linux, etc. will work fine if a shell is installed (e.g., Git Bash), shell scripts written or worked on by Windows developers may not be executable. For this reason, it is especially helpful for the CI to do a check on the file mode of the project's shell scripts, failing if they are not executable.
1 parent 02a83de commit 956f748

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Diff for: .github/workflows/check-shell-task.yml

+16
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,19 @@ jobs:
129129

130130
- name: Check formatting
131131
run: git diff --color --exit-code
132+
133+
executable:
134+
runs-on: ubuntu-latest
135+
136+
steps:
137+
- name: Checkout repository
138+
uses: actions/checkout@v2
139+
140+
- name: Install Task
141+
uses: arduino/setup-task@v1
142+
with:
143+
repo-token: ${{ secrets.GITHUB_TOKEN }}
144+
version: 3.x
145+
146+
- name: Check for non-executable scripts
147+
run: task --silent shell:check-mode

Diff for: Taskfile.yml

+30
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ tasks:
4646
- task: config:check
4747
- task: general:check-formatting
4848
- task: check-spelling
49+
- task: shell:check-mode
4950

5051
lint:
5152
desc: Lint all files
@@ -311,6 +312,35 @@ tasks:
311312
fi
312313
- shfmt -w .
313314

315+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-shell-task/Taskfile.yml
316+
shell:check-mode:
317+
desc: Check for non-executable shell scripts
318+
cmds:
319+
- |
320+
EXIT_STATUS=0
321+
while read -r nonExecutableScriptPath; do
322+
# The while loop always runs once, even if no file was found
323+
if [[ "$nonExecutableScriptPath" == "" ]]; then
324+
continue
325+
fi
326+
327+
echo "::error file=${nonExecutableScriptPath}::non-executable script file: $nonExecutableScriptPath";
328+
EXIT_STATUS=1
329+
done <<<"$(
330+
# The odd approach to escaping `.` in the regex is required for windows compatibility because mvdan.cc/sh
331+
# gives `\` characters special treatment on Windows in an attempt to support them as path separators.
332+
find . \
333+
-path ".git" -prune -or \
334+
\( \
335+
-regextype posix-extended \
336+
-regex '.*[.](bash|sh)' -and \
337+
-type f -and \
338+
-not -executable \
339+
-print \
340+
\)
341+
)"
342+
exit $EXIT_STATUS
343+
314344
config:check:
315345
desc: Lint and check formatting of configuration files
316346
cmds:

0 commit comments

Comments
 (0)