| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 5 | tmp_dir="$(mktemp -d)" |
| 6 | # CI saw `rm: cannot remove '.../checkout': Directory not empty` here: a |
| 7 | # detached `git maintenance run --auto` (spawned by the fixture's commit and |
| 8 | # pushes) was still writing into .git while the trap deleted it. Keep every |
| 9 | # git process in this fixture from spawning one, and retry once regardless. |
| 10 | export GIT_CONFIG_COUNT=2 |
| 11 | export GIT_CONFIG_KEY_0=maintenance.auto GIT_CONFIG_VALUE_0=false |
| 12 | export GIT_CONFIG_KEY_1=gc.auto GIT_CONFIG_VALUE_1=0 |
| 13 | trap 'rm -rf "${tmp_dir}" 2>/dev/null || { sleep 1; rm -rf "${tmp_dir}"; }' EXIT |
| 14 | |
| 15 | remote="${tmp_dir}/remote.git" |
| 16 | checkout="${tmp_dir}/checkout" |
| 17 | git init --bare --quiet "${remote}" |
| 18 | # GitHub's versions job intentionally uses a depth-1 checkout. A local clone |
| 19 | # of that checkout remains shallow, so this disposable remote must accept the |
| 20 | # fixture's tag without requiring history that the test never inspects. |
| 21 | git -C "${remote}" config receive.shallowUpdate true |
| 22 | git clone --quiet --no-hardlinks --no-tags "${repo_root}" "${checkout}" |
| 23 | git -C "${checkout}" remote set-url origin "${remote}" |
| 24 | git -C "${checkout}" config user.name "Release Test" |
| 25 | git -C "${checkout}" config user.email "release-test@example.invalid" |
| 26 | |
| 27 | release_sha="$(git -C "${checkout}" rev-parse HEAD)" |
| 28 | version="$(grep -E '^version = "' "${checkout}/Cargo.toml" | head -n1 | sed -E 's/^version = "([^"]+)".*/\1/')" |
| 29 | tag="v${version}" |
| 30 | git -C "${checkout}" tag "${tag}" |
| 31 | git -C "${checkout}" push --quiet origin "refs/tags/${tag}" |
| 32 | |
| 33 | "${checkout}/scripts/release/require-release-tag-checkout.sh" "${version}" |
| 34 | |
| 35 | printf 'dirty\n' >> "${checkout}/README.md" |
| 36 | if "${checkout}/scripts/release/require-release-tag-checkout.sh" \ |
| 37 | "${version}" >/dev/null 2>&1; then |
| 38 | echo "dirty checkout unexpectedly passed" >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | git -C "${checkout}" restore README.md |
| 42 | |
| 43 | git -C "${checkout}" commit --quiet --allow-empty -m branch-ahead |
| 44 | if "${checkout}/scripts/release/require-release-tag-checkout.sh" \ |
| 45 | "${version}" >/dev/null 2>&1; then |
| 46 | echo "branch-ahead checkout unexpectedly passed" >&2 |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | git -C "${checkout}" push --quiet --force origin "HEAD:refs/tags/${tag}" |
| 51 | git -C "${checkout}" checkout --quiet --detach "${release_sha}" |
| 52 | if "${checkout}/scripts/release/require-release-tag-checkout.sh" \ |
| 53 | "${version}" >/dev/null 2>&1; then |
| 54 | echo "remote-moved tag unexpectedly passed" >&2 |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
| 58 | echo "require-release-tag-checkout tests passed" |
| 59 |