|
38 | 38 | with: |
39 | 39 | ts-file: .github/scripts/fetch-status.ts |
40 | 40 | node-version: '22' |
41 | | - args: ${{ toJson({ url: 'https://example.com/health' }) }} |
| 41 | + args: | |
| 42 | + { |
| 43 | + "url": "https://example.com/health" |
| 44 | + } |
42 | 45 |
|
43 | 46 | - name: Show result |
44 | 47 | run: echo '${{ steps.run.outputs.result }}' |
|
56 | 59 | | Name | Required | Default | Description | |
57 | 60 | | ------------------- | -------- | ---------: | -------------------------------------------------------------------------------------------- | |
58 | 61 | | `ts-file` | ✅ | — | Path to your TypeScript entry file (relative to `working-directory`). | |
59 | | -| `args` | | `"{}"` | JSON string passed as `args` to your script's default export. | |
| 62 | +| `args` | | `"{}"` | JSON string passed as `args` to your script's default export. Use multiline YAML format for complex objects. | |
60 | 63 | | `working-directory` | | `"."` | Directory where bundling and imports resolve; bundle outputs go to `./.github-script-build`. | |
61 | 64 | | `node-version` | | `"22"` | Node target for bundling (affects `esbuild --target=nodeXX`). | |
62 | 65 | | `esbuild-version` | | `"0.24.0"` | esbuild version used to bundle. | |
@@ -211,6 +214,36 @@ Cache key factors: |
211 | 214 |
|
212 | 215 | ## Usage patterns |
213 | 216 |
|
| 217 | +**Pass static arguments:** |
| 218 | + |
| 219 | +```yaml |
| 220 | +- uses: tkstang/github-typescript@v1 |
| 221 | + with: |
| 222 | + ts-file: .github/scripts/my-task.ts |
| 223 | + args: | |
| 224 | + { |
| 225 | + "environment": "production", |
| 226 | + "retries": 3, |
| 227 | + "endpoints": ["api1", "api2"] |
| 228 | + } |
| 229 | +``` |
| 230 | + |
| 231 | +**Pass dynamic arguments from step outputs:** |
| 232 | + |
| 233 | +```yaml |
| 234 | +- name: Get deployment info |
| 235 | + id: deploy |
| 236 | + run: | |
| 237 | + echo "version=1.2.3" >> $GITHUB_OUTPUT |
| 238 | + echo "region=us-east-1" >> $GITHUB_OUTPUT |
| 239 | + echo "config={\"database\":\"prod\",\"replicas\":3}" >> $GITHUB_OUTPUT |
| 240 | +
|
| 241 | +- uses: tkstang/github-typescript@v1 |
| 242 | + with: |
| 243 | + ts-file: .github/scripts/deploy.ts |
| 244 | + args: '${{ toJson(steps.deploy.outputs) }}' |
| 245 | +``` |
| 246 | + |
214 | 247 | **Return JSON result:** |
215 | 248 |
|
216 | 249 | ```yaml |
@@ -272,6 +305,26 @@ Cache key factors: |
272 | 305 |
|
273 | 306 | - **Cannot find module 'axios'** → ensure you installed deps where `working-directory` can see them and that the wrapper's build step sets `NODE_PATH` accordingly. |
274 | 307 | - **`TypeError: run is not a function`** → your script must **default export** a function (`export default async function run(...) {}`). |
| 308 | +- **YAML parsing errors with `args`** → for static objects, use multiline YAML format: |
| 309 | + ```yaml |
| 310 | + args: | |
| 311 | + { |
| 312 | + "key": "value", |
| 313 | + "array": ["item1", "item2"] |
| 314 | + } |
| 315 | + ``` |
| 316 | + For dynamic values from step outputs or variables, use quoted `toJson()`: |
| 317 | + ```yaml |
| 318 | + # Pass all step outputs as an object |
| 319 | + args: '${{ toJson(steps.previous.outputs) }}' |
| 320 | +
|
| 321 | + # Pass workflow variables |
| 322 | + args: '${{ toJson(vars) }}' |
| 323 | +
|
| 324 | + # If you need to parse a JSON string first, use fromJson() (but not with toJson()) |
| 325 | + # Example: steps.data.outputs.config = '{"key": "value"}' |
| 326 | + - run: echo "Key is ${{ fromJson(steps.data.outputs.config).key }}" |
| 327 | + ``` |
275 | 328 | - **Output too large** → use artifacts instead of step outputs, or switch `result-encoding` to `string` if you only need a short message. |
276 | 329 | - **Cache misses** → narrow `hashFiles(...)` to your scripts subdir and lockfile; keep Node/esbuild versions consistent. |
277 | 330 |
|
|
0 commit comments