| 1 | name: Live test |
| 2 | |
| 3 | # End-to-end checks against the real diffinery.com after each deploy: email |
| 4 | # sending, 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. |
| 11 | on: |
| 12 | workflow_dispatch: |
| 13 | workflow_run: |
| 14 | workflows: [Deploy] |
| 15 | types: [completed] |
| 16 | branches: [main] |
| 17 | |
| 18 | permissions: |
| 19 | contents: read |
| 20 | |
| 21 | concurrency: |
| 22 | group: live-test |
| 23 | cancel-in-progress: false |
| 24 | |
| 25 | jobs: |
| 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: Email sending is configured |
| 98 | if: steps.token.outputs.skip != 'true' |
| 99 | run: | |
| 100 | set -euo pipefail |
| 101 | s=$(curl -fsS "$DIFFINERY/api/v3/diffinery/admin/email" -H "Authorization: Bearer $TOKEN") |
| 102 | echo "$s" | jq '{sending, queue, from, last_24h}' |
| 103 | [ "$(jq -r .sending <<<"$s")" = true ] || { echo "::error::the Worker has no Email Sending binding"; exit 1; } |
| 104 | [ "$(jq -r .queue <<<"$s")" = true ] || { echo "::error::the Worker has no mail queue binding"; exit 1; } |
| 105 | failed=$(jq -r .last_24h.failed <<<"$s") |
| 106 | [ "$failed" = 0 ] || echo "::warning::$failed emails failed in the last 24 hours; see Settings -> Email in site administration" |
| 107 | |
| 108 | - name: Create a throwaway repository with a webhook |
| 109 | if: steps.token.outputs.skip != 'true' |
| 110 | run: | |
| 111 | set -euo pipefail |
| 112 | api() { curl -fsS -X "$1" "$DIFFINERY/api/v3$2" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" ${3:+--data "$3"}; } |
| 113 | api POST /user/repos "{\"name\":\"$REPO\",\"private\":true}" >/dev/null |
| 114 | api POST "/repos/$OWNER/$REPO/hooks" "{\"config\":{\"url\":\"$DIFFINERY/healthz\"},\"events\":[\"push\"]}" >/dev/null |
| 115 | echo "created $OWNER/$REPO" |
| 116 | |
| 117 | - name: Push workflows and an LFS file |
| 118 | if: steps.token.outputs.skip != 'true' |
| 119 | run: | |
| 120 | set -euo pipefail |
| 121 | mkdir -p src/.github/workflows && cd src |
| 122 | git init -q -b main |
| 123 | git config user.name "Live test" && git config user.email "live-test@diffinery.com" |
| 124 | git lfs install --local >/dev/null |
| 125 | git lfs track "*.bin" >/dev/null |
| 126 | head -c 3145728 /dev/urandom > blob.bin |
| 127 | sha256sum blob.bin | cut -d' ' -f1 > ../blob.sha |
| 128 | echo "# $REPO" > README.md |
| 129 | cat > .github/workflows/ci.yml <<'EOF' |
| 130 | on: push |
| 131 | jobs: |
| 132 | hosted: |
| 133 | runs-on: ubuntu-latest |
| 134 | strategy: |
| 135 | matrix: |
| 136 | n: [1, 2] |
| 137 | steps: |
| 138 | - uses: actions/checkout@v4 |
| 139 | - run: echo "live ok ${{ '${{' }} matrix.n }} $(cat README.md)" |
| 140 | docker: |
| 141 | runs-on: ubuntu-latest |
| 142 | services: |
| 143 | cache: |
| 144 | image: redis:7-alpine |
| 145 | ports: ["6379"] |
| 146 | options: --health-cmd "redis-cli ping" --health-interval 1s --health-retries 30 |
| 147 | steps: |
| 148 | - run: | |
| 149 | printf 'FROM alpine:3.20\nRUN echo built > /msg\nCMD ["cat", "/msg"]\n' > Dockerfile |
| 150 | docker build -q -t live-image . |
| 151 | echo "docker ok $(docker run --rm live-image)" |
| 152 | exec 3<>/dev/tcp/127.0.0.1/${{ '${{' }} job.services.cache.ports['6379'] }} |
| 153 | printf 'PING\r\n' >&3 |
| 154 | read -r line <&3 |
| 155 | echo "service ok ${line%$'\r'}" |
| 156 | # Container registry: a layer over Cloudflare's 100 MB request limit, pushed with |
| 157 | # the job's GITHUB_TOKEN, plus the docker/*-action route most ghcr.io workflows use. |
| 158 | publish: |
| 159 | runs-on: ubuntu-latest |
| 160 | permissions: |
| 161 | packages: write |
| 162 | steps: |
| 163 | - run: | |
| 164 | image="diffinery.com/${GITHUB_REPOSITORY,,}" |
| 165 | echo "${{ '${{' }} secrets.GITHUB_TOKEN }}" | docker login diffinery.com -u "${{ '${{' }} github.actor }}" --password-stdin |
| 166 | head -c 150000000 /dev/urandom > big.bin |
| 167 | sha256sum big.bin | cut -d' ' -f1 > big.sha |
| 168 | printf 'FROM scratch\nCOPY big.bin big.sha /\n' > Dockerfile |
| 169 | docker build -q -t "$image:live" . |
| 170 | docker push "$image:live" |
| 171 | echo "pushed $(cat big.sha)" |
| 172 | buildx: |
| 173 | runs-on: ubuntu-latest |
| 174 | permissions: |
| 175 | packages: write |
| 176 | steps: |
| 177 | - run: | |
| 178 | echo "IMAGE=diffinery.com/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" |
| 179 | head -c 120000000 /dev/urandom > big.bin |
| 180 | printf 'FROM scratch\nCOPY big.bin /\n' > Dockerfile |
| 181 | - uses: docker/setup-buildx-action@v3 |
| 182 | - uses: docker/login-action@v3 |
| 183 | with: |
| 184 | registry: diffinery.com |
| 185 | username: ${{ '${{' }} github.actor }} |
| 186 | password: ${{ '${{' }} secrets.GITHUB_TOKEN }} |
| 187 | - uses: docker/build-push-action@v6 |
| 188 | with: |
| 189 | context: . |
| 190 | push: true |
| 191 | tags: ${{ '${{' }} env.IMAGE }}:buildx |
| 192 | pull: |
| 193 | needs: [publish, buildx] |
| 194 | runs-on: ubuntu-latest |
| 195 | permissions: |
| 196 | packages: read |
| 197 | steps: |
| 198 | - run: | |
| 199 | image="diffinery.com/${GITHUB_REPOSITORY,,}" |
| 200 | echo "${{ '${{' }} secrets.GITHUB_TOKEN }}" | docker login diffinery.com -u "${{ '${{' }} github.actor }}" --password-stdin |
| 201 | docker pull -q "$image:live" |
| 202 | id=$(docker create "$image:live" true) |
| 203 | docker cp "$id:/big.bin" big.bin && docker cp "$id:/big.sha" big.sha |
| 204 | [ "$(sha256sum big.bin | cut -d' ' -f1)" = "$(cat big.sha)" ] && echo "registry ok $(stat -c %s big.bin) bytes" |
| 205 | docker pull -q "$image:buildx" |
| 206 | id=$(docker create "$image:buildx" true) |
| 207 | docker cp "$id:/big.bin" buildx.bin |
| 208 | echo "buildx ok $(stat -c %s buildx.bin) bytes" |
| 209 | EOF |
| 210 | cat > .github/workflows/tick.yml <<'EOF' |
| 211 | on: |
| 212 | schedule: |
| 213 | - cron: "*/5 * * * *" |
| 214 | jobs: |
| 215 | tick: |
| 216 | runs-on: ubuntu-latest |
| 217 | steps: |
| 218 | - run: echo "scheduled ok" |
| 219 | EOF |
| 220 | git add -A && git commit -q -m "Live test" |
| 221 | git push -q "https://x-token:${TOKEN}@${DIFFINERY#https://}/$OWNER/$REPO.git" main |
| 222 | git lfs ls-files |
| 223 | |
| 224 | - name: Hosted Actions jobs (and Docker) run in Cloudflare Containers |
| 225 | if: steps.token.outputs.skip != 'true' |
| 226 | run: | |
| 227 | set -euo pipefail |
| 228 | api() { curl -fsS "$DIFFINERY/api/v3$1" -H "Authorization: Bearer $TOKEN"; } |
| 229 | for i in $(seq 1 90); do |
| 230 | run=$(api "/repos/$OWNER/$REPO/actions/runs?event=push" | jq -c '.workflow_runs[0] // empty') |
| 231 | [ -n "$run" ] && [ "$(jq -r .status <<<"$run")" = completed ] && break |
| 232 | sleep 10 |
| 233 | done |
| 234 | echo "$run" | jq '{id, status, conclusion}' |
| 235 | id=$(jq -r .id <<<"$run") |
| 236 | jobs=$(api "/repos/$OWNER/$REPO/actions/runs/$id/jobs") |
| 237 | jq -r '.jobs[] | " \(.name): \(.conclusion)\(if .failure then " - " + (.failure.message // "") else "" end)"' <<<"$jobs" |
| 238 | if [ "$(jq -r .conclusion <<<"$run")" != success ]; then |
| 239 | for job in $(jq -r '.jobs[] | select(.conclusion == "failure" or .conclusion == "timed_out") | .id' <<<"$jobs"); do |
| 240 | echo "::group::Last log lines of job $job" |
| 241 | api "/repos/$OWNER/$REPO/actions/jobs/$job/logs" | tail -n 80 || true |
| 242 | echo "::endgroup::" |
| 243 | done |
| 244 | echo "::error::the push run did not succeed" |
| 245 | exit 1 |
| 246 | fi |
| 247 | for job in $(jq -r '.jobs[] | select(.name | startswith("hosted")) | .id' <<<"$jobs"); do |
| 248 | log=$(api "/repos/$OWNER/$REPO/actions/jobs/$job/logs") |
| 249 | grep -F "live ok" <<<"$log" | grep -F "# $REPO" || { echo "::error::job $job did not print its line (checkout or run step failed)"; exit 1; } |
| 250 | done |
| 251 | job=$(jq -r '.jobs[] | select(.name == "docker") | .id' <<<"$jobs") |
| 252 | log=$(api "/repos/$OWNER/$REPO/actions/jobs/$job/logs") |
| 253 | grep -F "docker ok built" <<<"$log" || { echo "::error::docker build or run failed on a hosted runner"; exit 1; } |
| 254 | grep -F "service ok +PONG" <<<"$log" || { echo "::error::the redis service container was not reachable"; exit 1; } |
| 255 | job=$(jq -r '.jobs[] | select(.name == "pull") | .id' <<<"$jobs") |
| 256 | log=$(api "/repos/$OWNER/$REPO/actions/jobs/$job/logs") |
| 257 | 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; } |
| 258 | 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; } |
| 259 | api "/users/$OWNER/packages/container/${REPO,,}/versions" | jq -c '.[] | {tags: .metadata.container.tags, size, platforms}' |
| 260 | |
| 261 | - name: Git LFS round trip |
| 262 | if: steps.token.outputs.skip != 'true' |
| 263 | run: | |
| 264 | set -euo pipefail |
| 265 | git clone -q "https://x-token:${TOKEN}@${DIFFINERY#https://}/$OWNER/$REPO.git" clone |
| 266 | [ "$(sha256sum clone/blob.bin | cut -d' ' -f1)" = "$(cat blob.sha)" ] || { echo "::error::the LFS file came back different"; exit 1; } |
| 267 | echo "LFS file matches ($(stat -c %s clone/blob.bin) bytes)" |
| 268 | |
| 269 | - name: Webhook delivered |
| 270 | if: steps.token.outputs.skip != 'true' |
| 271 | run: | |
| 272 | set -euo pipefail |
| 273 | for i in $(seq 1 30); do |
| 274 | hook=$(curl -fsS "$DIFFINERY/api/v3/repos/$OWNER/$REPO/hooks" -H "Authorization: Bearer $TOKEN" | jq -c '.[0]') |
| 275 | # GitHub's hook shape: the target is config.url, the last delivery's status last_response.code. |
| 276 | [ "$(jq -r '.last_response.code // empty' <<<"$hook")" != "" ] && break |
| 277 | sleep 5 |
| 278 | done |
| 279 | echo "$hook" | jq '{target: .config.url, last_response, updated_at}' |
| 280 | [ "$(jq -r '.last_response.code // empty' <<<"$hook")" != "" ] || { echo "::error::the push webhook was never delivered"; exit 1; } |
| 281 | |
| 282 | - name: Agent sandbox |
| 283 | if: steps.token.outputs.skip != 'true' |
| 284 | run: | |
| 285 | set -euo pipefail |
| 286 | base="$DIFFINERY/api/v3/repos/$OWNER/$REPO/diffinery/sandboxes" |
| 287 | id=$(curl -fsS --retry 1 --retry-delay 15 -X POST "$base" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" --data '{}' | jq -r .id) |
| 288 | echo "sandbox $id" |
| 289 | for i in $(seq 1 40); do |
| 290 | 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) |
| 291 | jq -e '.exitCode == 0' >/dev/null 2>&1 <<<"$out" && break |
| 292 | sleep 6 |
| 293 | done |
| 294 | echo "$out" | jq '{exitCode, stdout}' |
| 295 | curl -sS -X POST "$base/$id/close" -H "Authorization: Bearer $TOKEN" >/dev/null || true |
| 296 | 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; } |
| 297 | |
| 298 | - name: Pull requests and the merge queue |
| 299 | if: steps.token.outputs.skip != 'true' |
| 300 | run: | |
| 301 | set -euo pipefail |
| 302 | Q="$REPO-pr" |
| 303 | api() { curl -fsS -X "$1" "$DIFFINERY/api/v3$2" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" ${3:+--data "$3"}; } |
| 304 | api POST /user/repos "{\"name\":\"$Q\",\"private\":true}" >/dev/null |
| 305 | echo "PR_REPO=$Q" >> "$GITHUB_ENV" |
| 306 | api PUT "/repos/$OWNER/$Q/actions/secrets/TOPSECRET" '{"value":"s3cret"}' >/dev/null |
| 307 | remote="https://x-token:${TOKEN}@${DIFFINERY#https://}/$OWNER/$Q.git" |
| 308 | mkdir -p pr/.github/workflows && cd pr |
| 309 | git init -q -b main |
| 310 | git config user.name "Live test" && git config user.email "live-test@diffinery.com" |
| 311 | printf 'a\nb\nc\n' > app.txt |
| 312 | cat > .github/workflows/ci.yml <<'EOF' |
| 313 | name: CI |
| 314 | on: |
| 315 | pull_request: |
| 316 | merge_group: |
| 317 | jobs: |
| 318 | test: |
| 319 | runs-on: ubuntu-latest |
| 320 | steps: |
| 321 | - uses: actions/checkout@v4 |
| 322 | - run: echo "pr ok event=${{ '${{' }} github.event_name }} ref=${{ '${{' }} github.ref }} sha=${{ '${{' }} github.sha }} head=$(git rev-parse HEAD) app=$(tr '\n' ' ' < app.txt)" |
| 323 | EOF |
| 324 | cat > .github/workflows/target.yml <<'EOF' |
| 325 | name: Target |
| 326 | on: pull_request_target |
| 327 | jobs: |
| 328 | t: |
| 329 | runs-on: ubuntu-latest |
| 330 | steps: |
| 331 | - run: echo "target ok secret=${{ '${{' }} secrets.TOPSECRET == 's3cret' }} ref=${{ '${{' }} github.ref }}" |
| 332 | EOF |
| 333 | git add -A && git commit -q -m "PR test" && git push -q "$remote" main |
| 334 | # The pull request changes app.txt and tries to rewrite the pull_request_target workflow. |
| 335 | git checkout -q -b change |
| 336 | printf 'A\nb\nc\n' > app.txt |
| 337 | sed -i 's/target ok/PWNED/' .github/workflows/target.yml |
| 338 | git commit -q -am "Change" && git push -q "$remote" change |
| 339 | head=$(git rev-parse HEAD) |
| 340 | # Main moves on, so the test merge commit holds both sides. |
| 341 | git checkout -q main |
| 342 | printf 'a\nb\nC\n' > app.txt |
| 343 | git commit -q -am "Main moves" && git push -q "$remote" main |
| 344 | n=$(api POST "/repos/$OWNER/$Q/pulls" '{"title":"Change","head":"change","base":"main"}' | jq -r .number) |
| 345 | echo "opened pull request #$n (head $head)" |
| 346 | |
| 347 | wait_run() { # event -> the completed run JSON |
| 348 | for i in $(seq 1 60); do |
| 349 | run=$(api GET "/repos/$OWNER/$Q/actions/runs?event=$1" | jq -c '.workflow_runs[0] // empty') |
| 350 | [ -n "$run" ] && [ "$(jq -r .status <<<"$run")" = completed ] && { echo "$run"; return; } |
| 351 | sleep 10 |
| 352 | done |
| 353 | echo "::error::no completed $1 run" >&2; exit 1 |
| 354 | } |
| 355 | 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; } |
| 356 | pr=$(wait_run pull_request) |
| 357 | echo "$pr" | jq '{event, ref, sha, head_sha, conclusion}' |
| 358 | [ "$(jq -r .conclusion <<<"$pr")" = success ] || { echo "::error::the pull_request run failed"; exit 1; } |
| 359 | [ "$(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; } |
| 360 | 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; } |
| 361 | target=$(wait_run pull_request_target) |
| 362 | echo "$target" | jq '{event, ref, sha, head_sha, conclusion}' |
| 363 | tlog=$(log_of "$(jq -r .id <<<"$target")") |
| 364 | 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; } |
| 365 | ! grep -q PWNED <<<"$tlog" || { echo "::error::pull_request_target ran the pull request's workflow"; exit 1; } |
| 366 | |
| 367 | api PUT "/repos/$OWNER/$Q/branches/main/protection" '{"requirePullRequest":true,"requiredChecks":["CI / test"],"mergeQueue":{"method":"squash","checkTimeoutMinutes":20}}' >/dev/null |
| 368 | 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 '{}') |
| 369 | [ "$code" = 405 ] || { echo "::error::a direct merge into a merge queue branch returned $code"; exit 1; } |
| 370 | api PUT "/repos/$OWNER/$Q/pulls/$n/merge-queue" '{"delete_branch":true}' | jq '{state, position: .entry.position, merge_group: .entry.merge_group}' |
| 371 | for i in $(seq 1 60); do |
| 372 | merged=$(api GET "/repos/$OWNER/$Q/pulls/$n" | jq -r .merged) |
| 373 | [ "$merged" = true ] && break |
| 374 | sleep 10 |
| 375 | done |
| 376 | [ "$merged" = true ] || { echo "::error::the merge queue did not merge #$n"; api GET "/repos/$OWNER/$Q/merge-queue/main" | jq .; exit 1; } |
| 377 | group=$(wait_run merge_group) |
| 378 | echo "$group" | jq '{event, ref, sha, conclusion}' |
| 379 | [[ "$(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; } |
| 380 | sha=$(api GET "/repos/$OWNER/$Q/branches/main" | jq -r .commit.sha) |
| 381 | [ "$sha" = "$(jq -r .sha <<<"$group")" ] || { echo "::error::main ($sha) is not the tested merge group"; exit 1; } |
| 382 | 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; } |
| 383 | echo "pull request #$n merged through the queue as $sha" |
| 384 | |
| 385 | - name: Scheduled workflow |
| 386 | if: steps.token.outputs.skip != 'true' |
| 387 | run: | |
| 388 | set -euo pipefail |
| 389 | # The cron trigger fires every 5 minutes, so allow two windows. |
| 390 | for i in $(seq 1 75); do |
| 391 | run=$(curl -fsS "$DIFFINERY/api/v3/repos/$OWNER/$REPO/actions/runs?event=schedule" -H "Authorization: Bearer $TOKEN" | jq -c '.workflow_runs[0] // empty') |
| 392 | [ -n "$run" ] && [ "$(jq -r .status <<<"$run")" = completed ] && break |
| 393 | sleep 10 |
| 394 | done |
| 395 | [ -n "$run" ] || { echo "::error::no scheduled run started"; exit 1; } |
| 396 | echo "$run" | jq '{id, event, status, conclusion}' |
| 397 | [ "$(jq -r .conclusion <<<"$run")" = success ] || { echo "::error::the scheduled run did not succeed"; exit 1; } |
| 398 | |
| 399 | - name: Delete the throwaway repositories |
| 400 | if: always() && steps.token.outputs.skip != 'true' |
| 401 | run: | |
| 402 | curl -sS -o /dev/null -w 'package %{http_code}\n' -X DELETE "$DIFFINERY/api/v3/users/$OWNER/packages/container/${REPO,,}" -H "Authorization: Bearer $TOKEN" |
| 403 | curl -sS -o /dev/null -w '%{http_code}\n' -X DELETE "$DIFFINERY/api/v3/repos/$OWNER/$REPO" -H "Authorization: Bearer $TOKEN" |
| 404 | [ -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" |