-
Notifications
You must be signed in to change notification settings - Fork 4
249 lines (218 loc) · 8.48 KB
/
Copy pathshell-validation.yml
File metadata and controls
249 lines (218 loc) · 8.48 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: Shell Script Validation
on:
push:
branches: [main, develop]
paths:
- "scripts/**/*.sh"
- "zsh/**/*.zsh"
- ".github/workflows/shell-validation.yml"
pull_request:
branches: [main, develop]
paths:
- "scripts/**/*.sh"
- "zsh/**/*.zsh"
jobs:
shellcheck:
runs-on: ubuntu-latest
name: ShellCheck Linting
permissions:
issues: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install ShellCheck
run: sudo apt-get update && sudo apt-get install -y shellcheck
- name: Run ShellCheck on shell scripts
id: shellcheck
run: |
shellcheck $(find scripts -type f -name "*.sh") 2>&1 || true
- name: Create issue on ShellCheck failure
if: failure() && github.event_name == 'push'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const { execSync } = require('child_process');
try {
const output = execSync('bash -c "shellcheck $(find scripts -type f -name \\"*.sh\\") 2>&1"').toString();
} catch (error) {
const output = error.stdout ? error.stdout.toString() : error.message;
const title = `[Shell Validation] ShellCheck Issues Found`;
const body = `## ShellCheck Validation Failure\n\n\`\`\`\n${output}\n\`\`\`\n\n**Workflow Run:** [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
// Check if issue already exists
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['shellcheck-issue']
});
if (issues.data.length === 0) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['shellcheck-issue', 'shell-validation']
});
} else {
// Update existing issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issues.data[0].number,
body: body
});
}
}
bash-syntax-check:
runs-on: ubuntu-latest
name: Bash Syntax Validation
permissions:
issues: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check bash syntax
id: bash-syntax
run: |
echo "Checking bash syntax for .sh files..."
failed_files=""
for script in $(find scripts -type f -name "*.sh"); do
if ! bash -n "$script" 2>&1; then
failed_files="$failed_files$script\n"
fi
done
if [ -n "$failed_files" ]; then
echo "FAILED_FILES<<EOF" >> $GITHUB_OUTPUT
echo -e "$failed_files" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
exit 1
fi
echo "All bash scripts passed syntax validation!"
- name: Create issue on bash syntax check failure
if: failure() && github.event_name == 'push'
uses: actions/github-script@v7
with:
script: |
const failedFiles = `${{ steps.bash-syntax.outputs.FAILED_FILES }}`;
const title = `[Shell Validation] Bash Syntax Error`;
const body = `## Bash Syntax Validation Failure\n\n**Failed Files:**\n${failedFiles}\n\nPlease fix the syntax errors in the files listed above.\n\n**Workflow Run:** [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
// Check if issue already exists
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['bash-syntax-error']
});
if (issues.data.length === 0) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['bash-syntax-error', 'shell-validation']
});
} else {
// Update existing issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issues.data[0].number,
body: body
});
}
zsh-syntax-check:
runs-on: ubuntu-latest
name: Zsh Syntax Validation
permissions:
issues: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Zsh
run: sudo apt-get update && sudo apt-get install -y zsh
- name: Check zsh syntax
id: zsh-syntax
run: |
echo "Checking zsh syntax for .zsh files..."
failed_files=""
for script in $(find zsh -type f -name "*.zsh"); do
if ! zsh -n "$script" 2>&1; then
failed_files="$failed_files$script\n"
fi
done
if [ -n "$failed_files" ]; then
echo "FAILED_FILES<<EOF" >> $GITHUB_OUTPUT
echo -e "$failed_files" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
exit 1
fi
echo "All zsh scripts passed syntax validation!"
- name: Create issue on zsh syntax check failure
if: failure() && github.event_name == 'push'
uses: actions/github-script@v7
with:
script: |
const failedFiles = `${{ steps.zsh-syntax.outputs.FAILED_FILES }}`;
const title = `[Shell Validation] Zsh Syntax Error`;
const body = `## Zsh Syntax Validation Failure\n\n**Failed Files:**\n${failedFiles}\n\nPlease fix the syntax errors in the files listed above.\n\n**Workflow Run:** [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
// Check if issue already exists
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['zsh-syntax-error']
});
if (issues.data.length === 0) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['zsh-syntax-error', 'shell-validation']
});
} else {
// Update existing issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issues.data[0].number,
body: body
});
}
close-issues:
runs-on: ubuntu-latest
name: Close Issues on Success
needs: [shellcheck, bash-syntax-check, zsh-syntax-check]
if: success() && github.event_name == 'push'
permissions:
issues: write
contents: read
steps:
- name: Close shell-validation issues
uses: actions/github-script@v7
with:
script: |
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['shell-validation']
});
for (const issue of issues.data) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: '✅ All shell scripts passed validation! Closing this issue.\n\n**Workflow Run:** [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})'
});
}