Skip to content

Commit 4ba431c

Browse files
authored
Merge pull request #3 from danpetitt/feature/commit-options
Added commit options
2 parents d282623 + 12226d5 commit 4ba431c

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
path-to-opencover-xml: ./test/opencover.xml
2525
path-to-badges: ./
2626
minimum-coverage: 75
27+
commit-badges: false
2728
repo-token: ${{ secrets.CI_TOKEN }}
2829
```
2930
@@ -51,6 +52,14 @@ Path to the open cover xml file
5152

5253
Threshold percentage at which a red badge would appear.
5354

55+
### `commit-badges` (Optional)
56+
57+
**Optional:** When set will commit the changed badges to the repo. Default `true`.
58+
59+
### `commit-branch-name` (Optional)
60+
61+
**Optional:** When set will checkout the given branch name before committing the changed badges. Default is the current main branch.
62+
5463
### `repo-token` (Required)
5564

5665
GitHub repo token so that the changed file can be committed, like `${{ secrets.CI_TOKEN }}`

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ inputs:
1111
minimum-coverage:
1212
description: 'Threshold percentage at which a red badge would appear'
1313
required: true
14+
commit-badges:
15+
description: 'Commit changed badges to repository'
16+
required: false
17+
default: true
18+
commit-branch-name:
19+
description: 'Specify alternative branch to commit changed badges into'
20+
required: false
1421
repo-token:
1522
description: 'Github repo token so that the changed file can be committed, like secrets.GITHUB_TOKEN'
1623
required: true

src/git-utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ const core = require('@actions/core');
33

44
const commitAndPush = async function(files) {
55
const repoTokenInput = core.getInput('repo-token', { required: true });
6+
const branchName = core.getInput('commit-branch-name', { required: false });
67

78
core.info('Committing new badge');
89
await exec.exec('git', ['config', 'user.name', `"${process.env['GITHUB_ACTOR']}"`]);
910
await exec.exec('git', ['config', 'user.email', `"${process.env['GITHUB_ACTOR']}@users.noreply.github.com"`]);
1011
await exec.exec('git', ['remote', 'set-url', 'origin', `https://x-access-token:${repoTokenInput}@github.com/${process.env['GITHUB_REPOSITORY']}.git`]);
12+
13+
if (branchName.length > 0) {
14+
await exec.exec('git', ['checkout', branchName]);
15+
}
16+
1117
for (const file of files) {
1218
await exec.exec('git', ['add', file]);
1319
}

src/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const generateBadge = require('./generate-badge');
77
async function run() {
88
try {
99
const openCoverFilePathInput = core.getInput('path-to-opencover-xml', { required: true });
10-
let badgesFilePathInput = core.getInput('path-to-badges', { required: false, });
10+
let badgesFilePathInput = core.getInput('path-to-badges', { required: false });
1111
if (!badgesFilePathInput) {
1212
badgesFilePathInput = './/';
1313
}
@@ -32,10 +32,14 @@ async function run() {
3232
);
3333

3434
if (wasNewLineBadgeCreated || wasNewBranchBadgeCreated) {
35-
await commitAndPush([
36-
lineBadgePath,
37-
branchBadgePath
38-
]);
35+
// Default for no value is 'true'
36+
const commitBadges = core.getInput('commit-badges', { required: false });
37+
if (commitBadges.length === 0 || commitBadges === 'true') {
38+
await commitAndPush([
39+
lineBadgePath,
40+
branchBadgePath
41+
]);
42+
}
3943
} else {
4044
core.info('No new badges were created, skipping git commit')
4145
}

0 commit comments

Comments
 (0)