diff --git a/action.yml b/action.yml index fdeaf5195..4dac2dc2e 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,10 @@ inputs: description: Set working directory if project is not in root folder required: false default: "./" + post-to: + description: Post the coverage report to either "comment" or "job-summary" + required: false + default: "comment" title: description: Title to add to the comment required: false diff --git a/src/index.js b/src/index.js index 2efc5fb02..0f63db965 100644 --- a/src/index.js +++ b/src/index.js @@ -21,6 +21,7 @@ async function main() { core.getInput("filter-changed-files").toLowerCase() === "true" const shouldDeleteOldComments = core.getInput("delete-old-comments").toLowerCase() === "true" + const postTo = core.getInput("post-to").toLowerCase() const title = core.getInput("title") const raw = await fs.readFile(lcovFile, "utf-8").catch(err => null) @@ -67,20 +68,29 @@ async function main() { await deleteOldComments(githubClient, options, context) } - if (context.eventName === "pull_request") { - await githubClient.issues.createComment({ - repo: context.repo.repo, - owner: context.repo.owner, - issue_number: context.payload.pull_request.number, - body: body, - }) - } else if (context.eventName === "push") { - await githubClient.repos.createCommitComment({ - repo: context.repo.repo, - owner: context.repo.owner, - commit_sha: options.commit, - body: body, - }) + switch (postTo) { + case "comment": + if (context.eventName === "pull_request") { + await githubClient.issues.createComment({ + repo: context.repo.repo, + owner: context.repo.owner, + issue_number: context.payload.pull_request.number, + body: body, + }) + } else if (context.eventName === "push") { + await githubClient.repos.createCommitComment({ + repo: context.repo.repo, + owner: context.repo.owner, + commit_sha: options.commit, + body: body, + }) + } + break + case "job-summary": + await core.summary.addRaw(body).write() + break + default: + console.warn(`Unknown post-to value: '${postTo}'`) } }