POST_BUILD_CHECK: reworked to run everything from inside the flatpak, improved logging and output

This commit is contained in:
XargonWan 2024-12-10 11:11:32 +09:00
parent 9ff72f6381
commit 5211106b49

View file

@ -1,31 +1,65 @@
#!/bin/bash #!/bin/bash
# todo create launch test commands ie mame -help, ruffle --version # This script runs entirely inside the Flatpak sandbox for net.retrodeck.retrodeck
# Flatpak App ID
FLATPAK_APP_ID="net.retrodeck.retrodeck"
# Log file # Log file inside the Flatpak sandbox
LOG_FILE="$HOME/check.log" LOG_FILE="$HOME/retrodeck-post-build-check.log"
# Clear previous log # Clear previous log
> "$LOG_FILE" > "$LOG_FILE"
# Ensure global.sh is sourced inside the Flatpak sandbox
GLOBAL_SH_PATH="/app/libexec/global.sh"
# Check if the global.sh script exists
if ! flatpak run --command=ls "$FLATPAK_APP_ID" "$GLOBAL_SH_PATH" &> /dev/null; then
echo "✗ global.sh not found at $GLOBAL_SH_PATH" | tee -a "$LOG_FILE"
exit 1
fi
# Source global.sh to load the `features` variable
echo "Sourcing $GLOBAL_SH_PATH to load features" | tee -a "$LOG_FILE"
features=$(flatpak run --command=bash "$FLATPAK_APP_ID" -c "source $GLOBAL_SH_PATH && echo \$features")
# Ensure `features` variable is set
if [ -z "$features" ]; then
echo "✗ Failed to load features from $GLOBAL_SH_PATH" | tee -a "$LOG_FILE"
exit 1
fi
# Extract launch commands using jq # Extract launch commands using jq
commands=($(jq -r '.emulator | to_entries[] | .value.launch' /app/retrodeck/config/retrodeck/reference_lists/features.json)) echo "Extracting launch commands from $features" | tee -a "$LOG_FILE"
commands=($(flatpak run --command=jq "$FLATPAK_APP_ID" -r '.emulator | to_entries[] | .value.launch' "$features"))
echo "Extracted launch commands: ${commands[@]}" | tee -a "$LOG_FILE"
# Timeout duration in seconds # Timeout duration in seconds
TIMEOUT=5 TIMEOUT=3
# Function to run command with timeout # Function to run command with timeout
run_and_check() { run_and_check() {
local cmd="flatpak run net.retrodeck.retrodeck $1" local cmd="$1"
echo "Validating command: \"$cmd\"" | tee -a "$LOG_FILE"
# Verify command exists # Verify command exists within the Flatpak sandbox
if ! command -v "$cmd" &> /dev/null; then if ! flatpak run --command=which "$FLATPAK_APP_ID" "$cmd" &> /dev/null; then
echo "✗ Command not found: $cmd (Exit Code: 127)" | tee -a "$LOG_FILE" echo "✗ Command not found: $cmd (Exit Code: 127)" | tee -a "$LOG_FILE"
return 127 return 127
fi fi
# Run command with timeout # Run command with timeout inside the sandbox
timeout -s TERM $TIMEOUT "$cmd" flatpak run --command=timeout "$FLATPAK_APP_ID" -s TERM $TIMEOUT "$cmd" &> /dev/null &
local pid=$!
sleep $TIMEOUT
# Ensure the process is terminated
if kill -0 $pid 2>/dev/null; then
#echo "✗ $cmd did not terminate, killing process" | tee -a "$LOG_FILE"
kill -9 $pid
fi
local exit_code=$? local exit_code=$?
# Log the results # Log the results
@ -39,7 +73,7 @@ run_and_check() {
echo "$cmd terminated after $TIMEOUT seconds" | tee -a "$LOG_FILE" echo "$cmd terminated after $TIMEOUT seconds" | tee -a "$LOG_FILE"
;; ;;
137) 137)
echo "$cmd killed" | tee -a "$LOG_FILE" echo "$cmd killed after timeout" | tee -a "$LOG_FILE"
;; ;;
*) *)
echo "$cmd failed" | tee -a "$LOG_FILE" echo "$cmd failed" | tee -a "$LOG_FILE"
@ -49,7 +83,11 @@ run_and_check() {
return $exit_code return $exit_code
} }
# Execute commands # Execute commands inside the Flatpak sandbox
for cmd in "${commands[@]}"; do for cmd in "${commands[@]}"; do
run_and_check "$cmd" run_and_check "$cmd"
done done
echo "$LOG_FILE"
grep "✗" "$LOG_FILE"