Skip to content

Commit 35eb825

Browse files
AbigailDengAbigailDeng
authored andcommitted
feat: badge
1 parent 3478e3b commit 35eb825

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

.github/workflows/test-badge.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ name: Test Badge
33
on:
44
push:
55
branches:
6+
- dev
67
- master
8+
- feature/badge
79

810
jobs:
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);

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<a href="http://commitizen.github.io/cz-cli/">
77
<img alt="Commitizen friendly" src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg">
88
</a>
9+
<img alt="TESTS" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/eanzhao/aelf-command/feature/use-github-actions/master-test-results.json">
910
</p>
1011

1112
## Descriptions

0 commit comments

Comments
 (0)