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
# https://github.com/marketplace/actions/shellcheck
name: Check shell scripts
on:
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- synchronize
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# Detect what files changed
changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
scripts: ${{ steps.filter.outputs.scripts }}
code: ${{ steps.filter.outputs.code }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
scripts:
- '**.sh'
- '**.bash'
code:
- '**/*.rs'
- '**/*.toml'
- '**/*.lock'
- '**/*.sh'
- '**/*.bash'
- '**/*.yaml'
- '**/*.yml'
- '**/*.json'
# Always check for scripts without .sh extension (catches bad additions)
extension-check:
name: Check .sh extension
needs: changes
if: ${{ needs.changes.outputs.code == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Check shell scripts have .sh extension
run: |
# Find files with shell shebang but without .sh extension
bad_scripts=$(find . -type f \
! -path './.git/*' \
! -path './vendor/*' \
! -path './target/*' \
! -name '*.sh' \
! -name '*.bash' \
-exec sh -c 'head -1 "$1" 2>/dev/null | grep -qE "^#!.*(bash|sh)" && echo "$1"' _ {} \;)
if [ -n "$bad_scripts" ]; then
echo "::error::Shell scripts must have .sh or .bash extension:"
echo "$bad_scripts"
exit 1
fi
echo "All shell scripts have correct extensions"
shellcheck:
needs: changes
if: ${{ needs.changes.outputs.scripts == 'true' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@00b27aa7cb85167568cb48a3838b75f4265f2bca # master (2024-06-20)
with:
ignore_paths: "**/vendor/**"