| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | repo_root="$(git rev-parse --show-toplevel)" |
| 5 | test_root="$(mktemp -d "${TMPDIR:-/tmp}/reasonix-push-ci-test.XXXXXX")" |
| 6 | trap 'rm -rf -- "$test_root"' EXIT |
| 7 | |
| 8 | git -C "$test_root" init -q |
| 9 | git -C "$test_root" config user.name test |
| 10 | git -C "$test_root" config user.email test@example.invalid |
| 11 | printf 'code\n' >"$test_root/product.txt" |
| 12 | git -C "$test_root" add product.txt |
| 13 | git -C "$test_root" commit -qm code |
| 14 | code_sha="$(git -C "$test_root" rev-parse HEAD)" |
| 15 | mkdir -p "$test_root/release-notes" |
| 16 | printf '{}\n' >"$test_root/release-notes/releases.json" |
| 17 | git -C "$test_root" add release-notes/releases.json |
| 18 | git -C "$test_root" commit -qm notes |
| 19 | notes_sha="$(git -C "$test_root" rev-parse HEAD)" |
| 20 | |
| 21 | mkdir -p "$test_root/bin" |
| 22 | cat >"$test_root/bin/gh" <<'SH' |
| 23 | #!/usr/bin/env bash |
| 24 | set -euo pipefail |
| 25 | sha="" |
| 26 | while [ "$#" -gt 0 ]; do |
| 27 | if [ "$1" = --commit ]; then sha="$2"; shift 2; else shift; fi |
| 28 | done |
| 29 | [ -n "$sha" ] |
| 30 | printf '%s\n' "$sha" >>"$GH_QUERY_LOG" |
| 31 | printf '[{"headSha":"%s","status":"completed","conclusion":"success"}]\n' "$sha" |
| 32 | SH |
| 33 | chmod +x "$test_root/bin/gh" |
| 34 | |
| 35 | run_verify() { |
| 36 | local sha="$1" |
| 37 | : >"$test_root/queries" |
| 38 | ( |
| 39 | cd "$test_root" |
| 40 | PATH="$test_root/bin:$PATH" GH_QUERY_LOG="$test_root/queries" \ |
| 41 | RELEASE_CI_WAIT_SECONDS=0 RELEASE_CI_POLL_SECONDS=1 \ |
| 42 | bash "$repo_root/scripts/verify-release-push-ci.sh" "$sha" |
| 43 | ) |
| 44 | } |
| 45 | |
| 46 | run_verify "$notes_sha" |
| 47 | [ "$(cat "$test_root/queries")" = "$code_sha" ] |
| 48 | |
| 49 | run_verify "$code_sha" |
| 50 | [ "$(cat "$test_root/queries")" = "$code_sha" ] |
| 51 | |
| 52 | printf 'changed\n' >>"$test_root/product.txt" |
| 53 | git -C "$test_root" add product.txt |
| 54 | git -C "$test_root" commit -qm mixed |
| 55 | mixed_sha="$(git -C "$test_root" rev-parse HEAD)" |
| 56 | run_verify "$mixed_sha" |
| 57 | [ "$(cat "$test_root/queries")" = "$mixed_sha" ] |
| 58 |