-
-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (85 loc) · 2.78 KB
/
shellcheck-markdown.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
name: Shellcheck code in Markdown
on: [push]
concurrency:
# cancel any in-progress job or run
# https://github.com/kdeldycke/workflows/commit/8bee3ba877
# https://docs.github.com/actions/using-jobs/using-concurrency
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Run shellcheck
run: |
# test shell syntax of Markdown code snippets
# https://github.com/dylanaraps/pure-sh-bible/commit/9d54e96011
set +o allexport
set -o noclobber
set -o noglob
set -o nounset
set -o verbose
trap 'printf "shellcheck complete\n"' EXIT INT
# Extract code blocks from the README.
while read -r line; do
test "${code-}" = '1' &&
test "${line-}" != '```' &&
printf '%s\n' "${line-}"
case "${line-}" in
'```sh' | '```bash' | '```zsh' | '```shell')
code='1'
;;
'```')
code=''
;;
*) ;;
esac
done < <(
# Markdown filename extensions
# https://github.com/github/linguist/blob/116d46aacc/lib/linguist/languages.yml#L3221-L3231
command find -- . \
-name '*.md' -o \
-name '*.markdown' -o \
-name '*.mdown' -o \
-name '*.mdwn' -o \
-name '*.mdx' -o \
-name '*.mkd' -o \
-name '*.mkdn' -o \
-name '*.mkdown' -o \
-name '*.ronn' -o \
-name '*.scd' -o \
-name '*.workbook'
) >'./codesnippets_code'
# Print the code blocks.
while read -r line; do
printf '%s\n' "${line-}"
done <'./codesnippets_code'
# Run shellcheck on the extracted code blocks
# and this test script itself.
# SC1071: allow shell directives outside sh, bash, ksh, dash
# SC1090: allow linking to a dynamic location
# SC1091: allow linking to, but not following, linked scripts
# SC2123: allow `PATH=...`
# SC2312: allow masking of return values
command shellcheck \
--exclude="SC1071,SC1090,SC1091,SC2123,SC2312" \
--wiki-link-count="$(command getconf UINT_MAX)" \
--check-sourced \
--enable=all \
--source-path=/dev/null \
--external-sources \
--include="" \
--shell=bash \
--severity=style \
--norc \
--color=always \
-- \
./codesnippets_code \
"$0" ||
exit 1
...