forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (67 loc) · 2.12 KB
/
CheckScripts.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
name: CheckScripts
# spell-checker:ignore ludeeus mfinelli
env:
SCRIPT_DIR: 'util'
on:
push:
branches:
- main
paths:
- 'util/**/*.sh'
pull_request:
branches:
- main
paths:
- 'util/**/*.sh'
# End the current execution if there is a new changeset in the PR.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
shell_check:
name: ShellScript/Check
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -s bash
with:
severity: warning
scandir: ${{ env.SCRIPT_DIR }}
format: tty
shell_fmt:
name: ShellScript/Format
# no need to run in pr events
# shfmt will be performed on main branch when the PR is merged
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [ shell_check ]
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup shfmt
uses: mfinelli/setup-shfmt@v3
- name: Run shfmt
shell: bash
run: |
# show differs first for every files that need to be formatted
# fmt options: bash syntax, 4 spaces indent, indent for switch-case
echo "## show the differences between formatted and original scripts..."
find ${{ env.SCRIPT_DIR }} -name "*.sh" -print0 | xargs -0 shfmt -ln=bash -i 4 -ci -d || true
# perform a shell format
echo "## perform a shell format..."
# ignore the error code because `-d` will always return false when the file has difference
find ${{ env.SCRIPT_DIR }} -name "*.sh" -print0 | xargs -0 shfmt -ln=bash -i 4 -ci -w
- name: Commit any changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "style: auto format by CI (shfmt)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}