-
Notifications
You must be signed in to change notification settings - Fork 2
205 lines (170 loc) · 6.48 KB
/
test.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
name: Test
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- edited
permissions:
contents: read
pull-requests: write
issues: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
pre-test:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
need_to_run: ${{ steps.set-matrix.outputs.need_to_run }}
steps:
- name: generate matrix from PR body
id: set-matrix
env:
RAW_BODY: ${{ github.event.pull_request.body }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const TASK_REGEXP = /- \[x\] (.*)/g;
const getTask = (text) => {
const result = [];
let match;
while ((match = TASK_REGEXP.exec(text)) !== null) {
result.push(match[1]);
}
return {
matrix: result,
need_to_run: result.length > 0
};
}
if (context.payload.action !== "edited") {
console.log("not edited event");
const { matrix, need_to_run } = getTask(process.env.RAW_BODY);
core.setOutput("matrix", matrix);
core.setOutput("need_to_run", need_to_run);
return;
}
const query = `query ($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
userContentEdits(first: 2) {
nodes {
diff
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
number: context.issue.number
};
const history = await github.graphql(query, variables);
if (history.repository.pullRequest.userContentEdits.nodes.length !== 2) {
console.log("not enough history")
const { matrix, need_to_run } = getTask(process.env.RAW_BODY);
core.setOutput("matrix", matrix);
core.setOutput("need_to_run", need_to_run);
return;
}
const latestTasks = getTask(history.repository.pullRequest.userContentEdits.nodes[0].diff);
const previousTasks = getTask(history.repository.pullRequest.userContentEdits.nodes[1].diff);
const sortLatest = latestTasks.matrix.sort();
const sortPrevious = previousTasks.matrix.sort();
for (const [index, task] of sortPrevious.entries()) {
if (sortLatest[index] === undefined) {
console.log("latest task is less than previous, skip");
continue;
}
if (task !== sortLatest[index]) {
console.log(`has added ${task}, need to run`);
const { matrix, need_to_run } = latestTasks;
core.setOutput("matrix", matrix);
core.setOutput("need_to_run", need_to_run);
return;
}
}
console.log("no new task added, skip");
core.setOutput("matrix", []);
core.setOutput("need_to_run", false);
test:
runs-on: ubuntu-latest
needs: pre-test
if: ${{ needs.pre-test.outputs.need_to_run == 'true' }}
outputs:
matrix: ${{ needs.pre-test.outputs.matrix }}
strategy:
fail-fast: true
matrix:
target-arch: ${{ fromJSON(needs.pre-test.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Update kernel submodules
if: ${{ startsWith(matrix.target-arch, 'kernel') }}
run: git submodule update --init kernel
- name: Update buildroot submodules
if: ${{ !startsWith(matrix.target-arch, 'kernel') }}
run: git submodule update --init buildroot
- name: Install deps
run: sudo apt-get install -y build-essential flex bison libssl-dev libelf-dev bc
- name: Install kernel arm64 deps
if: ${{ matrix.target-arch == 'kernel-arm64' }}
run: sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Defconfig
run: make defconfig-${{ matrix.target-arch }}
- name: Build
run: make build-${{ matrix.target-arch }} -j$(nproc)
- name: Get output file size
run: |
FILE_PATH=$(make print-outpath-${{ matrix.target-arch }})
SIZE_B=$(stat -c%s "$FILE_PATH")
SIZE_MB=$(echo $SIZE_B | awk '{ printf "%.4f", $1 / 1024 / 1024 }')
mkdir outputs-size
echo "${{ matrix.target-arch }} $SIZE_MB $SIZE_B" > outputs-size/${{ matrix.target-arch }}.txt
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ${{ github.run_id }}-${{ github.run_number }}-${{ matrix.target-arch }}
path: outputs-size/*.txt
retention-days: 1
post-test:
runs-on: ubuntu-latest
needs:
- pre-test
- test
if: ${{ needs.pre-test.outputs.need_to_run == 'true' }}
steps:
- name: Load outputs-size
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
with:
pattern: ${{ github.run_id }}-${{ github.run_number }}-*
path: outputs-size
merge-multiple: true
- name: Format outputs-size
id: size
run: |
cat > comment.md <<EOF
Build Output Summary
|Target|Size|
|-|-|
`sort outputs-size/*.txt | awk '{ printf "|**"$1"**|*"$2"MB ("$3" bytes)*|\n" }'`
EOF
- name: Find comment
uses: peter-evans/find-comment@d5fe37641ad8451bdd80312415672ba26c86575e # v3.0.0
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Build Output Summary
- name: Create or update comment
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: ./comment.md
edit-mode: replace