forked from Serious-senpai/tabu-search
-
Notifications
You must be signed in to change notification settings - Fork 0
218 lines (187 loc) · 6.38 KB
/
d2d-compare.yml
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
name: Compare D2D solutions
on:
issue_comment:
types: created
permissions:
contents: read
pull-requests: write
jobs:
input-check:
name: Check input
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/d2d-compare') && github.event.comment.author_association == 'OWNER' }}
runs-on: ubuntu-latest
steps:
- name: Parse and check input
run: |
dot="\."
problem="${{ github.event.comment.body }}"
problem=$(echo ${problem#"/d2d-compare"} | xargs)
echo -n "$problem" > input.txt
echo "$problem"
[[ "$problem" =~ ^[0-9]+$dot[0-9]+$dot[0-9]+$ ]]
exit $?
- name: Upload parsed input
uses: actions/upload-artifact@v3
with:
name: solutions
path: input.txt
- name: Send comment on failure
if: ${{ failure() }}
uses: actions/github-script@v7
with:
retries: 3
script: |
var fs = require("fs");
await fs.readFile(
"input.txt",
"utf-8",
function(error, data) {
if (error) throw error;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.issue.number }},
body: `❌ Invalid input \`${data}\``,
});
}
);
- name: Add reaction to comment
uses: actions/github-script@v7
with:
retries: 3
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
content: "+1",
});
pr-test:
name: Test on PR
runs-on: ubuntu-latest
needs: input-check
strategy:
matrix:
counter: [1, 2]
steps:
- name: Get PR branch name
id: get-branch
uses: actions/github-script@v7
with:
script: |
try {
var result = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.issue.number }},
});
return result.data;
} catch (e) {
core.setFailed(`Failed to get branch name of PR#${{ github.event.issue.number }}: ${e}`);
}
- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ fromJSON(steps.get-branch.outputs.result).head.ref }}
- name: Setup Python
uses: actions/setup-python@v4
- name: Install dependencies
run: pip install -r dev-requirements.txt
- name: Download parsed input
uses: actions/download-artifact@v3
with:
name: solutions
- name: Run test
run: |
problem=$(cat input.txt)
python d2d.py "$problem" \
--drone-config-mapping 3 3 3 3 \
--pool-size 8 \
--dump PR#${{ github.event.issue.number }}-run#${{ matrix.counter }}.json
- name: Upload solution
uses: actions/upload-artifact@v3
with:
name: solutions
path: PR#${{ github.event.issue.number }}-run#${{ matrix.counter }}.json
main-test:
name: Test on main
runs-on: ubuntu-latest
needs: input-check
strategy:
matrix:
counter: [1, 2]
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: main
- name: Setup Python
uses: actions/setup-python@v4
- name: Install dependencies
run: pip install -r dev-requirements.txt
- name: Download parsed input
uses: actions/download-artifact@v3
with:
name: solutions
- name: Run test
run: |
problem=$(cat input.txt)
python d2d.py "$problem" \
--drone-config-mapping 3 3 3 3 \
--pool-size 8 \
--dump main-run#${{ matrix.counter }}.json
- name: Upload solution
uses: actions/upload-artifact@v3
with:
name: solutions
path: main-run#${{ matrix.counter }}.json
compare:
name: Compare solutions
if: ${{ github.event.issue.pull_request }}
needs: [pr-test, main-test]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
- name: Install dependencies
run: pip install -r dev-requirements.txt
- name: Download solutions
uses: actions/download-artifact@v3
with:
name: solutions
- name: Combine solutions and compare
run: |
export PYTHONPATH=$GITHUB_WORKSPACE
python scripts/d2d-compare.py PR#${{ github.event.issue.number }}-run#1.json PR#${{ github.event.issue.number }}-run#2.json main-run#1.json main-run#2.json
- name: Upload compare result as artifact
uses: actions/upload-artifact@v3
with:
name: solutions
path: compare.png
- name: Upload compare result to catbox.moe
run: |
url=$(curl -F "reqtype=fileupload" -F "fileToUpload=@compare.png" "https://catbox.moe/user/api.php")
errorcode=$?
echo "$url"
echo -n "$url" > url.txt
exit $errorcode
- name: Send completion notification
uses: actions/github-script@v7
with:
retries: 3
script: |
var fs = require("fs");
await fs.readFile("input.txt", "utf-8", async function (error, input) {
if (error) throw error;
await fs.readFile("url.txt", "utf-8", async function (error, url) {
if (error) throw error;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.issue.number }},
body: `🎉 Comparison request for D2D problem \`${input.trim()}\` completed! You can view the workflow results [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).\n![compare.png](${url.trim()})`,
});
});
});