BlueGit

ict rusty-teams

Files

rusty-teams / packaging / kvt / tests.sh

tests.sh

tests.sh 5.5 KiB Download Raw
1#!/usr/bin/env bash
2# KVT fork: tests for the scripts in packaging/kvt (no network, no secrets).
3set -euo pipefail
4HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5work="$(mktemp -d)"
6trap 'rm -rf "$work"' EXIT
7fail() { echo "FAIL: $*" >&2; exit 1; }
8sha="$(printf 'a%.0s' $(seq 64))"
9commit="$(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"
13p="$work/aur/PKGBUILD"
14grep -qx 'pkgver=0.6.1.kvt.2' "$p" || fail "pkgver"
15grep -qx '_tag=v0.6.1-kvt.2' "$p" || fail "_tag"
16grep -qx "sha256sums=('$sha')" "$p" || fail "sha256sums"
17grep -qx "provides=('rusty-teams')" "$p" || fail "provides"
18grep -q "^conflicts=('rusty-teams'" "$p" || fail "conflicts"
19grep -q '/usr/lib/rusty-teams/package-managed' "$p" || fail "package-managed marker"
20grep -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.
28out="$(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"
29grep -q 'overgeslagen' <<<"$out" || fail "skip message"
30
31# Release assets: versioned names, sums, the Windows exe only when it exists.
32mkdir -p "$work/r/dist/kvt"
33cd "$work/r"
34echo linux > dist/kvt/teams-linux-amd64
35echo 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"
38grep -q " rusty-teams-0.6.1-kvt.2-linux-amd64$" dist/kvt/SHA256SUMS || fail "linux sum name"
39echo 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"
44json="$("$HERE/release-assets.sh" json v0.6.1-kvt.2 "$commit")"
45python3 - "$json" <<'PY' || fail "release json"
46import json, sys
47body = json.loads(sys.argv[1])
48names = {a["name"]: (a["job"], a["path"]) for a in body["assets"]}
49assert body["name"] == "v0.6.1-kvt.2" and len(body["commit"]) == 40
50assert names["rusty-teams-0.6.1-kvt.2-linux-amd64"] == ("linux_release", "dist/kvt/teams-linux-amd64")
51assert names["rusty-teams-0.6.1-kvt.2-windows-amd64.exe"][0] == "windows_release"
52assert names["SHA256SUMS"] == ("checksums", "dist/kvt/SHA256SUMS")
53assert len(names) == 4
54PY
55rm 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).
59cachework="$(mktemp -d)"
60mkdir -p "$cachework/cargo-home/registry/cache/demo" "$cachework/rustup-home/toolchains"
61echo crate > "$cachework/cargo-home/registry/cache/demo/foo.crate"
62echo 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"
65rm -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"
69out="$(cd "$cachework" && "$HERE/ci-cache.sh" restore windows)"
70grep -q 'Geen CI-cache' <<<"$out" || fail "missing windows cache message"
71rm -rf "$cachework"
72
73# AUR source package: the tag and commit are filled in, and .SRCINFO (made without makepkg)
74# equals the committed one.
75SRC="$HERE/../aur-source"
76srcsha="$(printf 'e%.0s' $(seq 40))"
77"$SRC/publish.sh" --render v0.6.1-kvt.4 e972869751c189818d20930bebdb6a0156b16db1 "$work/src" || fail "aur-source render"
78diff -q "$work/src/PKGBUILD" "$SRC/PKGBUILD" >/dev/null || fail "aur-source PKGBUILD is not rendered for v0.6.1-kvt.4"
79diff -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"
81grep -qx 'pkgver=0.7.0.kvt.1' "$work/src2/PKGBUILD" || fail "aur-source pkgver"
82grep -qx '_tag=v0.7.0-kvt.1' "$work/src2/PKGBUILD" || fail "aur-source _tag"
83grep -qx "_commit=$srcsha" "$work/src2/PKGBUILD" || fail "aur-source _commit"
84grep -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"
87out="$(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"
88grep -q 'overgeslagen' <<<"$out" || fail "aur-source skip message"
89
90echo "packaging/kvt tests: ok"