| 1 | #!/usr/bin/env bash |
| 2 | # KVT fork: tests for the scripts in packaging/kvt (no network, no secrets). |
| 3 | set -euo pipefail |
| 4 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | work="$(mktemp -d)" |
| 6 | trap 'rm -rf "$work"' EXIT |
| 7 | fail() { echo "FAIL: $*" >&2; exit 1; } |
| 8 | sha="$(printf 'a%.0s' $(seq 64))" |
| 9 | commit="$(printf '0%.0s' $(seq 40))" |
| 10 | |
| 11 | # PKGBUILD: version, tag, checksum, provides/conflicts, marker file. |
| 12 | "$HERE/publish-aur.sh" --render v0.6.1-kvt.2 "$sha" "$work/aur" |
| 13 | p="$work/aur/PKGBUILD" |
| 14 | grep -qx 'pkgver=0.6.1.kvt.2' "$p" || fail "pkgver" |
| 15 | grep -qx '_tag=v0.6.1-kvt.2' "$p" || fail "_tag" |
| 16 | grep -qx "sha256sums=('$sha')" "$p" || fail "sha256sums" |
| 17 | grep -qx "provides=('rusty-teams')" "$p" || fail "provides" |
| 18 | grep -q "^conflicts=('rusty-teams'" "$p" || fail "conflicts" |
| 19 | grep -q '/usr/lib/rusty-teams/package-managed' "$p" || fail "package-managed marker" |
| 20 | grep -q 'rusty-teams.desktop' "$p" || fail "desktop file" |
| 21 | # shellcheck disable=SC1090 |
| 22 | ( source "$p"; [[ "${source[0]}" == "rusty-teams-0.6.1-kvt.2-linux-x86_64.tar.gz::https://git.kvt.nl/api/v1/projects/ict/rusty-teams/releases/v0.6.1-kvt.2/assets/rusty-teams-0.6.1-kvt.2-linux-x86_64.tar.gz" ]] ) || fail "source url" |
| 23 | ! "$HERE/publish-aur.sh" --render v0.6.1-kvt.2 nothex "$work/x" 2>/dev/null || fail "bad sha accepted" |
| 24 | ! "$HERE/publish-aur.sh" --render 0.6 "$sha" "$work/x" 2>/dev/null || fail "bad tag accepted" |
| 25 | [[ "$(grep -c '^pkgver=' "$HERE/aur/PKGBUILD")" == 1 ]] || fail "template pkgver" |
| 26 | |
| 27 | # No AUR key: a clear message and exit 0. |
| 28 | out="$(env -u AUR_SSH_PRIVATE_KEY -u AUR_SSH_PRIVATE_KEY_B64 "$HERE/publish-aur.sh" v0.6.1-kvt.2)" || fail "skip must exit 0" |
| 29 | grep -q 'overgeslagen' <<<"$out" || fail "skip message" |
| 30 | |
| 31 | # Release assets: versioned names, sums, the Windows exe only when it exists. |
| 32 | mkdir -p "$work/r/dist/kvt" |
| 33 | cd "$work/r" |
| 34 | echo linux > dist/kvt/teams-linux-amd64 |
| 35 | echo tar > dist/kvt/linux-x86_64.tar.gz |
| 36 | "$HERE/release-assets.sh" sums v0.6.1-kvt.2 >/dev/null 2>&1 |
| 37 | [[ "$(wc -l < dist/kvt/SHA256SUMS)" == 2 ]] || fail "sums without windows" |
| 38 | grep -q " rusty-teams-0.6.1-kvt.2-linux-amd64$" dist/kvt/SHA256SUMS || fail "linux sum name" |
| 39 | echo exe > dist/kvt/teams-windows-amd64.exe |
| 40 | "$HERE/release-assets.sh" sums v0.6.1-kvt.2 >/dev/null |
| 41 | [[ "$(wc -l < dist/kvt/SHA256SUMS)" == 3 ]] || fail "sums with windows" |
| 42 | (cd dist/kvt && cp teams-windows-amd64.exe rusty-teams-0.6.1-kvt.2-windows-amd64.exe && |
| 43 | grep windows SHA256SUMS | sha256sum -c - >/dev/null) || fail "windows sum" |
| 44 | json="$("$HERE/release-assets.sh" json v0.6.1-kvt.2 "$commit")" |
| 45 | python3 - "$json" <<'PY' || fail "release json" |
| 46 | import json, sys |
| 47 | body = json.loads(sys.argv[1]) |
| 48 | names = {a["name"]: (a["job"], a["path"]) for a in body["assets"]} |
| 49 | assert body["name"] == "v0.6.1-kvt.2" and len(body["commit"]) == 40 |
| 50 | assert names["rusty-teams-0.6.1-kvt.2-linux-amd64"] == ("linux_release", "dist/kvt/teams-linux-amd64") |
| 51 | assert names["rusty-teams-0.6.1-kvt.2-windows-amd64.exe"][0] == "windows_release" |
| 52 | assert names["SHA256SUMS"] == ("checksums", "dist/kvt/SHA256SUMS") |
| 53 | assert len(names) == 4 |
| 54 | PY |
| 55 | rm dist/kvt/teams-linux-amd64 |
| 56 | ! "$HERE/release-assets.sh" sums v0.6.1-kvt.2 2>/dev/null || fail "missing linux binary accepted" |
| 57 | |
| 58 | # CI cache helper: tarball round-trip (BlueGit caches files, not directories). |
| 59 | cachework="$(mktemp -d)" |
| 60 | mkdir -p "$cachework/cargo-home/registry/cache/demo" "$cachework/rustup-home/toolchains" |
| 61 | echo crate > "$cachework/cargo-home/registry/cache/demo/foo.crate" |
| 62 | echo rustc > "$cachework/rustup-home/toolchains/marker" |
| 63 | (cd "$cachework" && CARGO_HOME="$cachework/cargo-home" RUSTUP_HOME="$cachework/rustup-home" "$HERE/ci-cache.sh" save linux) |
| 64 | [[ -f "$cachework/.ci-cache/cargo-linux.tar.gz" ]] || fail "cache archive missing" |
| 65 | rm -rf "$cachework/cargo-home" "$cachework/rustup-home" |
| 66 | (cd "$cachework" && CARGO_HOME="$cachework/cargo-home" RUSTUP_HOME="$cachework/rustup-home" "$HERE/ci-cache.sh" restore linux) |
| 67 | [[ -f "$cachework/cargo-home/registry/cache/demo/foo.crate" ]] || fail "cache restore cargo" |
| 68 | [[ -f "$cachework/rustup-home/toolchains/marker" ]] || fail "cache restore rustup" |
| 69 | out="$(cd "$cachework" && "$HERE/ci-cache.sh" restore windows)" |
| 70 | grep -q 'Geen CI-cache' <<<"$out" || fail "missing windows cache message" |
| 71 | rm -rf "$cachework" |
| 72 | |
| 73 | # AUR source package: the tag and commit are filled in, and .SRCINFO (made without makepkg) |
| 74 | # equals the committed one. |
| 75 | SRC="$HERE/../aur-source" |
| 76 | srcsha="$(printf 'e%.0s' $(seq 40))" |
| 77 | "$SRC/publish.sh" --render v0.6.1-kvt.4 e972869751c189818d20930bebdb6a0156b16db1 "$work/src" || fail "aur-source render" |
| 78 | diff -q "$work/src/PKGBUILD" "$SRC/PKGBUILD" >/dev/null || fail "aur-source PKGBUILD is not rendered for v0.6.1-kvt.4" |
| 79 | diff -q "$work/src/.SRCINFO" "$SRC/.SRCINFO" >/dev/null || fail "aur-source .SRCINFO differs from the committed one" |
| 80 | "$SRC/publish.sh" --render v0.7.0-kvt.1 "$srcsha" "$work/src2" || fail "aur-source render 2" |
| 81 | grep -qx 'pkgver=0.7.0.kvt.1' "$work/src2/PKGBUILD" || fail "aur-source pkgver" |
| 82 | grep -qx '_tag=v0.7.0-kvt.1' "$work/src2/PKGBUILD" || fail "aur-source _tag" |
| 83 | grep -qx "_commit=$srcsha" "$work/src2/PKGBUILD" || fail "aur-source _commit" |
| 84 | grep -qP '^\tpkgver = 0\.7\.0\.kvt\.1$' "$work/src2/.SRCINFO" || fail "aur-source .SRCINFO pkgver" |
| 85 | ! "$SRC/publish.sh" --render 0.7 "$srcsha" "$work/x" 2>/dev/null || fail "aur-source bad tag accepted" |
| 86 | ! "$SRC/publish.sh" --render v0.7.0-kvt.1 abc "$work/x" 2>/dev/null || fail "aur-source bad commit accepted" |
| 87 | out="$(env -u AUR_SSH_PRIVATE_KEY -u AUR_SSH_PRIVATE_KEY_B64 "$SRC/publish.sh" v0.7.0-kvt.1 "$srcsha")" || fail "aur-source skip must exit 0" |
| 88 | grep -q 'overgeslagen' <<<"$out" || fail "aur-source skip message" |
| 89 | |
| 90 | echo "packaging/kvt tests: ok" |