@@ -3,11 +3,13 @@ name: Test Badge
33on :
44 push :
55 branches :
6+ - dev
67 - master
8+ - feature/badge
79
810jobs :
911 test :
10- name : Coverage Diff
12+ name : Generate Test Badge
1113 runs-on : ubuntu-latest
1214
1315 steps :
@@ -66,19 +68,34 @@ jobs:
6668 const filePath = path.join(process.env.GITHUB_WORKSPACE, filename);
6769 const fileContent = fs.readFileSync(filePath, 'utf8');
6870
69- const { data: { sha } } = await github.rest.repos.getContent({
70- owner: context.repo.owner,
71- repo: context.repo.repo,
72- path: filename,
73- ref: 'feature/use-github-actions'
74- });
71+ let sha;
72+ try {
73+ const { data } = await github.rest.repos.getContent({
74+ owner: context.repo.owner,
75+ repo: context.repo.repo,
76+ path: filename,
77+ ref: 'feature/use-github-actions'
78+ });
79+ sha = data.sha;
80+ } catch (error) {
81+ if (error.status !== 404) {
82+ throw error;
83+ }
84+ // File does not exist, so we'll create it
85+ }
7586
76- await github.rest.repos.createOrUpdateFileContents( {
87+ const params = {
7788 owner: context.repo.owner,
7889 repo: context.repo.repo,
7990 path: filename,
8091 message: `Update ${filename}`,
8192 content: Buffer.from(fileContent).toString('base64'),
82- sha,
8393 branch: 'feature/use-github-actions'
84- });
94+ };
95+
96+ // Only add sha to params if it is defined
97+ if (sha) {
98+ params.sha = sha;
99+ }
100+
101+ await github.rest.repos.createOrUpdateFileContents(params);
0 commit comments