Skip to content

Commit 39015bf

Browse files
authored
Replace github-script with file-based approach to avoid large JSON output max limit (#177)
## Summary Replaces the `actions/github-script@v8` "Set results output" step with a file-based bash/node approach to avoid Linux's `ARG_MAX` limit when processing large JSON payloads (~138KB+). ## Problem The previous implementation interpolated large `filings` JSON directly as a CLI argument to `node` via `github-script`. This exceeded the `ARG_MAX` limit on Linux runners, causing: ``` An error occurred trying to start process 'node' ... Argument list too long ``` ## Changes 1. **Replaced `github-script@v8` step** with two bash steps: - A step that writes filings/fixings to temp files via heredocs (avoids CLI arg limits) - A step that processes the data via a node heredoc script and writes `scanner-results.json` 2. **Added `results_file` output** — a new composite action output pointing to the JSON file, for consumers that need to handle large datasets without output size limits. 3. **Switched cache saving** from the value-based `gh-cache/cache` action to the file-based `gh-cache/save` action, copying `scanner-results.json` to the cache key path first. ## Backward compatibility - The `results` output is still set via `GITHUB_OUTPUT` heredoc delimiter for existing consumers. - The new `results_file` output is additive and opt-in. [Staff only] Resolves github/accessibility#10354
2 parents 5bd8d26 + 1f361d5 commit 39015bf

File tree

2 files changed

+55
-21
lines changed

2 files changed

+55
-21
lines changed

.github/actions/gh-cache/cache/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ runs:
6363
echo "value<<EOF" >> $GITHUB_OUTPUT
6464
if [ -f "${{ inputs.key }}" ]; then
6565
cat "${{ inputs.key }}" >> $GITHUB_OUTPUT
66+
echo >> $GITHUB_OUTPUT
6667
echo "Outputted 'value=$(cat "${{ inputs.key }}")'"
6768
else
6869
echo "Skipped outputting 'value'"

action.yml

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ outputs:
5353
results:
5454
description: 'List of issues and pull requests filed (and their associated finding(s)), as stringified JSON'
5555
value: ${{ steps.results.outputs.results }}
56+
results_file:
57+
description: 'Path to a JSON file containing the results (use for large datasets to avoid output size limits)'
58+
value: ${{ steps.results.outputs.results_file }}
5659

5760
runs:
5861
using: 'composite'
@@ -132,38 +135,68 @@ runs:
132135
issues: ${{ steps.get_issues_from_filings.outputs.issues }}
133136
repository: ${{ inputs.repository }}
134137
token: ${{ inputs.token }}
138+
- name: Write filings and fixings to temp files
139+
shell: bash
140+
run: |
141+
cat > "$RUNNER_TEMP/filings.json" << 'FILINGS_HEREDOC_DELIMITER'
142+
${{ steps.file.outputs.filings || '[]' }}
143+
FILINGS_HEREDOC_DELIMITER
144+
145+
cat > "$RUNNER_TEMP/fixings.json" << 'FIXINGS_HEREDOC_DELIMITER'
146+
${{ steps.fix.outputs.fixings || '[]' }}
147+
FIXINGS_HEREDOC_DELIMITER
148+
135149
- name: Set results output
136150
id: results
137-
uses: actions/github-script@v8
138-
with:
139-
script: |
140-
const filings = ${{ steps.file.outputs.filings || '""' }} || [];
141-
const fixings = ${{ steps.fix.outputs.fixings || '""' }} || [];
142-
const fixingsByIssueUrl = fixings.reduce((acc, fixing) => {
143-
if (fixing.issue && fixing.issue.url) {
144-
acc[fixing.issue.url] = fixing;
145-
}
146-
return acc;
147-
}, {});
148-
const results = filings;
149-
for (const result of results) {
150-
if (result.issue && result.issue.url && fixingsByIssueUrl[result.issue.url]) {
151-
result.pullRequest = fixingsByIssueUrl[result.issue.url].pullRequest;
152-
}
151+
shell: bash
152+
run: |
153+
node << 'NODE_SCRIPT'
154+
const fs = require('fs');
155+
const path = require('path');
156+
const runnerTemp = process.env.RUNNER_TEMP;
157+
const filings = JSON.parse(fs.readFileSync(path.join(runnerTemp, 'filings.json'), 'utf8')) || [];
158+
const fixings = JSON.parse(fs.readFileSync(path.join(runnerTemp, 'fixings.json'), 'utf8')) || [];
159+
const fixingsByIssueUrl = fixings.reduce((acc, fixing) => {
160+
if (fixing.issue && fixing.issue.url) acc[fixing.issue.url] = fixing;
161+
return acc;
162+
}, {});
163+
for (const result of filings) {
164+
if (result.issue && result.issue.url && fixingsByIssueUrl[result.issue.url]) {
165+
result.pullRequest = fixingsByIssueUrl[result.issue.url].pullRequest;
153166
}
154-
core.setOutput('results', JSON.stringify(results));
155-
core.debug(`Results: ${JSON.stringify(results)}`);
167+
}
168+
const resultsPath = path.join(process.env.GITHUB_WORKSPACE, 'scanner-results.json');
169+
fs.writeFileSync(resultsPath, JSON.stringify(filings));
170+
NODE_SCRIPT
171+
172+
RESULTS_FILE="$GITHUB_WORKSPACE/scanner-results.json"
173+
174+
# Set results output (backward compat)
175+
{
176+
echo 'results<<__RESULTS_OUTPUT_DELIMITER__'
177+
cat "$RESULTS_FILE"
178+
echo
179+
echo '__RESULTS_OUTPUT_DELIMITER__'
180+
} >> "$GITHUB_OUTPUT"
181+
182+
# Set results_file output
183+
echo "results_file=$RESULTS_FILE" >> "$GITHUB_OUTPUT"
156184
- if: ${{ inputs.include_screenshots == 'true' }}
157185
name: Save screenshots
158186
uses: ./../../_actions/github/accessibility-scanner/current/.github/actions/gh-cache/save
159187
with:
160188
path: .screenshots
161189
token: ${{ inputs.token }}
190+
- name: Copy results to cache path
191+
shell: bash
192+
run: |
193+
mkdir -p "$(dirname '${{ inputs.cache_key }}')"
194+
cp "$GITHUB_WORKSPACE/scanner-results.json" "${{ inputs.cache_key }}"
195+
162196
- name: Save cached results
163-
uses: ./../../_actions/github/accessibility-scanner/current/.github/actions/gh-cache/cache
197+
uses: ./../../_actions/github/accessibility-scanner/current/.github/actions/gh-cache/save
164198
with:
165-
key: ${{ inputs.cache_key }}
166-
value: ${{ steps.results.outputs.results }}
199+
path: ${{ inputs.cache_key }}
167200
token: ${{ inputs.token }}
168201

169202
branding:

0 commit comments

Comments
 (0)