Skip to content

Commit

Permalink
add summary as an action output
Browse files Browse the repository at this point in the history
  • Loading branch information
jannon committed Aug 19, 2020
1 parent 9ac2f82 commit 47407ed
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ inputs:
description: "Name of the Check in the github actions UI"
require: true
default: "Junit Results"
outputs:
summary:
description: "The test run summary"
runs:
using: "node12"
main: "index.js"
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const path = require("path");
},
};

core.setOutput("summary", testSummary.toFormattedMessage());
const octokit = new github.GitHub(accessToken);
await octokit.checks.create(createCheckRequest);
} catch (error) {
Expand Down
38 changes: 38 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const index = require("./index");
const process = require("process");
const cp = require("child_process");
const path = require("path");
const fs = require("fs").promises;

Expand Down Expand Up @@ -330,6 +332,42 @@ describe('TestSummary', () => {
});
});

describe('action logic', () => {
// Setup the necessary mocks
const token = 'dummyToken';
const inputPath = '**/TEST-*.xml';
const includeSummary = true;
const numFailures = 10;
const name = 'Junit Results';
const repo = 'foo/bar';
const ref = 'refs/heads/some-ref';
const sha = '1234567890123456789012345678901234567890';

beforeAll(() => {
process.env['INPUT_ACCESS-TOKEN'] = token;
process.env['INPUT_PATH'] = inputPath;
process.env['INPUT_INCLUDESUMMARY'] = includeSummary;
process.env['INPUT_NUMFAILURES'] = numFailures;
process.env['INPUT_NAME'] = name;
process.env['GITHUB_REPOSITORY'] = repo;
process.env['GITHUB_REF'] = ref;
process.env['GITHUB_SHA'] = sha;
});

it('should provide "summary" output', async done => {
const ip = path.join(__dirname, 'index.js');
cp.exec(`node ${ip}`, {env: process.env}, (error, stdout, stderr) => {
try {
console.log(`STDOUT: ${stdout}`);
expect(stdout).toContain("::set-output name=summary::Junit Results ran 3 in 0.132 seconds 1 Errored, 1 Failed, 0 Skipped");
done();
} catch(error) {
done(error);
}
});
});
});

async function addFile(filePath, content) {
filePath = "tmp/" + filePath;
let dirname = path.dirname(filePath);
Expand Down

0 comments on commit 47407ed

Please sign in to comment.