Skip to content

Commit 84004cd

Browse files
Copilotchenrui333
andcommitted
fix: gracefully fallback to body when body_path cannot be read
Co-authored-by: chenrui333 <[email protected]>
1 parent 9dc3c0d commit 84004cd

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

__tests__/util.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,52 @@ describe('util', () => {
110110
}),
111111
);
112112
});
113+
it('falls back to body when body_path is missing', () => {
114+
assert.equal(
115+
releaseBody({
116+
github_ref: '',
117+
github_repository: '',
118+
github_token: '',
119+
input_body: 'fallback-body',
120+
input_body_path: '__tests__/does-not-exist.txt',
121+
input_draft: false,
122+
input_prerelease: false,
123+
input_files: [],
124+
input_overwrite_files: undefined,
125+
input_preserve_order: undefined,
126+
input_name: undefined,
127+
input_tag_name: undefined,
128+
input_target_commitish: undefined,
129+
input_discussion_category_name: undefined,
130+
input_generate_release_notes: false,
131+
input_make_latest: undefined,
132+
}),
133+
'fallback-body',
134+
);
135+
});
136+
it('returns undefined when body_path is missing and body is not provided', () => {
137+
assert.equal(
138+
releaseBody({
139+
github_ref: '',
140+
github_repository: '',
141+
github_token: '',
142+
input_body: undefined,
143+
input_body_path: '__tests__/does-not-exist.txt',
144+
input_draft: false,
145+
input_prerelease: false,
146+
input_files: [],
147+
input_overwrite_files: undefined,
148+
input_preserve_order: undefined,
149+
input_name: undefined,
150+
input_tag_name: undefined,
151+
input_target_commitish: undefined,
152+
input_discussion_category_name: undefined,
153+
input_generate_release_notes: false,
154+
input_make_latest: undefined,
155+
}),
156+
undefined,
157+
);
158+
});
113159
});
114160
describe('parseConfig', () => {
115161
it('parses basic config', () => {

src/util.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ export const uploadUrl = (url: string): string => {
3535
};
3636

3737
export const releaseBody = (config: Config): string | undefined => {
38-
return (
39-
(config.input_body_path && readFileSync(config.input_body_path).toString('utf8')) ||
40-
config.input_body
41-
);
38+
if (config.input_body_path) {
39+
try {
40+
const contents = readFileSync(config.input_body_path, 'utf8');
41+
return contents;
42+
} catch (err: any) {
43+
console.warn(
44+
`⚠️ Failed to read body_path "${config.input_body_path}" (${err?.code ?? 'ERR'}). Falling back to 'body' input.`,
45+
);
46+
}
47+
}
48+
return config.input_body;
4249
};
4350

4451
type Env = { [key: string]: string | undefined };

0 commit comments

Comments
 (0)