-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: New growcut (fill) implementation #5954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wayfarer3130
wants to merge
6
commits into
master
Choose a base branch
from
fix/grow-cut-suv-pt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26336d3
New growcut (fill) implementation
wayfarer3130 0c5d373
Merge remote-tracking branch 'origin/master' into fix/grow-cut-suv-pt
wayfarer3130 2c7d718
Merge remote-tracking branch 'origin/master' into fix/grow-cut-suv-pt
wayfarer3130 9554d56
Use region plus fill tool
wayfarer3130 b342e4d
Teardown old e2e runs
wayfarer3130 be5773e
Move server kill to different phase
wayfarer3130 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /** | ||
| * Frees the OHIF Playwright e2e dev-server port before CI runs. | ||
| * Self-hosted runners (macOS and Linux) often leave `yarn start` / nyc processes | ||
| * bound to 3335 after cancelled or failed jobs, which makes Playwright fail with | ||
| * "http://localhost:3335 is already used". | ||
| */ | ||
| import { execSync } from 'node:child_process'; | ||
|
|
||
| const DEFAULT_E2E_PORT = 3335; | ||
|
|
||
| export function getOhifE2ePort() { | ||
| const port = Number(process.env.OHIF_PORT || DEFAULT_E2E_PORT); | ||
| if (!Number.isInteger(port) || port < 1 || port > 65535) { | ||
| throw new Error(`Invalid OHIF_PORT: ${process.env.OHIF_PORT}`); | ||
| } | ||
| return port; | ||
| } | ||
|
|
||
| function runQuiet(command) { | ||
| try { | ||
| return execSync(command, { | ||
| encoding: 'utf8', | ||
| stdio: ['ignore', 'pipe', 'ignore'], | ||
| }).trim(); | ||
| } catch { | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| function parsePidList(output) { | ||
| return [...new Set(output.split(/\s+/).filter(Boolean))]; | ||
| } | ||
|
|
||
| function parseSsListeningPids(output) { | ||
| const pids = []; | ||
| for (const match of output.matchAll(/pid=(\d+)/g)) { | ||
| pids.push(match[1]); | ||
| } | ||
| return [...new Set(pids)]; | ||
| } | ||
|
|
||
| function killPids(pids, port, method) { | ||
| const killed = []; | ||
|
|
||
| for (const pid of pids) { | ||
| try { | ||
| process.kill(Number(pid), 'SIGKILL'); | ||
| killed.push(pid); | ||
| } catch { | ||
| // Process may have already exited. | ||
| } | ||
| } | ||
|
|
||
| if (killed.length > 0) { | ||
| console.log( | ||
| `[free-ohif-e2e-port] Freed port ${port} via ${method}: killed PID(s) ${killed.join(', ')}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function getListeningPidsDarwin(port) { | ||
| // macOS: -sTCP:LISTEN is supported and avoids matching outbound connections. | ||
| const output = runQuiet(`lsof -nP -iTCP:${port} -sTCP:LISTEN -t`); | ||
| if (output) { | ||
| return { pids: parsePidList(output), method: 'lsof (darwin)' }; | ||
| } | ||
|
|
||
| const fallback = runQuiet(`lsof -nP -i :${port} -t`); | ||
| return { pids: parsePidList(fallback), method: 'lsof (darwin, fallback)' }; | ||
| } | ||
|
|
||
| function getListeningPidsLinux(port) { | ||
| // Prefer LISTEN filter when supported (util-linux / recent lsof). | ||
| let output = runQuiet(`lsof -nP -iTCP:${port} -sTCP:LISTEN -t`); | ||
| if (output) { | ||
| return { pids: parsePidList(output), method: 'lsof (linux)' }; | ||
| } | ||
|
|
||
| // Broader match — some Linux images lack -sTCP:LISTEN. | ||
| output = runQuiet(`lsof -nP -i :${port} -t`); | ||
| if (output) { | ||
| return { pids: parsePidList(output), method: 'lsof (linux, fallback)' }; | ||
| } | ||
|
|
||
| // iproute2 ss — common on minimal Linux runners without lsof. | ||
| output = runQuiet(`ss -H -lptn 'sport = :${port}'`); | ||
| const ssPids = parseSsListeningPids(output); | ||
| if (ssPids.length > 0) { | ||
| return { pids: ssPids, method: 'ss' }; | ||
| } | ||
|
|
||
| return { pids: [], method: null }; | ||
| } | ||
|
|
||
| function freePortLinuxWithFuser(port) { | ||
| try { | ||
| execSync(`fuser -k ${port}/tcp`, { stdio: 'ignore' }); | ||
| console.log(`[free-ohif-e2e-port] Freed port ${port} via fuser`); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function freeOhifE2ePortUnix(port) { | ||
| const { pids, method } = | ||
| process.platform === 'darwin' | ||
| ? getListeningPidsDarwin(port) | ||
| : getListeningPidsLinux(port); | ||
|
|
||
| if (pids.length > 0) { | ||
| killPids(pids, port, method); | ||
| return; | ||
| } | ||
|
|
||
| if (process.platform === 'linux') { | ||
| freePortLinuxWithFuser(port); | ||
| } | ||
| } | ||
|
|
||
| function freeOhifE2ePortWindows(port) { | ||
| const output = runQuiet( | ||
| `netstat -ano | findstr :${port} | findstr LISTENING` | ||
| ); | ||
|
|
||
| if (!output) { | ||
| return; | ||
| } | ||
|
|
||
| const pids = [ | ||
| ...new Set( | ||
| output | ||
| .split(/\r?\n/) | ||
| .map(line => line.trim().split(/\s+/).pop()) | ||
| .filter(Boolean) | ||
| ), | ||
| ]; | ||
|
|
||
| killPids(pids, port, 'netstat'); | ||
| } | ||
|
|
||
| export function freeOhifE2ePort(port = getOhifE2ePort()) { | ||
| const { platform } = process; | ||
|
|
||
| if (platform === 'darwin' || platform === 'linux') { | ||
| freeOhifE2ePortUnix(port); | ||
| return; | ||
| } | ||
|
|
||
| if (platform === 'win32') { | ||
| freeOhifE2ePortWindows(port); | ||
| } | ||
| } | ||
|
|
||
| const isDirectRun = | ||
| process.argv[1]?.replace(/\\/g, '/').endsWith('free-ohif-e2e-port.mjs') ?? false; | ||
|
|
||
| if (isDirectRun) { | ||
| freeOhifE2ePort(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.