-
Notifications
You must be signed in to change notification settings - Fork 0
248 lines (199 loc) · 10.9 KB
/
upstream pretest.yaml
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
name: Upstream pretest
on:
push:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
enmr-PRs:
runs-on: windows-latest
outputs:
exec_list: ${{ steps.make_exec_list.outputs.exec_list }}
remove_list: ${{ steps.make_exec_list.outputs.remove_list }}
steps:
- name: git config
run: |
git config --global core.autocrlf false
git config --global user.name "sun pack bot"
git config --global user.email "[email protected]"
git config --global --add url.https://github.com/.insteadOf "[email protected]:"
- name: checkout
uses: actions/checkout@main
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
.gitmodules
- name: make exec list
id: make_exec_list
run: |
$exec_list = @()
$remove_list = @()
foreach ($subm_key in git config --file .gitmodules --name-only --get-regexp '^submodule\..+\.url$') {
$subm_url = git config --file .gitmodules --get $subm_key
Write-Host "URL: $subm_url"
if ($subm_url -notmatch '^git@github\.com:([\w\-]+)/([\w\-]+)\.git$') {
throw "Unexpected subm_url format: $subm_url"
}
$subm_owner = $Matches[1]
$subm_name = $Matches[2]
$subm_merge_pr_nums = @()
foreach ($ref_l in git ls-remote $subm_url 'refs/pull/*/merge') {
if ($ref_l -notmatch '^[0-9a-f]+\s+refs/pull/(\d+)/merge$') {
throw "Unexpected merge ref format: $ref_l"
}
$pr_num = $Matches[1]
Write-Host "- Found PR $pr_num"
$subm_merge_pr_nums += $pr_num
$exec_list += @{
'subm_url' = $subm_url;
'pr_num' = $pr_num;
}
}
if ($subm_owner -ne 'KhronosGroup') {
throw 'Unexpected original owner of submodule: $subm_owner'
}
$subm_fork_url = "[email protected]:SunSerega/${subm_name}.git"
if ($subm_fork_url -eq $subm_url) {
throw "Fork url [$subm_fork_url] = subm_url [$subm_url]"
}
$subm_pretest_pr_nums = @()
foreach ($ref_l in git ls-remote $subm_fork_url 'refs/heads/pretest/*') {
if ($ref_l -notmatch '^[0-9a-f]+\s+refs/heads/pretest/(.+)$') {
throw "Unexpected subm pretest ref format: $ref_l"
}
$pr_num = $Matches[1]
Write-Host "- Found subm pretest branch for PR $pr_num"
if ($subm_merge_pr_nums -contains $pr_num) { continue }
$subm_pretest_pr_nums += $pr_num
}
$core_pretest_pr_nums = @()
foreach ($ref_l in git ls-remote origin "refs/heads/subm-pretest/$subm_owner/$subm_name/*") {
if ($ref_l -notmatch "^[0-9a-f]+\s+refs/heads/subm-pretest/$subm_owner/$subm_name/(.+)$") {
throw "Unexpected core pretest ref format: $ref_l"
}
$pr_num = $Matches[1]
Write-Host "- Found core pretest branch for PR $pr_num"
if ($subm_merge_pr_nums -contains $pr_num) { continue }
$core_pretest_pr_nums += $pr_num
}
if ($subm_pretest_pr_nums -or $core_pretest_pr_nums) {
$remove_list += @{
'org_repo' = "$subm_owner/$subm_name";
'fork_repo' = "SunSerega/$subm_name";
'subm_pretest_pr_nums' = $subm_pretest_pr_nums -join ',';
'core_pretest_pr_nums' = $core_pretest_pr_nums -join ',';
}
}
}
$json = ConvertTo-Json -Compress $exec_list
Write-Host $json
echo "exec_list=$json" >> $env:GITHUB_OUTPUT
$json = ConvertTo-Json -Compress $remove_list
Write-Host $json
echo "remove_list=$json" >> $env:GITHUB_OUTPUT
pretest-each:
runs-on: windows-latest
needs: enmr-PRs
strategy:
fail-fast: false
matrix:
exec_data: ${{ fromJson(needs.enmr-PRs.outputs.exec_list) }}
steps:
- name: git config
run: |
git config --global core.autocrlf false
git config --global user.name "sun pack bot"
git config --global user.email "[email protected]"
git config --global --add url.https://github.com/.insteadOf "[email protected]:"
- name: checkout
uses: actions/checkout@main
# - name: checkout subm fork
# uses: actions/checkout@main
# with:
# repository: 'SunSerega/OpenCL-Docs'
# ref: 'pretest/${{ matrix.exec_data.pr_num }}'
# path: './fork'
# token: ${{ secrets.POCGL_pretest_upstream_PAT }}
- name: pretest
run: |
$subm_url = "${{ matrix.exec_data.subm_url }}"
$pr_num = "${{ matrix.exec_data.pr_num }}"
Write-Host "Testing PR $pr_num from: $subm_url"
# aaaaa
remove-old-pretest:
runs-on: windows-latest
needs: enmr-PRs
strategy:
fail-fast: false
matrix:
remove-data: ${{ fromJson(needs.enmr-PRs.outputs.remove_list) }}
steps:
- name: git config
run: |
git config --global core.autocrlf false
git config --global user.name "sun pack bot"
git config --global user.email "[email protected]"
git config --global --add url.https://github.com/.insteadOf "[email protected]:"
- name: checkout subm fork
uses: actions/checkout@main
with:
repository: ${{ matrix.remove-data.fork_repo }}
token: ${{ secrets.POCGL_pretest_upstream_PAT }}
sparse-checkout-cone-mode: false
sparse-checkout: '<NOTHING>'
- name: remove old pretest branches
run: |
function Split-OrEmpty {
param ( $s )
if (-not $s) { return @() }
return $s -split ','
}
$org_repo = '${{ matrix.remove-data.org_repo }}'
$fork_repo = '${{ matrix.remove-data.fork_repo }}'
$subm_pretest_pr_nums = Split-OrEmpty '${{ matrix.remove-data.subm_pretest_pr_nums }}'
$core_pretest_pr_nums = Split-OrEmpty '${{ matrix.remove-data.core_pretest_pr_nums }}'
$main_repo_dir = './core'
New-Item -ItemType Directory -Path $main_repo_dir | Out-Null
Push-Location $main_repo_dir
$main_repo_url = '${{ github.server_url }}/${{ github.repository }}'
Write-Host "fetching commits of: $main_repo_url"
git clone --filter=tree:0 $main_repo_url
git branch -r
$core_removed_pr_nums = @()
foreach ($pr_num in $core_pretest_pr_nums) {
Write-Host "Checking if subm-pretest branch for PR $pr_num is trivial"
$branch_name = "subm-pretest/$org_repo/$pr_num"
Write-Host $branch_name
$is_trivial = $true
foreach ($commit_name in git show --pretty=format:"%s" -s "HEAD..origin/$branch_name") {
Write-Host "- $commit_name"
if ($commit_name.StartsWith('[auto pretest]')) { continue }
Write-Host "--- NOT TRIVIAL"
$is_trivial = false
}
if ($is_trivial) {
Write-Host "Is trivial, removing"
git push origin --delete $branch_name
$core_removed_pr_nums += $pr_num
}
Write-Host '~~~~~'
}
Pop-Location
$core_pretest_pr_nums = $core_pretest_pr_nums |
Where-Object { $_ -notin $core_removed_pr_nums }
foreach ($pr_num in $subm_pretest_pr_nums) {
Write-Host "PR $pr_num was orphaned"
if ($core_pretest_pr_nums -contains $pr_num) {
Write-Host "But main repo is still referencing it"
} else {
git push origin --delete "pretest/$pr_num"
}
Write-Host '~~~~~'
}
if ($core_pretest_pr_nums) {
$core_pretest_pr_nums | Out-Host
# TODO test for local changes
throw "Some pretest branches in main repo are dangling"
}