Repository navigation
222 lines (195 loc) Β· 8.48 KB
/
Copy pathcommand-pr-build.yml
File metadata and controls
222 lines (195 loc) Β· 8.48 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
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
name: PR Build
# Triggered by a maintainer commenting on a pull request:
# /build binaries (amd64/arm64/arm) + multiarch docker
# /build amd linux amd64 only
# /build arm linux arm64 + arm/v6 only
# /build docker multiarch docker image only, no binaries
# Uploads downloadable binaries and publishes a docker image tagged pr-<number>.
# The /nightly command lives in command-nightly.yml.
on:
issue_comment:
types: [created]
permissions:
contents: read
jobs:
prep:
name: Prepare
# only on PR comments starting with /build, and only from maintainers
if: |
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/build') &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
runs-on: depot-ubuntu-24.04-arm
permissions:
contents: read
pull-requests: write
outputs:
sha: ${{ steps.pr.outputs.sha }}
archs: ${{ steps.parse.outputs.archs }}
platforms: ${{ steps.parse.outputs.platforms }}
steps:
- name: React to comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'eyes',
});
- name: Parse target
id: parse
env:
BODY: ${{ github.event.comment.body }}
run: |
arg=$(printf '%s' "$BODY" | awk '{print $2}' | tr '[:upper:]' '[:lower:]')
case "$arg" in
amd*) archs='["amd64"]'; platforms='linux/amd64' ;;
arm*) archs='["arm64","arm"]'; platforms='linux/arm64,linux/arm/v6' ;;
docker*) archs='[]'; platforms='linux/amd64,linux/arm64,linux/arm/v6' ;;
*) archs='["amd64","arm64","arm"]'; platforms='linux/amd64,linux/arm64,linux/arm/v6' ;;
esac
echo "archs=$archs" >> "$GITHUB_OUTPUT"
echo "platforms=$platforms" >> "$GITHUB_OUTPUT"
- name: Resolve PR head
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sha=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefOid -q .headRefOid)
echo "sha=$sha" >> "$GITHUB_OUTPUT"
binaries:
name: Binaries
needs: prep
if: needs.prep.outputs.archs != '[]'
runs-on: depot-ubuntu-24.04-arm
permissions:
contents: read
strategy:
matrix:
arch: ${{ fromJSON(needs.prep.outputs.archs) }}
steps:
# base checkout: the local actions below must never come from the PR
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ needs.prep.outputs.sha }}
path: pr
fetch-depth: 0
persist-credentials: false
- name: Setup Buildx
id: buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Restore build cache
uses: ./.github/actions/docker-cache
with:
builder: ${{ steps.buildx.outputs.name }}
cache-scope: pr
# PR code only runs inside the build containers, never on the runner:
# a runner process could write any cache key, including the shared ones
- name: Build binary
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: pr
platforms: linux/${{ matrix.arch == 'arm' && 'arm/v6' || matrix.arch }}
outputs: type=local,dest=out
- name: Compress binary
run: gzip -9 -c out/usr/local/bin/evcc > "evcc-linux-${{ matrix.arch }}.gz"
- name: Upload binary
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: evcc-pr-${{ github.event.issue.number }}-linux-${{ matrix.arch }}
path: evcc-linux-${{ matrix.arch }}.gz
compression-level: 0 # already gzip'd, skip redundant zip compression
retention-days: 14
docker:
name: Docker
needs: prep
runs-on: depot-ubuntu-24.04-arm
permissions:
contents: read
steps:
# base checkout: the local actions below must never come from the PR
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ needs.prep.outputs.sha }}
path: pr
fetch-depth: 0
persist-credentials: false
- name: Setup Buildx
id: buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Restore build cache
uses: ./.github/actions/docker-cache
with:
builder: ${{ steps.buildx.outputs.name }}
cache-scope: pr
# as late as possible: PR code only runs inside the build containers
- name: Login
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Publish
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: pr
platforms: ${{ needs.prep.outputs.platforms }}
push: true
tags: evcc/evcc:pr-${{ github.event.issue.number }}
report:
name: Report
needs: [prep, binaries, docker]
if: always() && needs.prep.result == 'success'
runs-on: depot-ubuntu-24.04-arm
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Comment result
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const num = context.payload.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const runUrl = `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`;
const b = '${{ needs.binaries.result }}';
const d = '${{ needs.docker.result }}';
const ok = d === 'success' && (b === 'success' || b === 'skipped');
const artifacts = [];
if (b === 'success') artifacts.push(`- Binaries: [download artifacts](${runUrl}#artifacts)`);
artifacts.push(`- Docker: \`docker pull evcc/evcc:pr-${num}\``);
const prBody = ok
? [`β
Build finished.`, '', ...artifacts].join('\n')
: `β Build failed. See the [run logs](${runUrl}).`;
await github.rest.issues.createComment({ owner, repo, issue_number: num, body: prBody });
if (!ok) return;
// builds are ready to test: flag PR and linked issues as waiting for feedback
const labels = ['waiting for feedback'];
await github.rest.issues.addLabels({ owner, repo, issue_number: num, labels });
// notify each issue this PR closes (via "fixes #N" keywords) that fresh builds exist
const q = `query($owner:String!,$repo:String!,$num:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$num){closingIssuesReferences(first:20){nodes{number}}}}}`;
const res = await github.graphql(q, { owner, repo, num });
const issues = res.repository.pullRequest.closingIssuesReferences.nodes.map((n) => n.number);
for (const issue_number of issues) {
const body = [`Test binaries for the fix in #${num} are ready to test:`, '', ...artifacts].join('\n');
await github.rest.issues.createComment({ owner, repo, issue_number, body });
await github.rest.issues.addLabels({ owner, repo, issue_number, labels });
}
- name: Resolve command comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
// collapse the /build comment as resolved now that the build is done
await github.graphql(
`mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:RESOLVED}){minimizedComment{isMinimized}}}`,
{ id: context.payload.comment.node_id }
);