Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

457 lines · 26.7 KBRaw History
1name: Live test
2
3# End-to-end checks against the real diffinery.com after each deploy: email
4# sending, web UI features (syntax highlighting, settings pages, view transitions), hosted Actions jobs in Cloudflare Containers (with Docker builds and services), the container registry, agent sandboxes,
5# webhooks, scheduled workflows, Git LFS, and pull requests (test merge commits, pull_request_target and the merge
6# queue). Each run works in a throwaway private repository that it
7# deletes at the end.
8#
9# Needs the repository secret DIFFINERY_LIVE_TOKEN: a Diffinery token (Settings ->
10# Tokens) with the admin scope and access to all repositories.
11on:
12 workflow_dispatch:
13 workflow_run:
14 workflows: [Deploy]
15 types: [completed]
16 branches: [main]
17
18permissions:
19 contents: read
20
21concurrency:
22 group: live-test
23 cancel-in-progress: false
24
25jobs:
26 live:
27 name: Containers, registry, sandboxes, webhooks, schedules, LFS and pull requests
28 # Runs on the host that deploys production (see the gate in deploy.yml).
29 if: ${{ github.event_name == 'workflow_dispatch' || (github.server_url == 'https://diffinery.com' && github.event.workflow_run.conclusion == 'success') }}
30 runs-on: ubuntu-latest
31 timeout-minutes: 45
32 env:
33 DIFFINERY: https://diffinery.com
34 TOKEN: ${{ secrets.DIFFINERY_LIVE_TOKEN }}
35 REPO: live-${{ github.run_id }}-${{ github.run_attempt }}
36 steps:
37 - name: Check the token
38 id: token
39 run: |
40 if [ -z "$TOKEN" ]; then
41 echo "::warning::DIFFINERY_LIVE_TOKEN is not set, so the live test is skipped. Create an admin token at $DIFFINERY/settings/tokens and save it as a repository secret."
42 echo "skip=true" >> "$GITHUB_OUTPUT"
43 exit 0
44 fi
45 login=$(curl -fsS "$DIFFINERY/api/v3/user" -H "Authorization: Bearer $TOKEN" | jq -r .login)
46 echo "OWNER=$login" >> "$GITHUB_ENV"
47 echo "testing as $login in $login/$REPO"
48
49 - name: Profile picture upload (WASM resize in the Worker)
50 if: steps.token.outputs.skip != 'true'
51 run: |
52 set -euo pipefail
53 av="$DIFFINERY/api/avatars/$OWNER"
54 # Keep the account's current picture, if it has one, to put it back afterwards.
55 had=$(curl -fsS -o before.webp -w '%{content_type}' "$av?s=256&v=1")
56 restore() {
57 if [ "$had" = image/webp ]; then
58 curl -fsS -X PUT "$DIFFINERY/api/v3/user/avatar" -H "Authorization: Bearer $TOKEN" -H "content-type: image/webp" --data-binary @before.webp | jq -r '"restored the previous picture: \(.avatar_url)"'
59 else
60 curl -fsS -o /dev/null -X DELETE "$DIFFINERY/api/v3/user/avatar" -H "Authorization: Bearer $TOKEN"
61 fi
62 }
63 trap restore EXIT
64 # A 600×400 PNG gradient; the server crops it to a square and makes small WebPs.
65 python3 - <<'EOF'
66 import struct, zlib
67 w, h = 600, 400
68 rows = b"".join(b"\0" + bytes(c for x in range(w) for c in (x * 255 // w, y * 255 // h, 128)) for y in range(h))
69 chunk = lambda t, d: struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d))
70 open("avatar.png", "wb").write(b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(rows)) + chunk(b"IEND", b""))
71 EOF
72 url=$(curl -fsS -X PUT "$DIFFINERY/api/v3/user/avatar" -H "Authorization: Bearer $TOKEN" -H "content-type: image/png" --data-binary @avatar.png | jq -r .avatar_url)
73 echo "uploaded: $url"
74 v=${url##*v=}
75 type=$(curl -fsS -o small.webp -w '%{content_type}' "$av?s=64&v=$v")
76 [ "$type" = image/webp ] || { echo "::error::expected image/webp, got $type"; exit 1; }
77 python3 - <<'EOF'
78 import struct, sys
79 b = open("small.webp", "rb").read()
80 ok = b[:4] == b"RIFF" and b[8:12] == b"WEBP"
81 if b[12:16] == b"VP8 ":
82 size = (struct.unpack("<H", b[26:28])[0] & 0x3FFF, struct.unpack("<H", b[28:30])[0] & 0x3FFF)
83 elif b[12:16] == b"VP8X":
84 size = (int.from_bytes(b[24:27], "little") + 1, int.from_bytes(b[27:30], "little") + 1)
85 else:
86 size = None
87 print(f"64 px avatar: {len(b)} bytes, {size}")
88 if not ok or size != (64, 64) or len(b) > 5000:
89 print("::error::the 64 px avatar is not a 64x64 WebP under 5 KB"); sys.exit(1)
90 EOF
91 curl -fsS -X DELETE "$DIFFINERY/api/v3/user/avatar" -H "Authorization: Bearer $TOKEN" >/dev/null
92 # A `v` that is not current bypasses the edge cache, so this sees the removal from any colo.
93 type=$(curl -fsS -o /dev/null -w '%{content_type}' "$av?s=64&v=1")
94 [[ "$type" == image/svg+xml* ]] || { echo "::error::after removal expected the initials SVG, got $type"; exit 1; }
95 echo "removed: initials again ($type)"
96
97 - name: Public docs are served without signing in
98 run: |
99 set -euo pipefail
100 check() { # path, content type, text it must contain
101 body=$(curl -fsS -D /tmp/h "$DIFFINERY$1")
102 grep -qi "content-type: $2" /tmp/h || { echo "::error::$1 is not $2"; exit 1; }
103 grep -qF -- "$3" <<<"$body" || { echo "::error::$1 doesn't contain: $3"; exit 1; }
104 echo "$1 ok ($(wc -c <<<"$body") bytes)"
105 }
106 check /docs "text/html" "Overview"
107 check /docs/actions/workflow-syntax "text/html" "View as Markdown"
108 check /docs/quickstart.md "text/markdown" "# Quickstart"
109 check /llms.txt "text/plain" "/docs/actions/workflow-syntax.md"
110 check /llms-full.txt "text/plain" "# REST API reference"
111 check /docs/api/openapi.json "application/json" '"openapi": "3.1.0"'
112 check /-/cli/diffinery.mjs "text/javascript" "#!/usr/bin/env node"
113 md=$(curl -fsS -H "Accept: text/markdown" "$DIFFINERY/docs/agents/mcp")
114 grep -q "^# MCP" <<<"$md" || { echo "::error::Accept: text/markdown didn't return Markdown"; exit 1; }
115 curl -fsS "$DIFFINERY/-/cli/diffinery.mjs" -o /tmp/diffinery.mjs && node /tmp/diffinery.mjs --version
116
117 - name: Email sending is configured
118 if: steps.token.outputs.skip != 'true'
119 run: |
120 set -euo pipefail
121 s=$(curl -fsS "$DIFFINERY/api/v3/diffinery/admin/email" -H "Authorization: Bearer $TOKEN")
122 echo "$s" | jq '{sending, queue, from, last_24h}'
123 [ "$(jq -r .sending <<<"$s")" = true ] || { echo "::error::the Worker has no Email Sending binding"; exit 1; }
124 [ "$(jq -r .queue <<<"$s")" = true ] || { echo "::error::the Worker has no mail queue binding"; exit 1; }
125 failed=$(jq -r .last_24h.failed <<<"$s")
126 [ "$failed" = 0 ] || echo "::warning::$failed emails failed in the last 24 hours; see Settings -> Email in site administration"
127
128 - name: Create a throwaway repository with a webhook
129 if: steps.token.outputs.skip != 'true'
130 run: |
131 set -euo pipefail
132 api() { curl -fsS -X "$1" "$DIFFINERY/api/v3$2" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" ${3:+--data "$3"}; }
133 api POST /user/repos "{\"name\":\"$REPO\",\"private\":true}" >/dev/null
134 api POST "/repos/$OWNER/$REPO/hooks" "{\"config\":{\"url\":\"$DIFFINERY/healthz\"},\"events\":[\"push\"]}" >/dev/null
135 echo "created $OWNER/$REPO"
136
137 - name: Push workflows and an LFS file
138 if: steps.token.outputs.skip != 'true'
139 run: |
140 set -euo pipefail
141 mkdir -p src/.github/workflows && cd src
142 git init -q -b main
143 git config user.name "Live test" && git config user.email "live-test@diffinery.com"
144 git lfs install --local >/dev/null
145 git lfs track "*.bin" >/dev/null
146 head -c 3145728 /dev/urandom > blob.bin
147 sha256sum blob.bin | cut -d' ' -f1 > ../blob.sha
148 echo "# $REPO" > README.md
149 cat > .github/workflows/ci.yml <<'EOF'
150 on: push
151 jobs:
152 hosted:
153 runs-on: ubuntu-latest
154 strategy:
155 matrix:
156 n: [1, 2]
157 steps:
158 - uses: actions/checkout@v4
159 - run: echo "live ok ${{ '${{' }} matrix.n }} $(cat README.md)"
160 docker:
161 runs-on: ubuntu-latest
162 services:
163 cache:
164 image: redis:7-alpine
165 ports: ["6379"]
166 options: --health-cmd "redis-cli ping" --health-interval 1s --health-retries 30
167 steps:
168 - run: |
169 printf 'FROM alpine:3.20\nRUN echo built > /msg\nCMD ["cat", "/msg"]\n' > Dockerfile
170 docker build -q -t live-image .
171 echo "docker ok $(docker run --rm live-image)"
172 exec 3<>/dev/tcp/127.0.0.1/${{ '${{' }} job.services.cache.ports['6379'] }}
173 printf 'PING\r\n' >&3
174 read -r line <&3
175 echo "service ok ${line%$'\r'}"
176 # Container registry: a layer over Cloudflare's 100 MB request limit, pushed with
177 # the job's GITHUB_TOKEN, plus the docker/*-action route most ghcr.io workflows use.
178 publish:
179 runs-on: ubuntu-latest
180 permissions:
181 packages: write
182 steps:
183 - run: |
184 image="diffinery.com/${GITHUB_REPOSITORY,,}"
185 echo "${{ '${{' }} secrets.GITHUB_TOKEN }}" | docker login diffinery.com -u "${{ '${{' }} github.actor }}" --password-stdin
186 head -c 150000000 /dev/urandom > big.bin
187 sha256sum big.bin | cut -d' ' -f1 > big.sha
188 printf 'FROM scratch\nCOPY big.bin big.sha /\n' > Dockerfile
189 docker build -q -t "$image:live" .
190 docker push "$image:live"
191 echo "pushed $(cat big.sha)"
192 buildx:
193 runs-on: ubuntu-latest
194 permissions:
195 packages: write
196 steps:
197 - run: |
198 echo "IMAGE=diffinery.com/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
199 head -c 120000000 /dev/urandom > big.bin
200 printf 'FROM scratch\nCOPY big.bin /\n' > Dockerfile
201 - uses: docker/setup-buildx-action@v3
202 - uses: docker/login-action@v3
203 with:
204 registry: diffinery.com
205 username: ${{ '${{' }} github.actor }}
206 password: ${{ '${{' }} secrets.GITHUB_TOKEN }}
207 - uses: docker/build-push-action@v6
208 with:
209 context: .
210 push: true
211 tags: ${{ '${{' }} env.IMAGE }}:buildx
212 pull:
213 needs: [publish, buildx]
214 runs-on: ubuntu-latest
215 permissions:
216 packages: read
217 steps:
218 - run: |
219 image="diffinery.com/${GITHUB_REPOSITORY,,}"
220 echo "${{ '${{' }} secrets.GITHUB_TOKEN }}" | docker login diffinery.com -u "${{ '${{' }} github.actor }}" --password-stdin
221 docker pull -q "$image:live"
222 id=$(docker create "$image:live" true)
223 docker cp "$id:/big.bin" big.bin && docker cp "$id:/big.sha" big.sha
224 [ "$(sha256sum big.bin | cut -d' ' -f1)" = "$(cat big.sha)" ] && echo "registry ok $(stat -c %s big.bin) bytes"
225 docker pull -q "$image:buildx"
226 id=$(docker create "$image:buildx" true)
227 docker cp "$id:/big.bin" buildx.bin
228 echo "buildx ok $(stat -c %s buildx.bin) bytes"
229 EOF
230 cat > .github/workflows/tick.yml <<'EOF'
231 on:
232 schedule:
233 - cron: "*/5 * * * *"
234 jobs:
235 tick:
236 runs-on: ubuntu-latest
237 steps:
238 - run: echo "scheduled ok"
239 EOF
240 git add -A && git commit -q -m "Live test"
241 git push -q "https://x-token:${TOKEN}@${DIFFINERY#https://}/$OWNER/$REPO.git" main
242 git lfs ls-files
243
244 - name: Web UI features (highlighting, settings pages, view transitions, base permission)
245 if: steps.token.outputs.skip != 'true'
246 run: |
247 set -euo pipefail
248 page() { curl -fsS "$DIFFINERY$1" -H "Authorization: Bearer $TOKEN"; }
249 has() { grep -qF -- "$2" <<<"$1" || { echo "::error::$3"; exit 1; }; }
250 html=$(page "/$OWNER/$REPO/blob/main/.github/workflows/ci.yml")
251 has "$html" '<td class="sh">' "the workflow file is not syntax highlighted"
252 has "$html" "--shiki-dark" "highlighted code has no dark theme colours"
253 has "$html" "@view-transition{navigation:auto}" "pages don't opt in to view transitions"
254 has "$html" "prefers-reduced-motion:no-preference" "view transitions ignore reduced motion"
255 has "$(page /settings/appearance)" 'name="appearance"' "Settings -> Appearance has no theme choice"
256 has "$(page /notifications)" 'href="/settings/notifications"' "the notifications page doesn't link to notification settings"
257 code=$(curl -sS -o /tmp/out -w '%{http_code}' -X POST "$DIFFINERY/api/v3/user/repos" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" --data "{\"name\":\"$REPO-internal\",\"visibility\":\"internal\"}")
258 [ "$code" = 422 ] || { echo "::error::visibility internal got $code, expected 422"; curl -sS -o /dev/null -X DELETE "$DIFFINERY/api/v3/repos/$OWNER/$REPO-internal" -H "Authorization: Bearer $TOKEN"; exit 1; }
259 org=$(page /api/v3/user/orgs | jq -r '.[0].login // empty')
260 if [ -n "$org" ]; then
261 perm=$(page "/api/v3/orgs/$org" | jq -r '.default_repository_permission // empty')
262 case "$perm" in none|read|write|admin) echo "$org's base permission: $perm" ;; *) echo "::error::GET /orgs/$org has no default_repository_permission"; exit 1 ;; esac
263 fi
264 echo "highlighting, Appearance, notification settings link, view transitions and visibility checks passed"
265
266 - name: Hosted Actions jobs (and Docker) run in Cloudflare Containers
267 if: steps.token.outputs.skip != 'true'
268 run: |
269 set -euo pipefail
270 api() { curl -fsS "$DIFFINERY/api/v3$1" -H "Authorization: Bearer $TOKEN"; }
271 for i in $(seq 1 90); do
272 run=$(api "/repos/$OWNER/$REPO/actions/runs?event=push" | jq -c '.workflow_runs[0] // empty')
273 [ -n "$run" ] && [ "$(jq -r .status <<<"$run")" = completed ] && break
274 sleep 10
275 done
276 echo "$run" | jq '{id, status, conclusion}'
277 id=$(jq -r .id <<<"$run")
278 jobs=$(api "/repos/$OWNER/$REPO/actions/runs/$id/jobs")
279 jq -r '.jobs[] | " \(.name): \(.conclusion)\(if .failure then " - " + (.failure.message // "") else "" end)"' <<<"$jobs"
280 if [ "$(jq -r .conclusion <<<"$run")" != success ]; then
281 for job in $(jq -r '.jobs[] | select(.conclusion == "failure" or .conclusion == "timed_out") | .id' <<<"$jobs"); do
282 echo "::group::Last log lines of job $job"
283 api "/repos/$OWNER/$REPO/actions/jobs/$job/logs" | tail -n 80 || true
284 echo "::endgroup::"
285 done
286 echo "::error::the push run did not succeed"
287 exit 1
288 fi
289 for job in $(jq -r '.jobs[] | select(.name | startswith("hosted")) | .id' <<<"$jobs"); do
290 log=$(api "/repos/$OWNER/$REPO/actions/jobs/$job/logs")
291 grep -F "live ok" <<<"$log" | grep -F "# $REPO" || { echo "::error::job $job did not print its line (checkout or run step failed)"; exit 1; }
292 done
293 job=$(jq -r '.jobs[] | select(.name == "docker") | .id' <<<"$jobs")
294 log=$(api "/repos/$OWNER/$REPO/actions/jobs/$job/logs")
295 grep -F "docker ok built" <<<"$log" || { echo "::error::docker build or run failed on a hosted runner"; exit 1; }
296 grep -F "service ok +PONG" <<<"$log" || { echo "::error::the redis service container was not reachable"; exit 1; }
297 job=$(jq -r '.jobs[] | select(.name == "pull") | .id' <<<"$jobs")
298 log=$(api "/repos/$OWNER/$REPO/actions/jobs/$job/logs")
299 grep -F "registry ok 150000000 bytes" <<<"$log" || { echo "::error::the image pushed with a 150 MB layer did not come back intact from the registry"; exit 1; }
300 grep -F "buildx ok 120000000 bytes" <<<"$log" || { echo "::error::the image pushed by docker/build-push-action did not come back from the registry"; exit 1; }
301 api "/users/$OWNER/packages/container/${REPO,,}/versions" | jq -c '.[] | {tags: .metadata.container.tags, size, platforms}'
302
303 - name: An organization's packages page keeps its tabs
304 if: steps.token.outputs.skip != 'true'
305 run: |
306 set -euo pipefail
307 org=$(curl -fsS "$DIFFINERY/api/v3/user/orgs" -H "Authorization: Bearer $TOKEN" | jq -r '.[0].login // empty')
308 [ -n "$org" ] || { echo "$OWNER is in no organization; skipped"; exit 0; }
309 html=$(curl -fsS "$DIFFINERY/$org/-/packages" -H "Authorization: Bearer $TOKEN")
310 grep -qF "<a href=\"/$org/-/packages\" class=\"on\">" <<<"$html" || { echo "::error::$org's packages page lost the organization's tab bar"; exit 1; }
311 grep -qF "href=\"/$org?tab=repositories\"" <<<"$html" || { echo "::error::$org's packages page has no Repositories tab"; exit 1; }
312 echo "$org's packages page shows the organization's tabs with Packages selected"
313
314 - name: Git LFS round trip
315 if: steps.token.outputs.skip != 'true'
316 run: |
317 set -euo pipefail
318 git clone -q "https://x-token:${TOKEN}@${DIFFINERY#https://}/$OWNER/$REPO.git" clone
319 [ "$(sha256sum clone/blob.bin | cut -d' ' -f1)" = "$(cat blob.sha)" ] || { echo "::error::the LFS file came back different"; exit 1; }
320 echo "LFS file matches ($(stat -c %s clone/blob.bin) bytes)"
321
322 - name: Webhook delivered
323 if: steps.token.outputs.skip != 'true'
324 run: |
325 set -euo pipefail
326 for i in $(seq 1 30); do
327 hook=$(curl -fsS "$DIFFINERY/api/v3/repos/$OWNER/$REPO/hooks" -H "Authorization: Bearer $TOKEN" | jq -c '.[0]')
328 # GitHub's hook shape: the target is config.url, the last delivery's status last_response.code.
329 [ "$(jq -r '.last_response.code // empty' <<<"$hook")" != "" ] && break
330 sleep 5
331 done
332 echo "$hook" | jq '{target: .config.url, last_response, updated_at}'
333 [ "$(jq -r '.last_response.code // empty' <<<"$hook")" != "" ] || { echo "::error::the push webhook was never delivered"; exit 1; }
334
335 - name: Agent sandbox
336 if: steps.token.outputs.skip != 'true'
337 run: |
338 set -euo pipefail
339 base="$DIFFINERY/api/v3/repos/$OWNER/$REPO/diffinery/sandboxes"
340 id=$(curl -fsS --retry 1 --retry-delay 15 -X POST "$base" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" --data '{}' | jq -r .id)
341 echo "sandbox $id"
342 for i in $(seq 1 40); do
343 out=$(curl -sS -X POST "$base/$id/exec" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" --data '{"cmd":"cat README.md && git lfs ls-files | wc -l"}' || true)
344 jq -e '.exitCode == 0' >/dev/null 2>&1 <<<"$out" && break
345 sleep 6
346 done
347 echo "$out" | jq '{exitCode, stdout}'
348 curl -sS -X POST "$base/$id/close" -H "Authorization: Bearer $TOKEN" >/dev/null || true
349 jq -e --arg r "# $REPO" '.exitCode == 0 and (.stdout | contains($r))' >/dev/null <<<"$out" || { echo "::error::the sandbox did not run the command in the repository"; exit 1; }
350
351 - name: Pull requests and the merge queue
352 if: steps.token.outputs.skip != 'true'
353 run: |
354 set -euo pipefail
355 Q="$REPO-pr"
356 api() { curl -fsS -X "$1" "$DIFFINERY/api/v3$2" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" ${3:+--data "$3"}; }
357 api POST /user/repos "{\"name\":\"$Q\",\"private\":true}" >/dev/null
358 echo "PR_REPO=$Q" >> "$GITHUB_ENV"
359 api PUT "/repos/$OWNER/$Q/actions/secrets/TOPSECRET" '{"value":"s3cret"}' >/dev/null
360 remote="https://x-token:${TOKEN}@${DIFFINERY#https://}/$OWNER/$Q.git"
361 mkdir -p pr/.github/workflows && cd pr
362 git init -q -b main
363 git config user.name "Live test" && git config user.email "live-test@diffinery.com"
364 printf 'a\nb\nc\n' > app.txt
365 cat > .github/workflows/ci.yml <<'EOF'
366 name: CI
367 on:
368 pull_request:
369 merge_group:
370 jobs:
371 test:
372 runs-on: ubuntu-latest
373 steps:
374 - uses: actions/checkout@v4
375 - run: echo "pr ok event=${{ '${{' }} github.event_name }} ref=${{ '${{' }} github.ref }} sha=${{ '${{' }} github.sha }} head=$(git rev-parse HEAD) app=$(tr '\n' ' ' < app.txt)"
376 EOF
377 cat > .github/workflows/target.yml <<'EOF'
378 name: Target
379 on: pull_request_target
380 jobs:
381 t:
382 runs-on: ubuntu-latest
383 steps:
384 - run: echo "target ok secret=${{ '${{' }} secrets.TOPSECRET == 's3cret' }} ref=${{ '${{' }} github.ref }}"
385 EOF
386 git add -A && git commit -q -m "PR test" && git push -q "$remote" main
387 # The pull request changes app.txt and tries to rewrite the pull_request_target workflow.
388 git checkout -q -b change
389 printf 'A\nb\nc\n' > app.txt
390 sed -i 's/target ok/PWNED/' .github/workflows/target.yml
391 git commit -q -am "Change" && git push -q "$remote" change
392 head=$(git rev-parse HEAD)
393 # Main moves on, so the test merge commit holds both sides.
394 git checkout -q main
395 printf 'a\nb\nC\n' > app.txt
396 git commit -q -am "Main moves" && git push -q "$remote" main
397 n=$(api POST "/repos/$OWNER/$Q/pulls" '{"title":"Change","head":"change","base":"main"}' | jq -r .number)
398 echo "opened pull request #$n (head $head)"
399
400 wait_run() { # event -> the completed run JSON
401 for i in $(seq 1 60); do
402 run=$(api GET "/repos/$OWNER/$Q/actions/runs?event=$1" | jq -c '.workflow_runs[0] // empty')
403 [ -n "$run" ] && [ "$(jq -r .status <<<"$run")" = completed ] && { echo "$run"; return; }
404 sleep 10
405 done
406 echo "::error::no completed $1 run" >&2; exit 1
407 }
408 log_of() { for job in $(api GET "/repos/$OWNER/$Q/actions/runs/$1/jobs" | jq -r '.jobs[].id'); do api GET "/repos/$OWNER/$Q/actions/jobs/$job/logs"; done; }
409 pr=$(wait_run pull_request)
410 echo "$pr" | jq '{event, ref, sha, head_sha, conclusion}'
411 [ "$(jq -r .conclusion <<<"$pr")" = success ] || { echo "::error::the pull_request run failed"; exit 1; }
412 [ "$(jq -r .ref <<<"$pr")" = "refs/pull/$n/merge" ] && [ "$(jq -r .head_sha <<<"$pr")" = "$head" ] && [ "$(jq -r .sha <<<"$pr")" != "$head" ] || { echo "::error::the pull_request run did not use the test merge commit"; exit 1; }
413 log_of "$(jq -r .id <<<"$pr")" | grep -F "pr ok event=pull_request ref=refs/pull/$n/merge" | grep -F "app=A b C" || { echo "::error::the pull_request job did not check out the merged code"; exit 1; }
414 target=$(wait_run pull_request_target)
415 echo "$target" | jq '{event, ref, sha, head_sha, conclusion}'
416 tlog=$(log_of "$(jq -r .id <<<"$target")")
417 grep -F "target ok secret=true ref=refs/heads/main" <<<"$tlog" || { echo "::error::pull_request_target did not run the base workflow with secrets"; exit 1; }
418 ! grep -q PWNED <<<"$tlog" || { echo "::error::pull_request_target ran the pull request's workflow"; exit 1; }
419
420 api PUT "/repos/$OWNER/$Q/branches/main/protection" '{"requirePullRequest":true,"requiredChecks":["CI / test"],"mergeQueue":{"method":"squash","checkTimeoutMinutes":20}}' >/dev/null
421 code=$(curl -sS -o /dev/null -w '%{http_code}' -X PUT "$DIFFINERY/api/v3/repos/$OWNER/$Q/pulls/$n/merge" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" --data '{}')
422 [ "$code" = 405 ] || { echo "::error::a direct merge into a merge queue branch returned $code"; exit 1; }
423 api PUT "/repos/$OWNER/$Q/pulls/$n/merge-queue" '{"delete_branch":true}' | jq '{state, position: .entry.position, merge_group: .entry.merge_group}'
424 for i in $(seq 1 60); do
425 merged=$(api GET "/repos/$OWNER/$Q/pulls/$n" | jq -r .merged)
426 [ "$merged" = true ] && break
427 sleep 10
428 done
429 [ "$merged" = true ] || { echo "::error::the merge queue did not merge #$n"; api GET "/repos/$OWNER/$Q/merge-queue/main" | jq .; exit 1; }
430 group=$(wait_run merge_group)
431 echo "$group" | jq '{event, ref, sha, conclusion}'
432 [[ "$(jq -r .ref <<<"$group")" == refs/heads/gh-readonly-queue/main/pr-$n-* ]] || { echo "::error::the merge_group run is not on a queue branch"; exit 1; }
433 sha=$(api GET "/repos/$OWNER/$Q/branches/main" | jq -r .commit.sha)
434 [ "$sha" = "$(jq -r .sha <<<"$group")" ] || { echo "::error::main ($sha) is not the tested merge group"; exit 1; }
435 git fetch -q "$remote" main && [ "$(git show FETCH_HEAD:app.txt | tr '\n' ' ')" = "A b C " ] || { echo "::error::main does not hold the merged change"; exit 1; }
436 echo "pull request #$n merged through the queue as $sha"
437
438 - name: Scheduled workflow
439 if: steps.token.outputs.skip != 'true'
440 run: |
441 set -euo pipefail
442 # The cron trigger fires every 5 minutes, so allow two windows.
443 for i in $(seq 1 75); do
444 run=$(curl -fsS "$DIFFINERY/api/v3/repos/$OWNER/$REPO/actions/runs?event=schedule" -H "Authorization: Bearer $TOKEN" | jq -c '.workflow_runs[0] // empty')
445 [ -n "$run" ] && [ "$(jq -r .status <<<"$run")" = completed ] && break
446 sleep 10
447 done
448 [ -n "$run" ] || { echo "::error::no scheduled run started"; exit 1; }
449 echo "$run" | jq '{id, event, status, conclusion}'
450 [ "$(jq -r .conclusion <<<"$run")" = success ] || { echo "::error::the scheduled run did not succeed"; exit 1; }
451
452 - name: Delete the throwaway repositories
453 if: always() && steps.token.outputs.skip != 'true'
454 run: |
455 curl -sS -o /dev/null -w 'package %{http_code}\n' -X DELETE "$DIFFINERY/api/v3/users/$OWNER/packages/container/${REPO,,}" -H "Authorization: Bearer $TOKEN"
456 curl -sS -o /dev/null -w '%{http_code}\n' -X DELETE "$DIFFINERY/api/v3/repos/$OWNER/$REPO" -H "Authorization: Bearer $TOKEN"
457 [ -z "${PR_REPO:-}" ] || curl -sS -o /dev/null -w '%{http_code}\n' -X DELETE "$DIFFINERY/api/v3/repos/$OWNER/$PR_REPO" -H "Authorization: Bearer $TOKEN"