Skip to content

Commit 1c3f2a2

Browse files
authored
Merge pull request #230 from waic/fix_update_readme
chore: Update GitHub Actions workflow to handle branch not found error
2 parents d11f107 + 7daae3a commit 1c3f2a2

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

.github/workflows/update-readme.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,27 @@ jobs:
3232
uses: actions/github-script@v5
3333
with:
3434
script: |
35-
const result = await github.rest.repos.compareCommits({
36-
owner: context.repo.owner,
37-
repo: context.repo.repo,
38-
base: 'master',
39-
head: 'update-readme-${{ github.run_number }}'
40-
});
41-
if (result.data.files.length > 0) {
42-
console.log("Changes detected");
43-
core.setOutput("changes_detected", "true");
44-
} else {
45-
console.log("No changes detected");
46-
core.setOutput("changes_detected", "false");
35+
try {
36+
const result = await github.rest.repos.compareCommits({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
base: 'master',
40+
head: 'update-readme-${{ github.run_number }}'
41+
});
42+
if (result.data.files.length > 0) {
43+
console.log("Changes detected");
44+
core.setOutput("changes_detected", "true");
45+
} else {
46+
console.log("No changes detected");
47+
core.setOutput("changes_detected", "false");
48+
}
49+
} catch (error) {
50+
if (error.status === 404) {
51+
console.log("Branch not found, no changes detected");
52+
core.setOutput("changes_detected", "false");
53+
} else {
54+
throw error;
55+
}
4756
}
4857
4958
- name: Commit README.md updates

0 commit comments

Comments
 (0)