-
-
Notifications
You must be signed in to change notification settings - Fork 16
130 lines (117 loc) Β· 4.53 KB
/
integrity-check.yml
File metadata and controls
130 lines (117 loc) Β· 4.53 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
name: Integrity Check
run-name: Rank '${{ inputs.rank }}' Integrity Check
on:
workflow_dispatch:
inputs:
rank:
type: choice
description: 'Kata category'
default: 'beta'
options:
- 8-kyu
- 7-kyu
- 6-kyu
- 5-kyu
- 4-kyu
- 3-kyu
- 2-kyu
- 1-kyu
- beta
- retired
max_sleep:
description: 'Max request interval (sec)'
default: '10'
verbose:
description: 'Verbose mode'
type: boolean
default: 'false'
jobs:
setup:
runs-on: ubuntu-24.04
timeout-minutes: 1
outputs:
kata_count: ${{ steps.init.outputs.kata_count }}
fork_count: ${{ steps.init.outputs.fork_count }}
sid: ${{ steps.init.outputs.sid }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup parallel forks
id: init
run: |
kata_count=$(wc -l < "./kata/${{ github.event.inputs.rank }}/index.md")
echo "kata_count=$kata_count" >> $GITHUB_OUTPUT
fork_count=$((kata_count < 40 ? kata_count : 40))
echo "fork_count=$fork_count" >> $GITHUB_OUTPUT
echo "sid=[`seq -s , 0 $((fork_count - 1))`]" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
env:
KATA_RANK: ${{ github.event.inputs.rank }}
with:
name: index-file
path: "./kata/$KATA_RANK/index.md"
retention-days: 1
integrity-check:
needs: setup
runs-on: ubuntu-24.04
timeout-minutes: 10
strategy:
matrix:
fork_sid: ${{ fromJSON(needs.setup.outputs.sid) }}
steps:
- name: Download index file artifact
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: index-file
path: .
- name: Extract Kata IDs
run: |
kata_count=${{ needs.setup.outputs.kata_count }}
fork_count=${{ needs.setup.outputs.fork_count }}
kata_per_fork=$((kata_count / fork_count))
remainder=$((kata_count % fork_count))
fork_id=${{ matrix.fork_sid }}
batch_size=$((fork_id < remainder ? kata_per_fork + 1 : kata_per_fork))
batch_offset=$((fork_id < remainder ? fork_id : remainder))
start=$((fork_id * kata_per_fork + batch_offset + 1))
end=$((start + batch_size - 1))
sed -n "${start},${end}{=;p}" index.md | paste - - | sed -E 's/^([0-9]+)[ \t]+.* "([^"]+)"\).*/\1 \2/' > ids.txt
- name: Validate Kata rank
run: |
touch report_${{ matrix.fork_sid }}.txt
while IFS=' ' read -r sid kata_id; do
chunk=$(curl -s "https://www.codewars.com/kata/${kata_id}" | awk 'NR > 0 {print tolower(substr($0, 9650, 350))}')
actual=$(echo "$chunk" | grep -oP '(?<=<span>).*?(?=</span>)' | sed 's/ /-/g')
same=$([[ "${{ github.event.inputs.rank }}" == "$actual" || ("${{ github.event.inputs.rank }}" == "beta" && "$actual" == "draft") ]] && echo true || echo false)
if [[ "${{ github.event.inputs.verbose }}" == 'true' || "$same" == 'false' ]]; then
progress="[$sid / ${{ needs.setup.outputs.kata_count }}]"
status=$([[ "$same" == "true" ]] && echo "β
" || echo "β οΈ")
message="$status https://www.codewars.com/kata/$kata_id ($actual)"
echo "$progress $message" | tee -a "report_${{ matrix.fork_sid }}.txt"
fi
sleep $((RANDOM % ${{ github.event.inputs.max_sleep }} + 1))
done < ids.txt
- name: Upload status report
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: report_${{ matrix.fork_sid }}
path: report_${{ matrix.fork_sid }}.txt
retention-days: 1
report:
needs: [integrity-check]
runs-on: ubuntu-24.04
steps:
- name: Merge status reports
uses: actions/upload-artifact/merge@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: report-group
pattern: report_*
delete-merged: true
- name: Download all status reports
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: report-group
path: .
- name: Status report summary
run: |
find . -type f | xargs cat | sort -t'/' -k1.2n >> $GITHUB_STEP_SUMMARY