Skip to content

Commit 309a659

Browse files
committed
ci: check kata integrity
1 parent 68efd72 commit 309a659

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Integrity Check
2+
run-name: Rank '${{ inputs.rank }}' Integrity Check
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
rank:
8+
type: choice
9+
description: 'Kata category'
10+
default: 'beta'
11+
options:
12+
- 8-kyu
13+
- 7-kyu
14+
- 6-kyu
15+
- 5-kyu
16+
- 4-kyu
17+
- 3-kyu
18+
- 2-kyu
19+
- 1-kyu
20+
- beta
21+
- retired
22+
max_sleep:
23+
description: 'Max request interval (sec)'
24+
default: '10'
25+
verbose:
26+
description: 'Verbose mode'
27+
type: boolean
28+
default: 'false'
29+
30+
jobs:
31+
setup:
32+
runs-on: ubuntu-24.04
33+
timeout-minutes: 1
34+
outputs:
35+
kata_count: ${{ steps.init.outputs.kata_count }}
36+
fork_count: ${{ steps.init.outputs.fork_count }}
37+
sid: ${{ steps.init.outputs.sid }}
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
41+
42+
- name: Setup parallel forks
43+
id: init
44+
run: |
45+
kata_count=$(wc -l < "./kata/${{ github.event.inputs.rank }}/index.md")
46+
echo "kata_count=$kata_count" >> $GITHUB_OUTPUT
47+
fork_count=$((kata_count < 40 ? kata_count : 40))
48+
echo "fork_count=$fork_count" >> $GITHUB_OUTPUT
49+
echo "sid=[`seq -s , 0 $((fork_count - 1))`]" >> $GITHUB_OUTPUT
50+
51+
- uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
52+
with:
53+
name: index-file
54+
path: ./kata/${{ github.event.inputs.rank }}/index.md
55+
retention-days: 1
56+
57+
integrity-check:
58+
needs: setup
59+
runs-on: ubuntu-24.04
60+
timeout-minutes: 10
61+
strategy:
62+
matrix:
63+
fork_sid: ${{ fromJSON(needs.setup.outputs.sid) }}
64+
steps:
65+
- name: Download index file artifact
66+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
67+
with:
68+
name: index-file
69+
path: .
70+
71+
- name: Extract Kata IDs
72+
run: |
73+
kata_count=${{ needs.setup.outputs.kata_count }}
74+
fork_count=${{ needs.setup.outputs.fork_count }}
75+
kata_per_fork=$((kata_count / fork_count))
76+
remainder=$((kata_count % fork_count))
77+
78+
fork_id=${{ matrix.fork_sid }}
79+
batch_size=$((fork_id < remainder ? kata_per_fork + 1 : kata_per_fork))
80+
batch_offset=$((fork_id < remainder ? fork_id : remainder))
81+
start=$((fork_id * kata_per_fork + batch_offset + 1))
82+
end=$((start + batch_size - 1))
83+
sed -n "${start},${end}{=;p}" index.md | paste - - | sed -E 's/^([0-9]+)[ \t]+.* "([^"]+)"\).*/\1 \2/' > ids.txt
84+
85+
- name: Validate Kata rank
86+
run: |
87+
touch report_${{ matrix.fork_sid }}.txt
88+
while IFS=' ' read -r sid kata_id; do
89+
chunk=$(curl -s "https://www.codewars.com/kata/${kata_id}" | awk 'NR > 0 {print tolower(substr($0, 9650, 350))}')
90+
actual=$(echo "$chunk" | grep -oP '(?<=<span>).*?(?=</span>)' | sed 's/ /-/g')
91+
same=$([[ "${{ github.event.inputs.rank }}" == "$actual" || ("${{ github.event.inputs.rank }}" == "beta" && "$actual" == "draft") ]] && echo true || echo false)
92+
93+
if [[ "${{ github.event.inputs.verbose }}" == 'true' || "$same" == 'false' ]]; then
94+
progress="[$sid / ${{ needs.setup.outputs.kata_count }}]"
95+
status=$([[ "$same" == "true" ]] && echo "✅" || echo "⚠️")
96+
message="$status https://www.codewars.com/kata/$kata_id ($actual)"
97+
echo "$progress $message" | tee -a "report_${{ matrix.fork_sid }}.txt"
98+
fi
99+
sleep $((RANDOM % ${{ github.event.inputs.max_sleep }} + 1))
100+
done < ids.txt
101+
102+
- name: Upload status report
103+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
104+
with:
105+
name: report_${{ matrix.fork_sid }}
106+
path: report_${{ matrix.fork_sid }}.txt
107+
retention-days: 1
108+
109+
report:
110+
needs: [integrity-check]
111+
runs-on: ubuntu-24.04
112+
steps:
113+
- name: Merge status reports
114+
uses: actions/upload-artifact/merge@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
115+
with:
116+
name: report-group
117+
pattern: report_*
118+
delete-merged: true
119+
120+
- name: Download all status reports
121+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
122+
with:
123+
name: report-group
124+
path: .
125+
126+
- name: Status report summary
127+
run: |
128+
find . -type f | xargs cat | sort -t'/' -k1.2n >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)