Skip to content

Commit

Permalink
Add an extra argument 'commit' support
Browse files Browse the repository at this point in the history
  • Loading branch information
HyukjinKwon committed Aug 13, 2020
1 parent acc620b commit c96094c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
restore-keys: |
${{ runner.os }}-main-maven-
- run: cd tests && mvn clean test --batch-mode -Dmaven.test.failure.ignore=true
- uses: scacap/action-surefire-report@master
- uses: HyukjinKwon/action-surefire-report@master
if: endsWith(github.ref, 'master') == false
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
check_name: Example Surefire Test Report
- uses: cclauss/GitHub-Action-for-pytest@0.5.0
with:
args: pytest --junit-xml=python/report.xml python/ || exit 0
- uses: scacap/action-surefire-report@master
- uses: HyukjinKwon/action-surefire-report@master
if: endsWith(github.ref, 'master') == false
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Optional. [Glob](https://github.com/actions/toolkit/tree/master/packages/glob) e

Optional. Check name to use when creating a check run. The default is `Test Report`.

### `commit`

Optional. The commit sha to update the status. This is useful when you run it with `workflow_run`.

## Example usage

```yml
Expand Down
3 changes: 2 additions & 1 deletion action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const action = async () => {
core.info(`Going to parse results form ${reportPaths}`);
const githubToken = core.getInput('github_token');
const name = core.getInput('check_name');
const commit = core.getInput('commit');

let { count, skipped, annotations } = await parseTestReports(reportPaths);
const foundResults = count > 0 || skipped > 0;
Expand All @@ -19,7 +20,7 @@ const action = async () => {
const link = pullRequest && pullRequest.html_url || github.context.ref;
const conclusion = foundResults && annotations.length === 0 ? 'success' : 'failure';
const status = 'completed';
const head_sha = pullRequest && pullRequest.head.sha || github.context.sha;
const head_sha = commit || pullRequest && pullRequest.head.sha || github.context.sha;
core.info(
`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
);
Expand Down
12 changes: 6 additions & 6 deletions action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ describe('action should work', () => {
jest.spyOn(core, 'debug').mockImplementation(jest.fn());

github.context.payload.pull_request = {
html_url: 'https://github.com/scacap/action-surefire-report',
html_url: 'https://github.com/HyukjinKwon/action-surefire-report',
head: { sha: 'sha123' }
};

jest.spyOn(github.context, 'repo', 'get').mockImplementation(() => {
return {
owner: 'scacap',
owner: 'HyukjinKwon',
repo: 'action-surefire-report'
};
});
Expand All @@ -54,7 +54,7 @@ describe('action should work', () => {
it('should parse surefire reports and send a check run to GitHub', async () => {
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/scacap/action-surefire-report/check-runs', body => {
.post('/repos/HyukjinKwon/action-surefire-report/check-runs', body => {
request = body;
return body;
})
Expand All @@ -69,7 +69,7 @@ describe('action should work', () => {
inputs.report_paths = '**/surefire-reports/TEST-*AllOkTest.xml';
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/scacap/action-surefire-report/check-runs', body => {
.post('/repos/HyukjinKwon/action-surefire-report/check-runs', body => {
request = body;
return body;
})
Expand All @@ -84,7 +84,7 @@ describe('action should work', () => {
inputs.report_paths = '**/xxx/*.xml';
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/scacap/action-surefire-report/check-runs', body => {
.post('/repos/HyukjinKwon/action-surefire-report/check-runs', body => {
request = body;
return body;
})
Expand All @@ -103,7 +103,7 @@ describe('action should work', () => {

let request = null;
const scope = nock('https://api.github.com')
.post('/repos/scacap/action-surefire-report/check-runs', body => {
.post('/repos/HyukjinKwon/action-surefire-report/check-runs', body => {
request = body;
return body;
})
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
description: 'check name for test reports'
required: false
default: 'Test Report'
commit:
description: 'commit sha to update the status'
required: false
runs:
using: 'node12'
main: 'dist/index.js'
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29751,6 +29751,7 @@ const action = async () => {
core.info(`Going to parse results form ${reportPaths}`);
const githubToken = core.getInput('github_token');
const name = core.getInput('check_name');
const commit = core.getInput('commit');

let { count, skipped, annotations } = await parseTestReports(reportPaths);
const foundResults = count > 0 || skipped > 0;
Expand All @@ -29763,7 +29764,7 @@ const action = async () => {
const link = pullRequest && pullRequest.html_url || github.context.ref;
const conclusion = foundResults && annotations.length === 0 ? 'success' : 'failure';
const status = 'completed';
const head_sha = pullRequest && pullRequest.head.sha || github.context.sha;
const head_sha = commit || pullRequest && pullRequest.head.sha || github.context.sha;
core.info(
`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
);
Expand Down Expand Up @@ -30134,4 +30135,4 @@ function authenticate(state, options) {

/***/ })

/******/ });
/******/ });
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Scalable Capital",
"license": "Apache-2.0",
"main": "index.js",
"homepage": "https://github.com/ScaCap/action-surefire-report#readme",
"homepage": "https://github.com/HyukjinKwon/action-surefire-report#readme",
"scripts": {
"eslint": "eslint .",
"package": "ncc build index.js -o dist",
Expand All @@ -14,7 +14,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/ScaCap/action-surefire-report"
"url": "git+https://github.com/HyukjinKwon/action-surefire-report"
},
"keywords": [
"GitHub",
Expand All @@ -23,7 +23,7 @@
"Surefire"
],
"bugs": {
"url": "https://github.com/ScaCap/action-surefire-report/issues"
"url": "https://github.com/HyukjinKwon/action-surefire-report/issues"
},
"jest-junit": {
"suiteNameTemplate": "{filepath}",
Expand Down

0 comments on commit c96094c

Please sign in to comment.