Skip to content

Commit 022493c

Browse files
committed
refactor: update Socket Security workflow to manual dispatch with optional PR input and ensure proper Node.js task resource disposal.
1 parent aeb5f66 commit 022493c

File tree

2 files changed

+49
-46
lines changed

2 files changed

+49
-46
lines changed

.github/workflows/socket.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Socket Security GitHub Actions Workflow
2-
# This workflow runs Socket Security scans on every commit to any branch
3-
# It automatically detects git repository information and handles different event types
2+
# This workflow runs Socket Security scans manually
3+
# It is designed to be triggered via workflow_dispatch with an optional PR number
44

55
name: socket-security-workflow
66
run-name: Socket Security Github Action
77

88
on:
99
workflow_dispatch:
10-
# pull_request:
11-
# types: [opened, synchronize, reopened]
12-
# issue_comment:
13-
# types: [created]
10+
inputs:
11+
pr_number:
12+
description: 'PR number to target'
13+
required: false
14+
type: string
1415

1516
# Prevent concurrent runs for the same commit
1617
concurrency:
@@ -43,11 +44,12 @@ jobs:
4344
SOCKET_SECURITY_API_KEY: ${{ secrets.SOCKET_SECURITY_API_KEY }}
4445
GH_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4546
run: |
46-
# Determine PR number based on event type
47-
PR_NUMBER=0
48-
if [ "${{ github.event_name }}" == "pull_request" ]; then
47+
# Determine PR number based on event type or input
48+
PR_NUMBER="${{ inputs.pr_number || 0 }}"
49+
# Fallback logic if needed (though manual run usually implies input or 0)
50+
if [ "$PR_NUMBER" == "0" ] && [ "${{ github.event_name }}" == "pull_request" ]; then
4951
PR_NUMBER=${{ github.event.pull_request.number }}
50-
elif [ "${{ github.event_name }}" == "issue_comment" ]; then
52+
elif [ "$PR_NUMBER" == "0" ] && [ "${{ github.event_name }}" == "issue_comment" ]; then
5153
PR_NUMBER=${{ github.event.issue.number }}
5254
fi
5355

packages/nodejs/src/Task.ts

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
* @module
55
*/
66

7-
import {
8-
callback,
9-
createRunner,
10-
createUnknownError,
11-
type MainTask,
12-
} from "@evolu/common";
7+
import { callback, createRunner, createUnknownError, type MainTask } from '@evolu/common'
138

149
/**
1510
* Runs a main task with proper Node.js signal handling.
@@ -49,8 +44,8 @@ export const runMain =
4944
<D>(deps: D) =>
5045
(main: MainTask<D>): void => {
5146
void (async () => {
52-
await using run = createRunner(deps);
53-
const console = run.deps.console.child("process");
47+
await using run = createRunner(deps)
48+
const console = run.deps.console.child('process')
5449

5550
/**
5651
* "The correct use of 'uncaughtException' is to perform synchronous
@@ -63,38 +58,44 @@ export const runMain =
6358
* We log and initiate graceful shutdown.
6459
*/
6560
const handleError = (error: unknown): void => {
66-
console.error(createUnknownError(error));
61+
console.error(createUnknownError(error))
6762
// https://nodejs.org/api/process.html#processexitcode
68-
process.exitCode = 1;
69-
void run[Symbol.asyncDispose]();
70-
};
63+
process.exitCode = 1
64+
void run[Symbol.asyncDispose]()
65+
}
7166

72-
process.on("uncaughtException", handleError);
73-
process.on("unhandledRejection", handleError);
67+
process.on('uncaughtException', handleError)
68+
process.on('unhandledRejection', handleError)
7469

75-
const _ = await run(main);
70+
const result = await run(main)
7671
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
77-
await using _stack = _.ok ? (_.value ?? undefined) : undefined;
72+
const stack = result.ok ? (result.value ?? undefined) : undefined
7873

79-
await run(
80-
callback(({ ok }) => {
81-
// https://nodejs.org/api/process.html#signal-events
82-
process.on("SIGINT", ok); // Ctrl-C (all platforms)
83-
process.on("SIGTERM", ok); // OS/k8s/Docker termination (Unix)
84-
process.on("SIGHUP", ok); // Console close (Windows), terminal disconnect (Unix)
74+
try {
75+
await run(
76+
callback(({ ok }) => {
77+
// https://nodejs.org/api/process.html#signal-events
78+
process.on('SIGINT', ok) // Ctrl-C (all platforms)
79+
process.on('SIGTERM', ok) // OS/k8s/Docker termination (Unix)
80+
process.on('SIGHUP', ok) // Console close (Windows), terminal disconnect (Unix)
8581

86-
// TODO: Explain why it's important to use run.onAbort and not
87-
// unregister sooner (cli shows gracefull shutdown was terminated.)
88-
run.onAbort(() => {
89-
process.off("SIGINT", ok);
90-
process.off("SIGTERM", ok);
91-
process.off("SIGHUP", ok);
92-
});
93-
return undefined;
94-
}),
95-
);
82+
// TODO: Explain why it's important to use run.onAbort and not
83+
// unregister sooner (cli shows gracefull shutdown was terminated.)
84+
run.onAbort(() => {
85+
process.off('SIGINT', ok)
86+
process.off('SIGTERM', ok)
87+
process.off('SIGHUP', ok)
88+
})
89+
return undefined
90+
}),
91+
)
92+
} finally {
93+
if (stack) {
94+
await stack[Symbol.asyncDispose]()
95+
}
96+
}
9697

97-
process.off("uncaughtException", handleError);
98-
process.off("unhandledRejection", handleError);
99-
})();
100-
};
98+
process.off('uncaughtException', handleError)
99+
process.off('unhandledRejection', handleError)
100+
})()
101+
}

0 commit comments

Comments
 (0)