summaryrefslogtreecommitdiff
path: root/.github/scripts/linux-artifact-validation.sh
blob: 01a607f673767ee69b6c4d45ac74886fcf3033eb (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
# Shared acceptance checks for Linux build products.

linux_validation_error() {
  echo "::error::$*" >&2
  return 1
}

validate_elf_metadata() {
  local arch="$1"
  local path="$2"
  local file_output="$3"
  local header_output="$4"
  local program_output="$5"

  case "$arch" in
    armhf)
      [[ "$file_output" == *"ELF 32-bit"* ]] || {
        linux_validation_error "$path is not ELF32"
        return 1
      }
      [[ "$file_output" == *"ARM, EABI5"* ]] || {
        linux_validation_error "$path is not ARM EABI5"
        return 1
      }
      [[ "$header_output" == *"Class:"*"ELF32"* ]] || {
        linux_validation_error "$path has the wrong ELF class for armhf"
        return 1
      }
      [[ "$header_output" == *"Machine:"*"ARM"* ]] || {
        linux_validation_error "$path has the wrong ELF machine for armhf"
        return 1
      }
      [[ "$header_output" == *"Version5 EABI"* ]] || {
        linux_validation_error "$path does not use EABI5"
        return 1
      }
      [[ "$header_output" == *"hard-float ABI"* ]] || {
        linux_validation_error "$path does not use the ARM hard-float ABI"
        return 1
      }
      if [[ "$file_output" == *"dynamically linked"* ]] &&
        [[ "$program_output" != *"/lib/ld-linux-armhf.so.3"* ]]; then
        linux_validation_error "$path does not request /lib/ld-linux-armhf.so.3"
        return 1
      fi
      ;;
    x86_64)
      [[ "$file_output" == *"ELF 64-bit"* && "$file_output" == *"x86-64"* ]] || {
        linux_validation_error "$path is not a 64-bit x86-64 ELF"
        return 1
      }
      ;;
    aarch64)
      [[ "$file_output" == *"ELF 64-bit"* && "$file_output" == *"ARM aarch64"* ]] || {
        linux_validation_error "$path is not a 64-bit AArch64 ELF"
        return 1
      }
      ;;
    *)
      linux_validation_error "Unsupported Linux architecture: $arch"
      return 2
      ;;
  esac
}

validate_elf_executable() {
  local arch="$1"
  local path="$2"
  local file_output
  local header_output
  local program_output

  if [ ! -x "$path" ]; then
    linux_validation_error "Required executable is missing: $path"
    return 1
  fi

  file_output=$(file -- "$path") || return
  header_output=$(readelf -hW -- "$path") || return
  program_output=$(readelf -lW -- "$path") || return
  echo "$file_output"
  validate_elf_metadata "$arch" "$path" "$file_output" "$header_output" "$program_output"
}

validate_linux_build_executables() {
  local build_dir="$1"
  local arch="$2"
  local executable

  for executable in wsjtx jt9 qmap/qmap map65/map65 ft8code wsprd; do
    validate_elf_executable "$arch" "$build_dir/$executable" || return
  done
}

linux_manifest_has_path() {
  local manifest="$1"
  local path="$2"
  case $'\n'"$manifest"$'\n' in
    *"$path"$'\n'*) return 0 ;;
    *) return 1 ;;
  esac
}

validate_linux_package_manifest() {
  local manifest="$1"
  local label="$2"
  local path

  for path in \
    /usr/bin/wsjtx \
    /usr/bin/jt9 \
    /usr/bin/qmap \
    /usr/bin/map65 \
    /usr/share/wsjtx/ALLCALL7.TXT \
    /usr/share/wsjtx/CALL3.TXT \
    /usr/share/wsjtx/sounds/Message.wav \
    /usr/share/wsjtx/sounds/Testing123.wav; do
    if ! linux_manifest_has_path "$manifest" "$path"; then
      linux_validation_error "$label is missing expected package path: $path"
      return 1
    fi
  done

  case $'\n'"$manifest"$'\n' in
    *"/usr/bin/sounds"$'\n'* | *"/usr/bin/sounds/"*)
      linux_validation_error "$label contains unexpected package path: /usr/bin/sounds"
      return 1
      ;;
  esac
}

validate_deb_package() {
  local package="$1"
  local manifest

  manifest=$(dpkg-deb --fsys-tarfile "$package" | tar -tf -) || return
  validate_linux_package_manifest "$manifest" "DEB $package"
}

validate_rpm_package() {
  local package="$1"
  local manifest

  manifest=$(rpm -qpl "$package") || return
  printf '%s\n' "$manifest" | sed -n '1,40p'
  validate_linux_package_manifest "$manifest" "RPM $package"
}

linux_require_executable() {
  local path="$1"
  if [ ! -x "$path" ]; then
    linux_validation_error "Required executable is missing: $path"
    return 1
  fi
}

linux_require_file() {
  local path="$1"
  if [ ! -f "$path" ]; then
    linux_validation_error "Required file is missing: $path"
    return 1
  fi
}

validate_linux_application_layout() {
  local root="$1"
  local kind="$2"
  local path

  for path in wsjtx jt9 qmap map65 ft8code; do
    linux_require_executable "$root/usr/bin/$path" || return
  done
  if [ "$kind" = appimage ]; then
    linux_require_executable "$root/usr/bin/wsprd" || return
  elif [ "$kind" != appdir ]; then
    linux_validation_error "Unknown application tree kind: $kind"
    return 2
  fi

  for path in \
    usr/share/wsjtx/ALLCALL7.TXT \
    usr/share/wsjtx/CALL3.TXT \
    usr/share/wsjtx/sounds/Message.wav \
    usr/share/wsjtx/sounds/Testing123.wav; do
    linux_require_file "$root/$path" || return
  done
  if [ -e "$root/usr/bin/sounds" ] || [ -L "$root/usr/bin/sounds" ]; then
    linux_validation_error "Unexpected executable-adjacent sounds path is present: $root/usr/bin/sounds"
    return 1
  fi

  if [ "$kind" = appdir ]; then
    linux_require_file "$root/usr/share/applications/wsjtx.desktop" || return
    linux_require_file "$root/usr/share/pixmaps/wsjtx_icon.png" || return
    return 0
  fi

  for path in \
    usr/bin/qt.conf \
    usr/plugins/platforms/libqxcb.so \
    usr/plugins/sqldrivers/libqsqlite.so; do
    linux_require_file "$root/$path" || return
  done
  if ! grep -Eq '^[[:space:]]*Plugins[[:space:]]*=[[:space:]]*plugins[[:space:]]*$' \
    "$root/usr/bin/qt.conf"; then
    linux_validation_error "AppImage qt.conf must set Plugins = plugins"
    echo "AppImage qt.conf contents:"
    cat "$root/usr/bin/qt.conf"
    return 1
  fi

  for path in libQt5Core.so libQt5Widgets.so libQt5Multimedia.so; do
    if [ -z "$(find "$root/usr/lib" -maxdepth 1 -name "$path*" -print -quit 2>/dev/null)" ]; then
      linux_validation_error "Required AppImage Qt library is missing: $path"
      return 1
    fi
  done

  if [ -z "$(find "$root" -path '*/plugins/audio/*.so' -print -quit 2>/dev/null)" ]; then
    linux_validation_error "No Qt audio backend plugin is bundled in the AppImage"
    echo "AppImage plugin tree:"
    find "$root" -path '*/plugins/*' -name '*.so' -print 2>/dev/null | sed -n '1,20p'
    return 1
  fi
}

validate_linux_application_tree() {
  local root="$1"
  local kind="$2"
  local arch="$3"
  local executable

  validate_linux_application_layout "$root" "$kind" || return
  for executable in wsjtx jt9 qmap map65 ft8code; do
    validate_elf_executable "$arch" "$root/usr/bin/$executable" || return
  done
  if [ "$kind" = appimage ]; then
    validate_elf_executable "$arch" "$root/usr/bin/wsprd" || return
    echo "Qt audio plugins bundled:"
    find "$root" -path '*/plugins/audio/*.so' -print 2>/dev/null
  fi
}

run_packaged_appimage_startup_smoke() {
  local appimage="$1"
  local log="$2"
  local status
  local runner=()
  if [ -n "${LINUX_APPIMAGE_RUNNER:-}" ]; then
    runner=("$LINUX_APPIMAGE_RUNNER")
  fi

  mkdir -p "$(dirname "$log")"
  if env \
    -u LD_LIBRARY_PATH \
    -u LD_PRELOAD \
    -u LD_AUDIT \
    -u QT_PLUGIN_PATH \
    -u QT_QPA_PLATFORM_PLUGIN_PATH \
    -u QML_IMPORT_PATH \
    -u QML2_IMPORT_PATH \
    APPIMAGE_EXTRACT_AND_RUN=1 \
    QT_QPA_PLATFORM=xcb \
    timeout --kill-after=5s 45s \
      xvfb-run -a -s "-screen 0 1280x1024x24" \
      "${runner[@]}" \
      "$appimage" \
      --startup-smoke-test \
      --rig-name CI-APPIMAGE-STARTUP \
      >"$log" 2>&1; then
    status=0
  else
    status=$?
  fi

  cat "$log"
  if [ "$status" -eq 124 ]; then
    linux_validation_error "AppImage startup smoke test timed out after 45 seconds"
    return 1
  fi
  if [ "$status" -ne 0 ]; then
    linux_validation_error "AppImage startup smoke test exited with status $status"
    return 1
  fi
  if ! grep -Fq "WSJT-X startup smoke test passed" "$log"; then
    linux_validation_error "AppImage exited successfully without the startup-smoke success marker"
    return 1
  fi
}