Skip to content

Commit 0b123e0

Browse files
committed
fix(ci): stream coverage comment payloads
1 parent 921a26e commit 0b123e0

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

.github/scripts/upsert-bot-comment.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ marker="${3:?missing marker}"
3333
body_file="${4:?missing body file}"
3434
update_only="${5:-}"
3535

36-
body="$(cat "${body_file}")"
36+
comment_payload() {
37+
jq -n --rawfile body "${body_file}" '{body: $body}'
38+
}
3739

3840
for _attempt in 1 2 3; do
3941
if bot_login="${BOT_LOGIN:-}" \
@@ -49,17 +51,18 @@ for _attempt in 1 2 3; do
4951
| select((.body // "") | contains($marker))]
5052
| last | .id // empty')"; then
5153
if [ -n "${existing_id}" ]; then
52-
if gh api --method PATCH \
54+
if comment_payload | gh api --method PATCH \
5355
"repos/${repo}/issues/comments/${existing_id}" \
54-
-f body="${body}" >/dev/null; then
56+
--input - >/dev/null; then
5557
echo "updated comment ${existing_id}"
5658
exit 0
5759
fi
5860
elif [ "${update_only}" = "--update-only" ]; then
5961
echo "no existing comment; nothing to update"
6062
exit 0
61-
elif gh api "repos/${repo}/issues/${number}/comments" \
62-
-f body="${body}" >/dev/null; then
63+
elif comment_payload | gh api --method POST \
64+
"repos/${repo}/issues/${number}/comments" \
65+
--input - >/dev/null; then
6366
echo "posted new comment"
6467
exit 0
6568
fi

.github/scripts/upsert-bot-comment.test.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ const here = dirname(fileURLToPath(import.meta.url));
3131
const script = join(here, 'upsert-bot-comment.sh');
3232
const MARKER = '<!-- test-marker -->';
3333

34-
function run(scenario, { updateOnly = false, botLogin = '' } = {}) {
34+
function run(
35+
scenario,
36+
{ updateOnly = false, botLogin = '', body = `${MARKER}\nhello` } = {},
37+
) {
3538
const dir = mkdtempSync(join(tmpdir(), 'upsert-bot-comment-'));
3639
const bin = join(dir, 'bin');
3740
mkdirSync(bin);
3841
const calls = join(dir, 'calls');
3942
writeFileSync(calls, '');
4043
const bodyFile = join(dir, 'body');
41-
writeFileSync(bodyFile, `${MARKER}\nhello`);
44+
writeFileSync(bodyFile, body);
4245
const write = (name, body) => {
4346
writeFileSync(join(bin, name), body);
4447
chmodSync(join(bin, name), 0o755);
@@ -49,6 +52,7 @@ function run(scenario, { updateOnly = false, botLogin = '' } = {}) {
4952
[
5053
'#!/bin/bash',
5154
'echo "$*" >> "$CALLS"',
55+
'if [[ "$*" == *"--input -"* ]]; then cat >/dev/null; fi',
5256
'n=$(grep -c "method GET" "$CALLS" || true)',
5357
'case "$*" in',
5458
' "api user"*)',
@@ -120,6 +124,15 @@ test('uses BOT_LOGIN when the token cannot access /user', () => {
120124
assert.doesNotMatch(r.calls, /api user/);
121125
});
122126

127+
test('streams large comment bodies through stdin', () => {
128+
const r = run('fresh', {
129+
body: `${MARKER}\n${'x'.repeat(200_000)}`,
130+
});
131+
assert.equal(r.code, 0);
132+
assert.match(r.calls, /--method POST .* --input -/);
133+
assert.doesNotMatch(r.calls, /body=/);
134+
});
135+
123136
test('PATCHes the existing bot-authored marker comment', () => {
124137
const r = run('existing-bot');
125138
assert.equal(r.code, 0);
@@ -149,7 +162,7 @@ test('--update-only is a no-op success when nothing exists', () => {
149162
assert.match(r.stdout, /nothing to update/);
150163
assert.doesNotMatch(r.calls, /--method PATCH/);
151164
// And no POST either: the only api writes would be comment creation.
152-
assert.doesNotMatch(r.calls, /issues\/42\/comments -f/);
165+
assert.doesNotMatch(r.calls, /--method POST/);
153166
});
154167

155168
test('a failed listing NEVER falls through to POST (retries, then PATCHes)', () => {
@@ -159,7 +172,7 @@ test('a failed listing NEVER falls through to POST (retries, then PATCHes)', ()
159172
const r = run('listing-fails-once');
160173
assert.equal(r.code, 0);
161174
assert.match(r.stdout, /updated comment 7/);
162-
assert.doesNotMatch(r.calls, /issues\/42\/comments -f/);
175+
assert.doesNotMatch(r.calls, /--method POST/);
163176
});
164177

165178
test('a persistently failing identity lookup exits 1 without writing', () => {

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ jobs:
944944
path: 'coverage_artifact' # Download to a specific directory
945945

946946
- name: 'Post Coverage Comment using Composite Action'
947+
continue-on-error: true
947948
uses: './.github/actions/post-coverage-comment' # Path to the composite action directory
948949
with:
949950
cli_json_file: 'coverage_artifact/cli/coverage/coverage-summary.json'

0 commit comments

Comments
 (0)