Skip to content

Commit fcfaf41

Browse files
committed
feat(gha): check github actions workflows and git hooks in check workflow
1 parent 7c75101 commit fcfaf41

File tree

1 file changed

+125
-5
lines changed

1 file changed

+125
-5
lines changed

.github/workflows/check.yml

Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414
workflow_call:
1515

1616
jobs:
17-
check:
18-
name: Check
17+
check-library:
18+
name: Check Library
1919

2020
runs-on: ubuntu-latest
2121
defaults:
@@ -26,10 +26,10 @@ jobs:
2626
- name: Checkout
2727
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2828

29-
- name: Setup pnpm
29+
- name: Set up pnpm
3030
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3.0.0
3131

32-
- name: Setup Node.js
32+
- name: Set up Node.js
3333
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3434
with:
3535
node-version: 20.17.0
@@ -40,5 +40,125 @@ jobs:
4040
pnpm install
4141
pnpm exec playwright install firefox --with-deps
4242
43-
- name: Run check
43+
- name: Check library files
4444
run: pnpm run check
45+
46+
check-others:
47+
name: Check Others
48+
49+
runs-on: ubuntu-latest
50+
defaults:
51+
run:
52+
shell: bash
53+
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
57+
with:
58+
fetch-depth: ${{ github.event_name == 'push' && '0' || '1' }}
59+
60+
- name: Get changed files
61+
id: changed-files
62+
if: github.event_name != 'workflow_dispatch'
63+
uses: tj-actions/changed-files@a284dc1814e3fd07f2e34267fc8f81227ed29fb8 # v45.0.9
64+
with:
65+
files_yaml: |
66+
actionlint:
67+
- .github/workflows/*.{yml,yaml}
68+
69+
shellcheck:
70+
- '**/*.{sh,bash,mksh,bats,zsh}'
71+
- .githooks/*
72+
73+
- name: Check GitHub Actions workflows
74+
if: |
75+
github.event_name == 'workflow_dispatch' ||
76+
steps.changed-files.outputs.actionlint_any_changed == 'true'
77+
env:
78+
# renovate: datasource=github-releases depName=rhysd/actionlint
79+
ACTIONLINT_VERSION: v1.7.7
80+
ACTIONLINT_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.actionlint_all_changed_files }}
81+
run: |
82+
IFS=$' \t\n'; set -ux
83+
84+
if [[ "${GITHUB_EVENT_NAME}" == 'workflow_dispatch' ]]; then
85+
# Get files using globs.
86+
shopt -s nullglob globstar
87+
files=(.github/workflows/*.{yml,yaml})
88+
shopt -u nullglob globstar
89+
90+
# Check if files were found.
91+
if [[ "${#files[@]}" -eq 0 ]]; then
92+
: "No files found"
93+
exit 1
94+
fi
95+
else
96+
# Get files using changed files output.
97+
files=()
98+
for file in ${ACTIONLINT_ALL_CHANGED_FILES}; do
99+
files+=("${file}")
100+
done
101+
fi
102+
: "Files to lint: ${files[*]}"
103+
104+
# Download, extract and setup actionlint.
105+
wget -q "https://github.com/rhysd/actionlint/releases/download/${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION#v}_linux_amd64.tar.gz" \
106+
-O actionlint.tar.gz
107+
tar -xzf actionlint.tar.gz
108+
chmod +x actionlint
109+
110+
# Download and setup problem matcher for actionlint.
111+
wget -q "https://raw.githubusercontent.com/rhysd/actionlint/${ACTIONLINT_VERSION}/.github/actionlint-matcher.json" \
112+
-O actionlint-problem-matcher.json
113+
echo "::add-matcher::actionlint-problem-matcher.json"
114+
115+
# Run actionlint.
116+
./actionlint -verbose -color "${files[@]}"
117+
118+
- name: Check shell scripts and git hooks
119+
if: |
120+
github.event_name == 'workflow_dispatch' ||
121+
steps.changed-files.outputs.shellcheck_any_changed == 'true'
122+
env:
123+
# renovate: datasource=github-releases depName=koalaman/shellcheck
124+
SHELLCHECK_VERSION: v0.10.0
125+
SHELLCHECK_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.shellcheck_all_changed_files }}
126+
# renovate: datasource=github-releases depName=lumaxis/shellcheck-problem-matchers
127+
SHELLCHECK_PROBLEM_MATCHERS_VERSION: v2.1.0
128+
run: |
129+
IFS=$' \t\n'; set -ux
130+
131+
if [[ "${GITHUB_EVENT_NAME}" == 'workflow_dispatch' ]]; then
132+
# Get files using globs.
133+
shopt -s nullglob globstar
134+
files=(**/*.{sh,bash,mksh,bats,zsh} .githooks/*)
135+
shopt -u nullglob globstar
136+
137+
# Check if files were found.
138+
if [[ "${#files[@]}" -eq 0 ]]; then
139+
: "No files found"
140+
exit 1
141+
fi
142+
else
143+
# Get files using changed files output.
144+
files=()
145+
for file in ${SHELLCHECK_ALL_CHANGED_FILES}; do
146+
files+=("${file}")
147+
done
148+
fi
149+
: "Files to lint: ${files[*]}"
150+
151+
# Download, extract and setup shellcheck.
152+
wget -q "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" \
153+
-O shellcheck.tar.xz
154+
tar -xf shellcheck.tar.xz
155+
mv "shellcheck-${SHELLCHECK_VERSION}/shellcheck" shellcheck
156+
chmod +x shellcheck
157+
158+
# Download and setup problem matcher for shellcheck.
159+
wget -q "https://raw.githubusercontent.com/lumaxis/shellcheck-problem-matchers/${SHELLCHECK_PROBLEM_MATCHERS_VERSION}/.github/shellcheck-gcc.json" \
160+
-O shellcheck-problem-matcher.json
161+
echo "::add-matcher::shellcheck-problem-matcher.json"
162+
163+
# Run shellcheck.
164+
./shellcheck --norc --enable=all --format=gcc --color=never "${files[@]}"

0 commit comments

Comments
 (0)