From c96094cc35061fcf154a7cb46807f2f3e2339476 Mon Sep 17 00:00:00 2001 From: HyukjinKwon Date: Thu, 13 Aug 2020 10:33:19 +0900 Subject: [PATCH] Add an extra argument 'commit' support --- .github/workflows/build.yml | 4 ++-- README.md | 4 ++++ action.js | 3 ++- action.test.js | 12 ++++++------ action.yml | 3 +++ dist/index.js | 5 +++-- package.json | 6 +++--- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0deddaa..4e858b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ 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 }} @@ -25,7 +25,7 @@ jobs: - 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 }} diff --git a/README.md b/README.md index e80eb89..1db10bf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.js b/action.js index 2248384..b7a0e51 100644 --- a/action.js +++ b/action.js @@ -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; @@ -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})` ); diff --git a/action.test.js b/action.test.js index 4295fbf..bccdd9a 100644 --- a/action.test.js +++ b/action.test.js @@ -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' }; }); @@ -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; }) @@ -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; }) @@ -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; }) @@ -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; }) diff --git a/action.yml b/action.yml index ceaa2f6..6d6f491 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index a6cb392..81bde08 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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; @@ -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})` ); @@ -30134,4 +30135,4 @@ function authenticate(state, options) { /***/ }) -/******/ }); \ No newline at end of file +/******/ }); diff --git a/package.json b/package.json index ed74542..6033227 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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}",