summaryrefslogtreecommitdiff
path: root/.github/scripts/test-verify-linux-ci-image.sh
blob: 38348f5de69938a70fbce5fd40959f847e13e70f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
set -euo pipefail

fixture="$(mktemp -d)"
trap 'rm -rf "$fixture"' EXIT
mkdir -p "$fixture/prefix/pfunit/cmake" "$fixture/prefix/hamlib/lib"
touch "$fixture/prefix/pfunit/cmake/PFUNITConfig.cmake"
touch "$fixture/prefix/hamlib/lib/libhamlib.a"

# shellcheck source=.github/scripts/linux-ci-image-config.sh
. .github/scripts/linux-ci-image-config.sh
# shellcheck source=.github/scripts/tsan-linux-deps-config.sh
. .github/scripts/tsan-linux-deps-config.sh
recipe="$(.github/scripts/linux-ci-image-fingerprint.sh normal-noble)"
tsan_recipe="$(.github/scripts/linux-ci-image-fingerprint.sh tsan-noble)"
manifest="$fixture/image.env"
compiler=gcc
compiler_path="$(readlink -f "$(command -v "$compiler")")"
compiler_version="$($compiler -dumpfullversion -dumpversion)"
compiler_sha256="$(sha256sum "$compiler_path" | awk '{print $1}')"
compiler_target="$($compiler -dumpmachine)"
if command -v dpkg-query >/dev/null 2>&1; then
  package_sha256="$(dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort | sha256sum | awk '{print $1}')"
  toolchain_identity="$recipe:$compiler_target:$compiler_sha256:$package_sha256"
  toolchain_sha256="$(printf '%s' "$toolchain_identity" | sha256sum | awk '{print $1}')"
  toolchain_id="gcc${compiler_version}-x86_64-${toolchain_sha256:0:20}"
else
  package_sha256=0000000000000000000000000000000000000000000000000000000000000000
  toolchain_id=fixture
fi
compiler_major=${compiler_version%%.*}
ccache_compatibility_id="gcc${compiler_major}-v2"
compiler_signature_sha256=1111111111111111111111111111111111111111111111111111111111111111

write_manifest() {
  local hamlib_commit=${1:-$LINUX_HAMLIB_COMMIT}
  local recipe_sha=${2:-$recipe}
  local include_ccache_identity=${3:-true}
  {
    echo "schema=1"
    echo "flavor=normal"
    echo "architecture=x86_64"
    echo "generation=build-20260818-1-1"
    echo "compiler=$compiler"
    echo "compiler_version=$compiler_version"
    echo "compiler_sha256=$compiler_sha256"
    echo "compiler_target=$compiler_target"
    echo "package_sha256=$package_sha256"
    echo "toolchain_id=$toolchain_id"
    if [ "$include_ccache_identity" = true ]; then
      echo "ccache_compatibility_id=$ccache_compatibility_id"
      echo "compiler_signature_sha256=$compiler_signature_sha256"
    fi
    echo "hamlib_ref=$LINUX_HAMLIB_REF"
    echo "hamlib_commit=$hamlib_commit"
    echo "pfunit_version=$LINUX_PFUNIT_VERSION"
    echo "pfunit_commit=$LINUX_PFUNIT_COMMIT"
    echo "recipe_sha256=$recipe_sha"
  } > "$manifest"
}

run_verify() {
  local allow_stale_image=${1:-false}
  WSJTX_CI_IMAGE_MANIFEST="$manifest" \
    WSJTX_CI_PREFIX_OVERRIDE="$fixture/prefix" \
    WSJTX_CI_IMAGE_SKIP_RUNTIME_CHECKS=true \
    WSJTX_CI_IMAGE_ALLOW_RECIPE_MISMATCH="$allow_stale_image" \
    .github/scripts/verify-linux-ci-image.sh normal x86_64 "$LINUX_HAMLIB_REF"
}

write_manifest
run_verify >/dev/null

output="$fixture/output"
GITHUB_OUTPUT="$output" run_verify >/dev/null
grep -qx 'recipe_match=true' "$output"
grep -qx "ccache_compatibility_id=$ccache_compatibility_id" "$output"
grep -qx "ccache_compiler_check=string:$compiler_signature_sha256" "$output"

write_manifest "$LINUX_HAMLIB_COMMIT" "$recipe" false
if run_verify >/dev/null 2>&1; then
  echo "Expected a current image without ccache identity fields to fail" >&2
  exit 1
fi

write_manifest
printf '%s\n' 'compiler_signature_sha256=invalid' >> "$manifest"
if run_verify >/dev/null 2>&1; then
  echo "Expected an invalid compiler signature to fail" >&2
  exit 1
fi

write_manifest 0000000000000000000000000000000000000000
if run_verify >/dev/null 2>&1; then
  echo "Expected a mismatched Hamlib commit to fail" >&2
  exit 1
fi

write_manifest "$LINUX_HAMLIB_COMMIT" 0000000000000000000000000000000000000000000000000000000000000000 false
if run_verify >/dev/null 2>&1; then
  echo "Expected a mismatched recipe fingerprint to fail" >&2
  exit 1
fi
if ! run_verify true >/dev/null 2>&1; then
  echo "Expected stale image allowance to accept a mismatched recipe fingerprint" >&2
  exit 1
fi
output="$fixture/stale-output"
GITHUB_OUTPUT="$output" run_verify true >/dev/null 2>&1
grep -qx 'recipe_match=false' "$output"
grep -qx "ccache_compatibility_id=$toolchain_id" "$output"
grep -qx 'ccache_compiler_check=mtime' "$output"

tsan_config_dir="$fixture/tsan-config"
mkdir -p "$tsan_config_dir" "$fixture/prefix/tsan/boost/cmake"
cp .github/scripts/verify-linux-ci-image.sh \
  .github/scripts/linux-ccache-compiler-signature.sh \
  .github/scripts/linux-ci-image-config.sh \
  .github/scripts/tsan-linux-deps-config.sh \
  "$tsan_config_dir/"
cp .github/scripts/linux-ci-image-fingerprint.sh "$tsan_config_dir/"
cat > "$tsan_config_dir/verify-tsan-deps-linux.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
EOF
chmod +x "$tsan_config_dir/verify-tsan-deps-linux.sh"
touch "$fixture/prefix/tsan/boost/cmake/BoostConfig.cmake"

tsan_manifest="$fixture/tsan-image.env"
cat > "$tsan_manifest" <<EOF
schema=1
flavor=tsan
architecture=x86_64
generation=build-20260818-1-1
compiler=gcc-13
compiler_version=$TSAN_GCC_VERSION
compiler_sha256=0000000000000000000000000000000000000000000000000000000000000000
compiler_target=fixture
package_sha256=0000000000000000000000000000000000000000000000000000000000000000
toolchain_id=fixture
ccache_compatibility_id=gcc${TSAN_GCC_VERSION%%.*}-v2
compiler_signature_sha256=1111111111111111111111111111111111111111111111111111111111111111
hamlib_ref=$TSAN_HAMLIB_REF
hamlib_commit=$TSAN_HAMLIB_COMMIT
hamlib_patch_commit=$TSAN_HAMLIB_PATCH_COMMIT
qt_version=$TSAN_QT_VERSION
boost_version=$TSAN_BOOST_VERSION
recipe_sha256=$tsan_recipe
EOF
if ! WSJTX_CI_IMAGE_MANIFEST="$tsan_manifest" \
  WSJTX_CI_PREFIX_OVERRIDE="$fixture/prefix" \
  WSJTX_CI_IMAGE_SKIP_RUNTIME_CHECKS=true \
  IMAGE_RECIPE_SHA256="$tsan_recipe" \
  "$tsan_config_dir/verify-linux-ci-image.sh" \
    tsan x86_64 "$TSAN_HAMLIB_REF" >/dev/null; then
  echo "Expected TSan image verification to load its dependency configuration" >&2
  exit 1
fi

echo "verify-linux-ci-image.sh self-test passed"