Skip to content

Commit

Permalink
Merge pull request #3 from danpetitt/feature/commit-options
Browse files Browse the repository at this point in the history
Added commit options
  • Loading branch information
danpetitt authored Oct 16, 2020
2 parents d282623 + 12226d5 commit 4ba431c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
path-to-opencover-xml: ./test/opencover.xml
path-to-badges: ./
minimum-coverage: 75
commit-badges: false
repo-token: ${{ secrets.CI_TOKEN }}
```
Expand Down Expand Up @@ -51,6 +52,14 @@ Path to the open cover xml file

Threshold percentage at which a red badge would appear.

### `commit-badges` (Optional)

**Optional:** When set will commit the changed badges to the repo. Default `true`.

### `commit-branch-name` (Optional)

**Optional:** When set will checkout the given branch name before committing the changed badges. Default is the current main branch.

### `repo-token` (Required)

GitHub repo token so that the changed file can be committed, like `${{ secrets.CI_TOKEN }}`
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ inputs:
minimum-coverage:
description: 'Threshold percentage at which a red badge would appear'
required: true
commit-badges:
description: 'Commit changed badges to repository'
required: false
default: true
commit-branch-name:
description: 'Specify alternative branch to commit changed badges into'
required: false
repo-token:
description: 'Github repo token so that the changed file can be committed, like secrets.GITHUB_TOKEN'
required: true
Expand Down
6 changes: 6 additions & 0 deletions src/git-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ const core = require('@actions/core');

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

core.info('Committing new badge');
await exec.exec('git', ['config', 'user.name', `"${process.env['GITHUB_ACTOR']}"`]);
await exec.exec('git', ['config', 'user.email', `"${process.env['GITHUB_ACTOR']}@users.noreply.github.com"`]);
await exec.exec('git', ['remote', 'set-url', 'origin', `https://x-access-token:${repoTokenInput}@github.com/${process.env['GITHUB_REPOSITORY']}.git`]);

if (branchName.length > 0) {
await exec.exec('git', ['checkout', branchName]);
}

for (const file of files) {
await exec.exec('git', ['add', file]);
}
Expand Down
14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const generateBadge = require('./generate-badge');
async function run() {
try {
const openCoverFilePathInput = core.getInput('path-to-opencover-xml', { required: true });
let badgesFilePathInput = core.getInput('path-to-badges', { required: false, });
let badgesFilePathInput = core.getInput('path-to-badges', { required: false });
if (!badgesFilePathInput) {
badgesFilePathInput = './/';
}
Expand All @@ -32,10 +32,14 @@ async function run() {
);

if (wasNewLineBadgeCreated || wasNewBranchBadgeCreated) {
await commitAndPush([
lineBadgePath,
branchBadgePath
]);
// Default for no value is 'true'
const commitBadges = core.getInput('commit-badges', { required: false });
if (commitBadges.length === 0 || commitBadges === 'true') {
await commitAndPush([
lineBadgePath,
branchBadgePath
]);
}
} else {
core.info('No new badges were created, skipping git commit')
}
Expand Down

0 comments on commit 4ba431c

Please sign in to comment.