From 7482b86f51324938883cfdd0683aeb8aa75aab97 Mon Sep 17 00:00:00 2001 From: HackingGate Date: Fri, 11 Jun 2021 12:33:39 +0900 Subject: [PATCH 1/7] Remove comment --- README.md | 5 ----- action.yml | 5 +---- dist/main.js | 18 +----------------- src/index.js | 20 ++------------------ 4 files changed, 4 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 95a3761f..4aacf5e7 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,6 @@ Total Coverage: 99.39% ## Inputs -##### `github-token` (**Optional**) -Github token used for posting the comment. Defaults to `${{ github.token }}`. - -For alternative `github-token` values see: [Creating Personal Access Tokens](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) - ##### `lcov-file` (**Optional**) The location of the lcov file to read the coverage report from. Defaults to `./coverage/lcov.info`. diff --git a/action.yml b/action.yml index 159975ff..fa129468 100644 --- a/action.yml +++ b/action.yml @@ -5,13 +5,10 @@ branding: icon: check-square color: green inputs: - github-token: - description: Github token - required: true - default: ${{ github.token }} lcov-file: description: The location of the lcov.info file required: false + default: ./coverage/lcov.info lcov-base: description: The location of the lcov file for the base branch required: false diff --git a/dist/main.js b/dist/main.js index ba98502a..a7e2f6bb 100644 --- a/dist/main.js +++ b/dist/main.js @@ -22970,8 +22970,7 @@ function diff(lcov, before, options) { } async function main$1() { - const token = core$1.getInput("github-token"); - const lcovFile = core$1.getInput("lcov-file") || "./coverage/lcov.info"; + const lcovFile = core$1.getInput("lcov-file"); const baseFile = core$1.getInput("lcov-base"); const raw = await fs.promises.readFile(lcovFile, "utf-8").catch(err => null); @@ -23003,21 +23002,6 @@ async function main$1() { const baselcov = baseRaw && await parse$2(baseRaw); const body = diff(lcov, baselcov, options); - if (github_1.eventName === "pull_request") { - await new github_2(token).issues.createComment({ - repo: github_1.repo.repo, - owner: github_1.repo.owner, - issue_number: github_1.payload.pull_request.number, - body: diff(lcov, baselcov, options), - }); - } else if (github_1.eventName === "push") { - await new github_2(token).repos.createCommitComment({ - repo: github_1.repo.repo, - owner: github_1.repo.owner, - commit_sha: options.commit, - body: diff(lcov, baselcov, options), - }); - } } main$1().catch(function(err) { diff --git a/src/index.js b/src/index.js index 18f17a2f..be74eb25 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,12 @@ import { promises as fs } from "fs" import core from "@actions/core" -import { GitHub, context } from "@actions/github" +import { context } from "@actions/github" import { parse } from "./lcov" import { diff } from "./comment" async function main() { - const token = core.getInput("github-token") - const lcovFile = core.getInput("lcov-file") || "./coverage/lcov.info" + const lcovFile = core.getInput("lcov-file") const baseFile = core.getInput("lcov-base") const raw = await fs.readFile(lcovFile, "utf-8").catch(err => null) @@ -39,21 +38,6 @@ async function main() { const baselcov = baseRaw && await parse(baseRaw) const body = diff(lcov, baselcov, options) - if (context.eventName === "pull_request") { - await new GitHub(token).issues.createComment({ - repo: context.repo.repo, - owner: context.repo.owner, - issue_number: context.payload.pull_request.number, - body: diff(lcov, baselcov, options), - }) - } else if (context.eventName === "push") { - await new GitHub(token).repos.createCommitComment({ - repo: context.repo.repo, - owner: context.repo.owner, - commit_sha: options.commit, - body: diff(lcov, baselcov, options), - }) - } } main().catch(function(err) { From 8e0e2f75214b17f82a09ba15ad79ab96b25c7cf4 Mon Sep 17 00:00:00 2001 From: HackingGate Date: Fri, 11 Jun 2021 13:03:12 +0900 Subject: [PATCH 2/7] core.setOutput --- action.yml | 6 +++++- src/index.js | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index fa129468..c00a1e30 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: Code Coverage Report -description: Comments a pull request with the code coverage +description: Generate a HTML body with the code coverage author: Romeo Van Snick branding: icon: check-square @@ -12,6 +12,10 @@ inputs: lcov-base: description: The location of the lcov file for the base branch required: false + path: + description: 'The destination path the HTML body file' + required: false + default: ./coverage/body.html runs: using: node12 main: dist/main.js diff --git a/src/index.js b/src/index.js index be74eb25..6e0b74cc 100644 --- a/src/index.js +++ b/src/index.js @@ -37,7 +37,22 @@ async function main() { const lcov = await parse(raw) const baselcov = baseRaw && await parse(baseRaw) const body = diff(lcov, baselcov, options) - + core.debug(`HTML body is ${body}`) + + const path = core.getInput(Inputs.Path, {required: false}) + + let resolvedPath + // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern + if (path.startsWith(`~`)) { + resolvedPath = resolve(path.replace('~', os.homedir())) + } else { + resolvedPath = resolve(path) + } + core.debug(`Resolved path is ${resolvedPath}`) + + // output the directory that the artifact(s) was/were downloaded to + // if no path is provided, an empty string resolves to the current working directory + core.setOutput(body, resolvedPath) } main().catch(function(err) { From 14c98c8f711581c38179224281b18ba9f3c8d00e Mon Sep 17 00:00:00 2001 From: HackingGate Date: Fri, 11 Jun 2021 15:32:48 +0900 Subject: [PATCH 3/7] fs.writeFile --- src/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 6e0b74cc..d4527ad4 100644 --- a/src/index.js +++ b/src/index.js @@ -37,7 +37,7 @@ async function main() { const lcov = await parse(raw) const baselcov = baseRaw && await parse(baseRaw) const body = diff(lcov, baselcov, options) - core.debug(`HTML body is ${body}`) + console.log(`HTML body is ${body}`) const path = core.getInput(Inputs.Path, {required: false}) @@ -50,9 +50,7 @@ async function main() { } core.debug(`Resolved path is ${resolvedPath}`) - // output the directory that the artifact(s) was/were downloaded to - // if no path is provided, an empty string resolves to the current working directory - core.setOutput(body, resolvedPath) + fs.writeFile(resolvedPath, body).catch(err => null); } main().catch(function(err) { From 46cac5a3137acc58b8cb52704616f7edc1c82384 Mon Sep 17 00:00:00 2001 From: HackingGate Date: Fri, 11 Jun 2021 15:34:25 +0900 Subject: [PATCH 4/7] Forgot build --- dist/main.js | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/dist/main.js b/dist/main.js index a7e2f6bb..52153a6c 100644 --- a/dist/main.js +++ b/dist/main.js @@ -4,7 +4,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var fs = require('fs'); var fs__default = _interopDefault(fs); -var os = _interopDefault(require('os')); +var os$1 = _interopDefault(require('os')); var path = _interopDefault(require('path')); var child_process = _interopDefault(require('child_process')); var Stream = _interopDefault(require('stream')); @@ -45,7 +45,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); */ function issueCommand(command, properties, message) { const cmd = new Command(command, properties, message); - process.stdout.write(cmd.toString() + os.EOL); + process.stdout.write(cmd.toString() + os$1.EOL); } exports.issueCommand = issueCommand; function issue(name, message = '') { @@ -230,7 +230,7 @@ exports.warning = warning; * @param message info message */ function info(message) { - process.stdout.write(message + os.EOL); + process.stdout.write(message + os$1.EOL); } exports.info = info; /** @@ -383,7 +383,7 @@ const nameMap = new Map([ ]); const macosRelease = release => { - release = Number((release || os.release()).split('.')[0]); + release = Number((release || os$1.release()).split('.')[0]); return { name: nameMap.get(release), version: '10.' + (release - 4) @@ -3706,7 +3706,7 @@ const names = new Map([ ]); const windowsRelease = release => { - const version = /\d+\.\d/.exec(release || os.release()); + const version = /\d+\.\d/.exec(release || os$1.release()); if (release && !version) { throw new Error('`release` argument doesn\'t match `n.n`'); @@ -3718,7 +3718,7 @@ const windowsRelease = release => { // If `release` is omitted or we're on a Windows system, and the version number is an ambiguous version // then use `wmic` to get the OS caption: https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx // If the resulting caption contains the year 2008, 2012 or 2016, it is a server version, so return a server OS name. - if ((!release || release === os.release()) && ['6.1', '6.2', '6.3', '10.0'].includes(ver)) { + if ((!release || release === os$1.release()) && ['6.1', '6.2', '6.3', '10.0'].includes(ver)) { const stdout = execa.sync('wmic', ['os', 'get', 'Caption']).stdout || ''; const year = (stdout.match(/2008|2012|2016/) || [])[0]; if (year) { @@ -3736,13 +3736,13 @@ const osName = (platform, release) => { throw new Error('You can\'t specify a `release` without specifying `platform`'); } - platform = platform || os.platform(); + platform = platform || os$1.platform(); let id; if (platform === 'darwin') { - if (!release && os.platform() === 'darwin') { - release = os.release(); + if (!release && os$1.platform() === 'darwin') { + release = os$1.release(); } const prefix = release ? (Number(release.split('.')[0]) > 15 ? 'macOS' : 'OS X') : 'macOS'; @@ -3751,8 +3751,8 @@ const osName = (platform, release) => { } if (platform === 'linux') { - if (!release && os.platform() === 'linux') { - release = os.release(); + if (!release && os$1.platform() === 'linux') { + release = os$1.release(); } id = release ? release.replace(/^(\d+\.\d+).*/, '$1') : ''; @@ -3760,8 +3760,8 @@ const osName = (platform, release) => { } if (platform === 'win32') { - if (!release && os.platform() === 'win32') { - release = os.release(); + if (!release && os$1.platform() === 'win32') { + release = os$1.release(); } id = release ? windowsRelease_1(release) : ''; @@ -22538,7 +22538,7 @@ class Context { this.payload = JSON.parse(fs__default.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' })); } else { - process.stdout.write(`GITHUB_EVENT_PATH ${process.env.GITHUB_EVENT_PATH} does not exist${os.EOL}`); + process.stdout.write(`GITHUB_EVENT_PATH ${process.env.GITHUB_EVENT_PATH} does not exist${os$1.EOL}`); } } this.eventName = process.env.GITHUB_EVENT_NAME; @@ -23001,7 +23001,20 @@ async function main$1() { const lcov = await parse$2(raw); const baselcov = baseRaw && await parse$2(baseRaw); const body = diff(lcov, baselcov, options); + console.log(`HTML body is ${body}`); + const path = core$1.getInput(Inputs.Path, {required: false}); + + let resolvedPath; + // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern + if (path.startsWith(`~`)) { + resolvedPath = resolve(path.replace('~', os.homedir())); + } else { + resolvedPath = resolve(path); + } + core$1.debug(`Resolved path is ${resolvedPath}`); + + fs.promises.writeFile(resolvedPath, body).catch(err => null); } main$1().catch(function(err) { From 50d98a6e28f590b6e996f436bd726b93b7157a23 Mon Sep 17 00:00:00 2001 From: HackingGate Date: Fri, 11 Jun 2021 15:41:26 +0900 Subject: [PATCH 5/7] Fix path --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index d4527ad4..4c7c504f 100644 --- a/src/index.js +++ b/src/index.js @@ -37,9 +37,9 @@ async function main() { const lcov = await parse(raw) const baselcov = baseRaw && await parse(baseRaw) const body = diff(lcov, baselcov, options) - console.log(`HTML body is ${body}`) + console.log(body) - const path = core.getInput(Inputs.Path, {required: false}) + const path = core.getInput('path') let resolvedPath // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern From abccf7fbb7f35f7956e4a5fb8c1f49c3ba172167 Mon Sep 17 00:00:00 2001 From: HackingGate Date: Fri, 11 Jun 2021 15:49:24 +0900 Subject: [PATCH 6/7] Forgot build --- dist/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/main.js b/dist/main.js index 52153a6c..09c93579 100644 --- a/dist/main.js +++ b/dist/main.js @@ -23001,9 +23001,9 @@ async function main$1() { const lcov = await parse$2(raw); const baselcov = baseRaw && await parse$2(baseRaw); const body = diff(lcov, baselcov, options); - console.log(`HTML body is ${body}`); + console.log(body); - const path = core$1.getInput(Inputs.Path, {required: false}); + const path = core$1.getInput('path'); let resolvedPath; // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern From 7bf132b5f872f17fde607a37b7ca2308510abbb4 Mon Sep 17 00:00:00 2001 From: HackingGate Date: Fri, 11 Jun 2021 16:00:01 +0900 Subject: [PATCH 7/7] Fix resolve --- dist/main.js | 37 +++++++++++++++++++------------------ src/index.js | 2 ++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/dist/main.js b/dist/main.js index 09c93579..4417bf2b 100644 --- a/dist/main.js +++ b/dist/main.js @@ -5,7 +5,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var fs = require('fs'); var fs__default = _interopDefault(fs); var os$1 = _interopDefault(require('os')); -var path = _interopDefault(require('path')); +var path = require('path'); +var path__default = _interopDefault(path); var child_process = _interopDefault(require('child_process')); var Stream = _interopDefault(require('stream')); var assert = _interopDefault(require('assert')); @@ -157,7 +158,7 @@ exports.setSecret = setSecret; */ function addPath(inputPath) { command.issueCommand('add-path', {}, inputPath); - process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; + process.env['PATH'] = `${inputPath}${path__default.delimiter}${process.env['PATH']}`; } exports.addPath = addPath; /** @@ -622,7 +623,7 @@ function which (cmd, opt, cb) { if (pathPart.charAt(0) === '"' && pathPart.slice(-1) === '"') pathPart = pathPart.slice(1, -1); - var p = path.join(pathPart, cmd); + var p = path__default.join(pathPart, cmd); if (!pathPart && (/^\.[\\\/]/).test(cmd)) { p = cmd.slice(0, 2) + p; } @@ -656,7 +657,7 @@ function whichSync (cmd, opt) { if (pathPart.charAt(0) === '"' && pathPart.slice(-1) === '"') pathPart = pathPart.slice(1, -1); - var p = path.join(pathPart, cmd); + var p = path__default.join(pathPart, cmd); if (!pathPart && /^\.[\\\/]/.test(cmd)) { p = cmd.slice(0, 2) + p; } @@ -718,7 +719,7 @@ function resolveCommandAttempt(parsed, withoutPathExt) { try { resolved = which_1.sync(parsed.command, { path: (parsed.options.env || process.env)[pathKey$1], - pathExt: withoutPathExt ? path.delimiter : undefined, + pathExt: withoutPathExt ? path__default.delimiter : undefined, }); } catch (e) { /* Empty */ @@ -729,7 +730,7 @@ function resolveCommandAttempt(parsed, withoutPathExt) { // If we successfully resolved, ensure that an absolute path is returned // Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it if (resolved) { - resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : '', resolved); + resolved = path__default.resolve(hasCustomCwd ? parsed.options.cwd : '', resolved); } return resolved; @@ -2407,7 +2408,7 @@ function parseNonShell(parsed) { // Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\bar) // This is necessary otherwise it will always fail with ENOENT in those cases - parsed.command = path.normalize(parsed.command); + parsed.command = path__default.normalize(parsed.command); // Escape command & arguments parsed.command = _escape.command(parsed.command); @@ -2602,19 +2603,19 @@ module.exports = opts => { }, opts); let prev; - let pth = path.resolve(opts.cwd); + let pth = path__default.resolve(opts.cwd); const ret = []; while (prev !== pth) { - ret.push(path.join(pth, 'node_modules/.bin')); + ret.push(path__default.join(pth, 'node_modules/.bin')); prev = pth; - pth = path.resolve(pth, '..'); + pth = path__default.resolve(pth, '..'); } // ensure the running `node` binary is used - ret.push(path.dirname(process.execPath)); + ret.push(path__default.dirname(process.execPath)); - return ret.concat(opts.path).join(path.delimiter); + return ret.concat(opts.path).join(path__default.delimiter); }; module.exports.env = opts => { @@ -3387,7 +3388,7 @@ function handleArgs(cmd, args, opts) { opts.cleanup = false; } - if (process.platform === 'win32' && path.basename(parsed.command) === 'cmd.exe') { + if (process.platform === 'win32' && path__default.basename(parsed.command) === 'cmd.exe') { // #116 parsed.args.unshift('/q'); } @@ -22617,7 +22618,7 @@ http://yuilibrary.com/license/ /* istanbul ignore next */ -var exists = fs__default.exists || path.exists; +var exists = fs__default.exists || path__default.exists; var walkFile = function(str, cb) { var data = [], item; @@ -23003,14 +23004,14 @@ async function main$1() { const body = diff(lcov, baselcov, options); console.log(body); - const path = core$1.getInput('path'); + const path$1 = core$1.getInput('path'); let resolvedPath; // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern - if (path.startsWith(`~`)) { - resolvedPath = resolve(path.replace('~', os.homedir())); + if (path$1.startsWith(`~`)) { + resolvedPath = path.resolve(path$1.replace('~', os.homedir())); } else { - resolvedPath = resolve(path); + resolvedPath = path.resolve(path$1); } core$1.debug(`Resolved path is ${resolvedPath}`); diff --git a/src/index.js b/src/index.js index 4c7c504f..8fe502f0 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,8 @@ import { context } from "@actions/github" import { parse } from "./lcov" import { diff } from "./comment" +import { resolve } from 'path' + async function main() { const lcovFile = core.getInput("lcov-file") const baseFile = core.getInput("lcov-base")