Skip to content

Commit 85a7535

Browse files
committed
Improve input handling with input- prefix system and fix strace permissions
1 parent 9c6891a commit 85a7535

File tree

4 files changed

+70
-17
lines changed

4 files changed

+70
-17
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
with:
2727
action-ref: "actions/hello-world-javascript-action@main"
2828
enable-strace: "false"
29+
input-who-to-greet: "World"
2930

3031
test-strace:
3132
runs-on: ubuntu-latest
@@ -41,8 +42,12 @@ jobs:
4142
- name: Install dependencies
4243
run: npm ci
4344

44-
- name: Install strace
45-
run: sudo apt-get update && sudo apt-get install -y strace
45+
- name: Install strace and set permissions
46+
run: |
47+
sudo apt-get update
48+
sudo apt-get install -y strace
49+
# Set permissions to allow strace to work without privilege issues
50+
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope || true
4651
4752
- name: Test wrapper with strace
4853
id: strace-test
@@ -51,6 +56,7 @@ jobs:
5156
action-ref: "actions/hello-world-javascript-action@main"
5257
enable-strace: "true"
5358
strace-options: "-f -e trace=open,close,network,write"
59+
input-who-to-greet: "Strace"
5460

5561
- name: Check strace output
5662
run: |

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,29 @@ jobs:
1515
- name: Checkout
1616
uses: actions/checkout@v3
1717
- name: Run Nested Action via Wrapper
18-
uses: testifysec/action-wrapper@v1
18+
uses: testifysec/action-wrapper@v2
1919
with:
20-
action-ref: "owner/[email protected]"
21-
extra-args: "--foo bar"
20+
action-ref: "actions/hello-world-javascript-action@main"
21+
input-who-to-greet: "World" # Passed to the nested action as who-to-greet
22+
enable-strace: "true" # Enable strace instrumentation
2223
```
2324
2425
## Inputs
2526
2627
| Input | Description | Required | Default |
2728
|-------|-------------|----------|---------|
2829
| `action-ref` | Reference to the nested action (e.g., owner/repo@ref) | Yes | |
29-
| `extra-args` | Extra arguments to pass to the nested action | No | |
3030
| `enable-strace` | Enable strace instrumentation | No | `true` |
3131
| `strace-options` | Options to pass to strace | No | `-f -e trace=network,write,open` |
32+
| `input-*` | Any input with the prefix `input-` will be passed to the nested action | No | |
33+
| `extra-args` | Extra arguments to pass to the nested action (deprecated, use `input-*` instead) | No | |
34+
35+
### Passing Inputs to Nested Actions
36+
37+
To pass inputs to the nested action, prefix them with `input-`. For example:
38+
39+
- `input-who-to-greet: "World"` will be passed to the nested action as `who-to-greet: "World"`
40+
- `input-token: ${{ secrets.GITHUB_TOKEN }}` will be passed as `token: ${{ secrets.GITHUB_TOKEN }}`
3241

3342
## Outputs
3443

@@ -85,26 +94,29 @@ jobs:
8594
action-ref: "actions/hello-world-javascript-action@main"
8695
```
8796

88-
### Passing Arguments
97+
### Passing Inputs to the Nested Action
8998

9099
```yaml
91-
- name: Run with Arguments
92-
uses: testifysec/action-wrapper@v1
100+
- name: Run with Inputs
101+
uses: testifysec/action-wrapper@v2
93102
with:
94103
action-ref: "some/action@v1"
95-
extra-args: "--input1 value1 --input2 value2"
104+
input-username: "octocat"
105+
input-token: ${{ secrets.GITHUB_TOKEN }}
106+
input-repository: ${{ github.repository }}
96107
```
97108

98109
### Using with Strace
99110

100111
```yaml
101112
- name: Run with Strace
102113
id: strace-action
103-
uses: testifysec/action-wrapper@v1
114+
uses: testifysec/action-wrapper@v2
104115
with:
105116
action-ref: "actions/hello-world-javascript-action@main"
106117
enable-strace: "true"
107118
strace-options: "-f -e trace=network,write,open,close -o /tmp/trace.log"
119+
input-who-to-greet: "World" # Passed to the nested action as who-to-greet
108120
109121
- name: Upload Strace Results
110122
uses: actions/upload-artifact@v4
@@ -117,8 +129,9 @@ jobs:
117129

118130
```yaml
119131
- name: Run Without Strace
120-
uses: testifysec/action-wrapper@v1
132+
uses: testifysec/action-wrapper@v2
121133
with:
122134
action-ref: "actions/hello-world-javascript-action@main"
123135
enable-strace: "false"
136+
input-who-to-greet: "World" # Passed to the nested action as who-to-greet
124137
```

action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
description: "Reference to the nested action (e.g., owner/repo@ref)"
66
required: true
77
extra-args:
8-
description: "Extra arguments to pass to the nested action"
8+
description: "Extra arguments to pass to the nested action (deprecated, use input-* instead)"
99
required: false
1010
strace-options:
1111
description: "Options to pass to strace (default: '-f -e trace=network,write,open')"
@@ -14,6 +14,8 @@ inputs:
1414
description: "Enable strace instrumentation (default: true)"
1515
required: false
1616
default: "true"
17+
# Any input with the prefix 'input-' will be passed to the nested action
18+
# For example, input-who-to-greet will be passed as who-to-greet to the nested action
1719
outputs:
1820
strace-log:
1921
description: "Path to the strace output log file (if strace was enabled and successful)"

index.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,30 @@ async function processAction(actionDir, extraArgs) {
149149
await exec.exec("npm", ["install"], { cwd: actionDir });
150150
}
151151

152-
// Execute the nested action using Node.js
152+
// Get all inputs with 'input-' prefix and pass them to the nested action
153+
// We'll set these as environment variables that GitHub Actions uses
154+
const inputPrefix = 'input-';
155+
const nestedInputs = {};
156+
157+
// Get all inputs that start with 'input-'
158+
Object.keys(process.env)
159+
.filter(key => key.startsWith('INPUT_'))
160+
.forEach(key => {
161+
const inputName = key.substring(6).toLowerCase(); // Remove 'INPUT_' prefix
162+
if (inputName.startsWith(inputPrefix)) {
163+
const nestedInputName = inputName.substring(inputPrefix.length);
164+
nestedInputs[nestedInputName] = process.env[key];
165+
core.info(`Passing input '${nestedInputName}' to nested action`);
166+
}
167+
});
168+
169+
// Set environment variables for the nested action
170+
const envVars = { ...process.env };
171+
Object.keys(nestedInputs).forEach(name => {
172+
envVars[`INPUT_${name.toUpperCase()}`] = nestedInputs[name];
173+
});
174+
175+
// For backwards compatibility, also support the extra-args parameter
153176
const args = extraArgs.split(/\s+/).filter((a) => a); // split and remove empty strings
154177

155178
// Use strace if enabled and available
@@ -174,7 +197,10 @@ async function processAction(actionDir, extraArgs) {
174197
}
175198

176199
// Use strace to wrap the node process
177-
await exec.exec("strace", [...straceOptionsList, "node", entryFile, ...args], { cwd: actionDir });
200+
await exec.exec("strace", [...straceOptionsList, "node", entryFile, ...args], {
201+
cwd: actionDir,
202+
env: envVars
203+
});
178204

179205
// Export the strace log path as an output
180206
core.setOutput("strace-log", stracelLogFile);
@@ -183,12 +209,18 @@ async function processAction(actionDir, extraArgs) {
183209
// If strace is not available, fall back to running without it
184210
core.warning(`Strace is not available: ${error.message}`);
185211
core.info(`Executing nested action without strace: node ${entryFile} ${args.join(" ")}`);
186-
await exec.exec("node", [entryFile, ...args], { cwd: actionDir });
212+
await exec.exec("node", [entryFile, ...args], {
213+
cwd: actionDir,
214+
env: envVars
215+
});
187216
}
188217
} else {
189218
// Run without strace
190219
core.info(`Strace disabled. Executing nested action: node ${entryFile} ${args.join(" ")}`);
191-
await exec.exec("node", [entryFile, ...args], { cwd: actionDir });
220+
await exec.exec("node", [entryFile, ...args], {
221+
cwd: actionDir,
222+
env: envVars
223+
});
192224
}
193225
}
194226

0 commit comments

Comments
 (0)