Skip to content

Commit 12634ac

Browse files
committed
Improve strace output with better default options and detailed log headers
1 parent 4bceec0 commit 12634ac

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
with:
5656
action-ref: "actions/hello-world-javascript-action@main"
5757
enable-strace: "true"
58-
strace-options: "-f -e trace=open,close,network,write"
58+
strace-options: "-f -v -s 256 -e trace=file,process,network,signal,ipc,desc,memory"
5959
input-who-to-greet: "Strace"
6060

6161
- name: Check strace output

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
|-------|-------------|----------|---------|
2929
| `action-ref` | Reference to the nested action (e.g., owner/repo@ref) | Yes | |
3030
| `enable-strace` | Enable strace instrumentation | No | `true` |
31-
| `strace-options` | Options to pass to strace | No | `-f -e trace=network,write,open` |
31+
| `strace-options` | Options to pass to strace | No | `-f -v -s 256 -e trace=file,process,network,signal,ipc,desc,memory` |
3232
| `input-*` | Any input with the prefix `input-` will be passed to the nested action | No | |
3333
| `extra-args` | Extra arguments to pass to the nested action (deprecated, use `input-*` instead) | No | |
3434

@@ -43,7 +43,7 @@ To pass inputs to the nested action, prefix them with `input-`. For example:
4343

4444
| Output | Description |
4545
|--------|-------------|
46-
| `strace-log` | Path to the strace output log file (if strace was enabled and successful) |
46+
| `strace-log` | Path to the strace output log file. The filename includes timestamp and action name for easy identification. |
4747

4848
## Features
4949

@@ -111,11 +111,12 @@ To pass inputs to the nested action, prefix them with `input-`. For example:
111111
```yaml
112112
- name: Run with Strace
113113
id: strace-action
114-
uses: testifysec/action-wrapper@v2
114+
uses: testifysec/action-wrapper@v2.1.2
115115
with:
116116
action-ref: "actions/hello-world-javascript-action@main"
117117
enable-strace: "true"
118-
strace-options: "-f -e trace=network,write,open,close -o /tmp/trace.log"
118+
# Comprehensive tracing with improved verbosity
119+
strace-options: "-f -v -s 256 -e trace=file,process,network,signal,ipc,desc,memory"
119120
input-who-to-greet: "World" # Passed to the nested action as who-to-greet
120121
121122
- name: Upload Strace Results
@@ -125,6 +126,12 @@ To pass inputs to the nested action, prefix them with `input-`. For example:
125126
path: ${{ steps.strace-action.outputs.strace-log }}
126127
```
127128

129+
The strace log will include a helpful header with:
130+
- Action reference
131+
- Timestamp
132+
- Command executed
133+
- Strace options used
134+
128135
### Disabling Strace
129136

130137
```yaml

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
description: "Extra arguments to pass to the nested action (deprecated, use input-* instead)"
99
required: false
1010
strace-options:
11-
description: "Options to pass to strace (default: '-f -e trace=network,write,open')"
11+
description: "Options to pass to strace (default: '-f -v -s 256 -e trace=file,process,network,signal,ipc,desc,memory')"
1212
required: false
1313
enable-strace:
1414
description: "Enable strace instrumentation (default: true)"

index.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ async function run() {
4848
// Get inputs
4949
const actionRef = core.getInput("action-ref");
5050
const extraArgs = core.getInput("extra-args") || "";
51-
const straceOptions = core.getInput("strace-options") || "-f -e trace=network,write,open";
51+
// Improved default strace options for better insights
52+
const defaultStraceOptions = "-f -v -s 256 -e trace=file,process,network,signal,ipc,desc,memory";
53+
const straceOptions = core.getInput("strace-options") || defaultStraceOptions;
5254
const enableStrace = core.getInput("enable-strace").toLowerCase() === "true";
5355

5456
// Parse action-ref (expects format: owner/repo@ref)
@@ -223,8 +225,13 @@ async function processAction(actionDir, extraArgs) {
223225
// Parse strace options into an array
224226
const straceOptionsList = straceOptions.split(/\s+/).filter(Boolean);
225227

226-
// Create output file for strace results
227-
const stracelLogFile = path.join(process.env.GITHUB_WORKSPACE || '.', 'strace-output.log');
228+
// Create output file for strace results with timestamp and action name
229+
const repoName = repo.split("/")[1];
230+
const timestamp = new Date().toISOString().replace(/:/g, '-');
231+
const stracelLogFile = path.join(
232+
process.env.GITHUB_WORKSPACE || '.',
233+
`strace-${repoName}-${timestamp}.log`
234+
);
228235

229236
// Add output file option if not already specified
230237
if (!straceOptionsList.includes('-o') && !straceOptionsList.includes('--output')) {
@@ -259,6 +266,36 @@ async function processAction(actionDir, extraArgs) {
259266
const cp = await exec.getExecOutput("strace", [...straceOptionsList, "node", entryFile, ...args], options);
260267
core.debug(`Strace process completed with exit code: ${cp.exitCode}`);
261268

269+
// Add helpful headers to the strace log file
270+
if (fs.existsSync(stracelLogFile)) {
271+
// Create a temporary file for the header
272+
const headerFile = `${stracelLogFile}.header`;
273+
const header = `
274+
#=============================================================================
275+
# Strace log for GitHub Action: ${actionRef}
276+
# Date: ${new Date().toISOString()}
277+
# Command: node ${entryFile} ${args.join(" ")}
278+
# Options: ${straceOptions}
279+
#=============================================================================
280+
281+
`;
282+
fs.writeFileSync(headerFile, header);
283+
284+
// Concatenate the header and the original strace output
285+
const originalContent = fs.readFileSync(stracelLogFile);
286+
fs.writeFileSync(stracelLogFile, Buffer.concat([
287+
Buffer.from(header),
288+
originalContent
289+
]));
290+
291+
try {
292+
// Delete the temporary header file
293+
fs.unlinkSync(headerFile);
294+
} catch (error) {
295+
// Ignore any errors while deleting the temporary file
296+
}
297+
}
298+
262299
// Export the strace log path as an output
263300
core.setOutput("strace-log", stracelLogFile);
264301

0 commit comments

Comments
 (0)