forked from baron/baron-sso
167 lines
4.8 KiB
Bash
Executable File
167 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
job_name="${1:-adminfront-tests}"
|
|
repo_root="$(pwd)"
|
|
tmp_dir=""
|
|
|
|
cleanup() {
|
|
if [ -n "${tmp_dir:-}" ] && [ -d "$tmp_dir" ]; then
|
|
rm -rf "$tmp_dir"
|
|
fi
|
|
}
|
|
|
|
trap cleanup EXIT INT TERM
|
|
|
|
mkdir -p reports
|
|
rm -rf adminfront/node_modules
|
|
|
|
tmp_dir="$(mktemp -d /tmp/baron-sso-adminfront-tests.XXXXXX)"
|
|
playwright_browsers_path="$tmp_dir/ms-playwright"
|
|
|
|
if command -v rsync >/dev/null 2>&1; then
|
|
rsync -rlptD --delete \
|
|
--exclude 'node_modules' \
|
|
--exclude 'playwright-report' \
|
|
--exclude 'test-results' \
|
|
"$repo_root/adminfront/" "$tmp_dir/adminfront/"
|
|
else
|
|
cp -R "$repo_root/adminfront" "$tmp_dir/adminfront"
|
|
rm -rf "$tmp_dir/adminfront/node_modules" \
|
|
"$tmp_dir/adminfront/playwright-report" \
|
|
"$tmp_dir/adminfront/test-results"
|
|
fi
|
|
|
|
is_port_available() {
|
|
local port="$1"
|
|
node -e '
|
|
const net = require("net");
|
|
const port = Number(process.argv[1]);
|
|
const server = net.createServer();
|
|
server.once("error", () => process.exit(1));
|
|
server.once("listening", () => server.close(() => process.exit(0)));
|
|
server.listen(port, "127.0.0.1");
|
|
' "$port"
|
|
}
|
|
|
|
find_available_port() {
|
|
node -e '
|
|
const net = require("net");
|
|
const server = net.createServer();
|
|
server.listen(0, "127.0.0.1", () => {
|
|
const address = server.address();
|
|
process.stdout.write(String(address.port));
|
|
server.close();
|
|
});
|
|
'
|
|
}
|
|
|
|
playwright_install_cmd=(npx playwright install)
|
|
playwright_install_desc="npx playwright install"
|
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
playwright_install_cmd=(npx playwright install --with-deps)
|
|
playwright_install_desc="npx playwright install --with-deps"
|
|
elif command -v sudo >/dev/null 2>&1 && sudo -n true >/dev/null 2>&1; then
|
|
playwright_install_cmd=(npx playwright install --with-deps)
|
|
playwright_install_desc="npx playwright install --with-deps"
|
|
fi
|
|
|
|
set +e
|
|
(
|
|
cd "$tmp_dir/adminfront"
|
|
npm ci --ignore-scripts
|
|
) 2>&1 | tee reports/adminfront-install.log
|
|
install_exit_code=${PIPESTATUS[0]}
|
|
set -e
|
|
|
|
if [ "$install_exit_code" -ne 0 ]; then
|
|
{
|
|
echo "# Adminfront Test Failure Report"
|
|
echo
|
|
echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`"
|
|
echo "- Job: \`${job_name}\`"
|
|
echo "- Reason: \`Dependency install failed\`"
|
|
echo "- Exit Code: \`$install_exit_code\`"
|
|
echo
|
|
echo "## Command"
|
|
echo "\`cd adminfront && npm ci --ignore-scripts\`"
|
|
echo
|
|
echo "## Install Log Tail (last 200 lines)"
|
|
echo '```text'
|
|
tail -n 200 reports/adminfront-install.log
|
|
echo '```'
|
|
} > reports/adminfront-test-failure-report.md
|
|
exit 1
|
|
fi
|
|
|
|
set +e
|
|
(
|
|
cd "$tmp_dir/adminfront"
|
|
PLAYWRIGHT_BROWSERS_PATH="$playwright_browsers_path" "${playwright_install_cmd[@]}"
|
|
) 2>&1 | tee reports/adminfront-provision.log
|
|
provision_exit_code=${PIPESTATUS[0]}
|
|
set -e
|
|
|
|
if [ "$provision_exit_code" -ne 0 ]; then
|
|
{
|
|
echo "# Adminfront Test Failure Report"
|
|
echo
|
|
echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`"
|
|
echo "- Job: \`${job_name}\`"
|
|
echo "- Reason: \`Browser provisioning failed\`"
|
|
echo "- Exit Code: \`$provision_exit_code\`"
|
|
echo
|
|
echo "## Command"
|
|
echo "\`cd adminfront && ${playwright_install_desc}\`"
|
|
echo
|
|
echo "## Provision Log Tail (last 200 lines)"
|
|
echo '```text'
|
|
tail -n 200 reports/adminfront-provision.log
|
|
echo '```'
|
|
} > reports/adminfront-test-failure-report.md
|
|
exit 1
|
|
fi
|
|
|
|
set +e
|
|
port="${PORT:-5180}"
|
|
if ! is_port_available "$port"; then
|
|
fallback_port="$(find_available_port)"
|
|
echo "==> requested PORT=$port is already in use; switching to PORT=$fallback_port"
|
|
port="$fallback_port"
|
|
fi
|
|
echo "==> adminfront using PORT=$port"
|
|
(
|
|
cd "$tmp_dir/adminfront"
|
|
PORT="$port" PLAYWRIGHT_WORKERS="${PLAYWRIGHT_WORKERS:-1}" PLAYWRIGHT_BROWSERS_PATH="$playwright_browsers_path" \
|
|
node ./node_modules/playwright/cli.js test
|
|
) 2>&1 | tee reports/adminfront-test.log
|
|
test_exit_code=${PIPESTATUS[0]}
|
|
set -e
|
|
|
|
[ -d "$tmp_dir/adminfront/playwright-report" ] && rm -rf reports/adminfront-playwright-report && cp -R "$tmp_dir/adminfront/playwright-report" reports/adminfront-playwright-report || true
|
|
[ -d "$tmp_dir/adminfront/test-results" ] && rm -rf reports/adminfront-test-results && cp -R "$tmp_dir/adminfront/test-results" reports/adminfront-test-results || true
|
|
|
|
if [ "$test_exit_code" -ne 0 ]; then
|
|
{
|
|
echo "# Adminfront Test Failure Report"
|
|
echo
|
|
echo "- Workflow: \`${GITHUB_WORKFLOW:-Code Check}\`"
|
|
echo "- Job: \`${job_name}\`"
|
|
echo "- Exit Code: \`$test_exit_code\`"
|
|
echo
|
|
echo "## Commands"
|
|
echo "1. \`cd adminfront\`"
|
|
echo "2. \`npm ci --ignore-scripts\`"
|
|
echo "3. \`${playwright_install_desc}\`"
|
|
echo "4. \`node ./node_modules/playwright/cli.js test\`"
|
|
echo
|
|
echo "## Log Tail (last 200 lines)"
|
|
echo '```text'
|
|
tail -n 200 reports/adminfront-test.log
|
|
echo '```'
|
|
} > reports/adminfront-test-failure-report.md
|
|
fi
|
|
|
|
exit "$test_exit_code"
|