| 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 | trap 'rm -rf "${tmp_dir}"' EXIT |
| 7 | |
| 8 | remote="${tmp_dir}/remote.git" |
| 9 | checkout="${tmp_dir}/checkout" |
| 10 | git init --bare --quiet "${remote}" |
| 11 | # GitHub's versions job intentionally uses a depth-1 checkout. A local clone |
| 12 | # of that checkout remains shallow, so this disposable remote must accept the |
| 13 | # fixture's tag without requiring history that the test never inspects. |
| 14 | git -C "${remote}" config receive.shallowUpdate true |
| 15 | git clone --quiet --no-hardlinks --no-tags "${repo_root}" "${checkout}" |
| 16 | git -C "${checkout}" remote set-url origin "${remote}" |
| 17 | git -C "${checkout}" config user.name "Release Test" |
| 18 | git -C "${checkout}" config user.email "release-test@example.invalid" |
| 19 | |
| 20 | release_sha="$(git -C "${checkout}" rev-parse HEAD)" |
| 21 | version="$(grep -E '^version = "' "${checkout}/Cargo.toml" | head -n1 | sed -E 's/^version = "([^"]+)".*/\1/')" |
| 22 | tag="v${version}" |
| 23 | git -C "${checkout}" tag "${tag}" |
| 24 | git -C "${checkout}" push --quiet origin "refs/tags/${tag}" |
| 25 | |
| 26 | "${checkout}/scripts/release/require-release-tag-checkout.sh" "${version}" |
| 27 | |
| 28 | printf 'dirty\n' >> "${checkout}/README.md" |
| 29 | if "${checkout}/scripts/release/require-release-tag-checkout.sh" \ |
| 30 | "${version}" >/dev/null 2>&1; then |
| 31 | echo "dirty checkout unexpectedly passed" >&2 |
| 32 | exit 1 |
| 33 | fi |
| 34 | git -C "${checkout}" restore README.md |
| 35 | |
| 36 | git -C "${checkout}" commit --quiet --allow-empty -m branch-ahead |
| 37 | if "${checkout}/scripts/release/require-release-tag-checkout.sh" \ |
| 38 | "${version}" >/dev/null 2>&1; then |
| 39 | echo "branch-ahead checkout unexpectedly passed" >&2 |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | git -C "${checkout}" push --quiet --force origin "HEAD:refs/tags/${tag}" |
| 44 | git -C "${checkout}" checkout --quiet --detach "${release_sha}" |
| 45 | if "${checkout}/scripts/release/require-release-tag-checkout.sh" \ |
| 46 | "${version}" >/dev/null 2>&1; then |
| 47 | echo "remote-moved tag unexpectedly passed" >&2 |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | echo "require-release-tag-checkout tests passed" |
| 52 |