Skip to content

Commit 8cfe36f

Browse files
author
FTMahringer
committed
fix(workflow): handle missing release-notes directory gracefully
Add defensive error handling for 404 responses: - collectTags() returns [] if docs/release-notes missing - syncRelease() skips tag if notes file missing Prevents workflow crash when release notes not yet created.
1 parent ea2dde3 commit 8cfe36f

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

.github/workflows/create-milestone-release.yml

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ jobs:
3838
return [context.ref.replace('refs/tags/', '')];
3939
}
4040
41-
const directory = await github.rest.repos.getContent({
42-
owner: context.repo.owner,
43-
repo: context.repo.repo,
44-
path: 'docs/release-notes',
45-
ref: defaultBranch,
46-
});
41+
let directory;
42+
try {
43+
directory = await github.rest.repos.getContent({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
path: 'docs/release-notes',
47+
ref: defaultBranch,
48+
});
49+
} catch (error) {
50+
if (error.status === 404) {
51+
core.info('docs/release-notes does not exist on the default branch; nothing to release.');
52+
return [];
53+
}
54+
throw error;
55+
}
4756
4857
if (!Array.isArray(directory.data)) {
4958
throw new Error('docs/release-notes must be a directory.');
@@ -86,12 +95,21 @@ jobs:
8695
const notesPath = `docs/release-notes/${tag}.md`;
8796
const ref = context.ref.startsWith('refs/tags/') ? tag : defaultBranch;
8897
89-
const file = await github.rest.repos.getContent({
90-
owner: context.repo.owner,
91-
repo: context.repo.repo,
92-
path: notesPath,
93-
ref,
94-
});
98+
let file;
99+
try {
100+
file = await github.rest.repos.getContent({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
path: notesPath,
104+
ref,
105+
});
106+
} catch (error) {
107+
if (error.status === 404) {
108+
core.info(`Skipping ${tag}; ${notesPath} was not found at ref ${ref}.`);
109+
return { tag, status: 'missing-notes' };
110+
}
111+
throw error;
112+
}
95113
96114
if (!file.data || !file.data.content) {
97115
throw new Error(`Unable to read ${notesPath} at ref ${ref}`);

0 commit comments

Comments
 (0)