Reserve Playwright CI ports
This commit is contained in:
+46
-44
@@ -181,28 +181,29 @@ jobs:
|
||||
*) echo "Unsupported Playwright PR project: $MATRIX_PROJECT" >&2; exit 1 ;;
|
||||
esac
|
||||
port_seed=$((20000 + (RUN_ID % 20000) + suite_offset + project_offset))
|
||||
playwright_dev_port="$(
|
||||
PORT_SEED="$port_seed" node - <<'NODE'
|
||||
const net = require("node:net");
|
||||
const start = Number(process.env.PORT_SEED || 20000);
|
||||
const candidates = Array.from({ length: 200 }, (_, index) => start + index);
|
||||
function tryPort(index) {
|
||||
if (index >= candidates.length) {
|
||||
console.error("Unable to find a free Playwright dev-server port.");
|
||||
process.exit(1);
|
||||
}
|
||||
const port = candidates[index];
|
||||
const server = net.createServer();
|
||||
server.once("error", () => tryPort(index + 1));
|
||||
server.listen(port, "127.0.0.1", () => {
|
||||
server.close(() => {
|
||||
console.log(port);
|
||||
});
|
||||
});
|
||||
}
|
||||
tryPort(0);
|
||||
NODE
|
||||
)"
|
||||
lock_root="${RUNNER_TEMP:-/tmp}/pleno-playwright-port-locks"
|
||||
mkdir -p "$lock_root"
|
||||
find "$lock_root" -mindepth 1 -maxdepth 1 -type d -mmin +360 -exec rmdir {} \; 2>/dev/null || true
|
||||
playwright_port_lock=""
|
||||
playwright_dev_port=""
|
||||
for ((candidate = port_seed; candidate < port_seed + 1000; candidate += 1)); do
|
||||
lock_dir="${lock_root}/${candidate}.lock"
|
||||
if ! mkdir "$lock_dir" 2>/dev/null; then
|
||||
continue
|
||||
fi
|
||||
if ss -H -ltn "sport = :${candidate}" 2>/dev/null | grep -q .; then
|
||||
rmdir "$lock_dir" || true
|
||||
continue
|
||||
fi
|
||||
playwright_port_lock="$lock_dir"
|
||||
playwright_dev_port="$candidate"
|
||||
break
|
||||
done
|
||||
if [[ -z "$playwright_dev_port" ]]; then
|
||||
echo "Unable to find a free Playwright dev-server port." >&2
|
||||
exit 1
|
||||
fi
|
||||
trap 'if [[ -n "${playwright_port_lock:-}" ]]; then rmdir "$playwright_port_lock" 2>/dev/null || true; fi' EXIT
|
||||
if docker info >/dev/null 2>&1; then
|
||||
docker_cmd=(docker)
|
||||
elif sudo -n docker info >/dev/null 2>&1; then
|
||||
@@ -335,28 +336,29 @@ jobs:
|
||||
*) echo "Unsupported Playwright device: $MATRIX_DEVICE" >&2; exit 1 ;;
|
||||
esac
|
||||
port_seed=$((20000 + (RUN_ID % 20000) + role_offset + browser_offset + device_offset))
|
||||
playwright_dev_port="$(
|
||||
PORT_SEED="$port_seed" node - <<'NODE'
|
||||
const net = require("node:net");
|
||||
const start = Number(process.env.PORT_SEED || 20000);
|
||||
const candidates = Array.from({ length: 200 }, (_, index) => start + index);
|
||||
function tryPort(index) {
|
||||
if (index >= candidates.length) {
|
||||
console.error("Unable to find a free Playwright dev-server port.");
|
||||
process.exit(1);
|
||||
}
|
||||
const port = candidates[index];
|
||||
const server = net.createServer();
|
||||
server.once("error", () => tryPort(index + 1));
|
||||
server.listen(port, "127.0.0.1", () => {
|
||||
server.close(() => {
|
||||
console.log(port);
|
||||
});
|
||||
});
|
||||
}
|
||||
tryPort(0);
|
||||
NODE
|
||||
)"
|
||||
lock_root="${RUNNER_TEMP:-/tmp}/pleno-playwright-port-locks"
|
||||
mkdir -p "$lock_root"
|
||||
find "$lock_root" -mindepth 1 -maxdepth 1 -type d -mmin +360 -exec rmdir {} \; 2>/dev/null || true
|
||||
playwright_port_lock=""
|
||||
playwright_dev_port=""
|
||||
for ((candidate = port_seed; candidate < port_seed + 1000; candidate += 1)); do
|
||||
lock_dir="${lock_root}/${candidate}.lock"
|
||||
if ! mkdir "$lock_dir" 2>/dev/null; then
|
||||
continue
|
||||
fi
|
||||
if ss -H -ltn "sport = :${candidate}" 2>/dev/null | grep -q .; then
|
||||
rmdir "$lock_dir" || true
|
||||
continue
|
||||
fi
|
||||
playwright_port_lock="$lock_dir"
|
||||
playwright_dev_port="$candidate"
|
||||
break
|
||||
done
|
||||
if [[ -z "$playwright_dev_port" ]]; then
|
||||
echo "Unable to find a free Playwright dev-server port." >&2
|
||||
exit 1
|
||||
fi
|
||||
trap 'if [[ -n "${playwright_port_lock:-}" ]]; then rmdir "$playwright_port_lock" 2>/dev/null || true; fi' EXIT
|
||||
if docker info >/dev/null 2>&1; then
|
||||
docker_cmd=(docker)
|
||||
elif sudo -n docker info >/dev/null 2>&1; then
|
||||
|
||||
Reference in New Issue
Block a user