-
Notifications
You must be signed in to change notification settings - Fork 3
120 lines (101 loc) · 3.21 KB
/
guard-scripts.yml
File metadata and controls
120 lines (101 loc) · 3.21 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
name: Guard Scripts
on:
pull_request:
branches:
- develop
- version-1
push:
branches:
- develop
- version-1
workflow_dispatch:
permissions:
contents: read
concurrency:
group: guard-scripts-${{ github.ref }}
cancel-in-progress: true
jobs:
guard-scripts:
name: Check guard scripts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve runtime requirements
id: runtime
shell: bash
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
target_branch="${{ github.event.pull_request.base.ref }}"
else
target_branch="${{ github.ref_name }}"
fi
case "$target_branch" in
develop|version-1)
echo "python_version=3.14" >> "$GITHUB_OUTPUT"
;;
*)
echo "Unsupported target branch: $target_branch"
exit 1
;;
esac
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ steps.runtime.outputs.python_version }}
- name: Run guard scripts
shell: bash
run: |
set -uo pipefail
mapfile -t guard_scripts < <(find scripts -maxdepth 1 -type f -name 'check_*.py' | sort)
{
echo "## Guard Scripts Report"
echo
echo "| Script | Status |"
echo "| --- | --- |"
} >> "$GITHUB_STEP_SUMMARY"
if [ "${#guard_scripts[@]}" -eq 0 ]; then
echo "| _(none found)_ | n/a |" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
failed=0
details_file="$(mktemp)"
for script in "${guard_scripts[@]}"; do
echo "::group::${script}"
output_file="$(mktemp)"
if python "$script" >"$output_file" 2>&1; then
echo "PASS: ${script}"
echo "| \`${script}\` | PASS |" >> "$GITHUB_STEP_SUMMARY"
else
failed=$((failed + 1))
echo "FAIL: ${script}"
echo "| \`${script}\` | FAIL |" >> "$GITHUB_STEP_SUMMARY"
while IFS= read -r line; do
if [[ "$line" =~ ^([^:]+):([0-9]+):[[:space:]](.*)$ ]]; then
echo "::error file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]}::${BASH_REMATCH[3]}"
fi
done < "$output_file"
{
echo "<details>"
echo "<summary><code>${script}</code> output</summary>"
echo
echo '```text'
cat "$output_file"
echo '```'
echo "</details>"
echo
} >> "$details_file"
fi
cat "$output_file"
rm -f "$output_file"
echo "::endgroup::"
done
if [ "$failed" -gt 0 ]; then
echo >> "$GITHUB_STEP_SUMMARY"
echo "### Failure details" >> "$GITHUB_STEP_SUMMARY"
echo >> "$GITHUB_STEP_SUMMARY"
cat "$details_file" >> "$GITHUB_STEP_SUMMARY"
rm -f "$details_file"
exit 1
fi
rm -f "$details_file"