-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the initial implementation of a cli tool that will compare the coverage of the current PR to that of the main branch. Ref: LOG-9611 Semver: minor
- Loading branch information
Showing
18 changed files
with
1,935 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# test artifacts | ||
.nyc_output | ||
coverage/ | ||
tmp/ | ||
output/ | ||
lib-cov | ||
*.lcov | ||
.tap | ||
|
||
# IDE files | ||
.idea | ||
*.swp | ||
*.vim | ||
|
||
# dev files | ||
*.save | ||
*.tgz | ||
.npm | ||
.pnpm/ | ||
.eslintcache/ | ||
.node_repl_history | ||
node_modules/ | ||
npm-debug.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ts: false | ||
jsx: false | ||
check-coverage: true | ||
output-file: .tap | ||
coverage-report: | ||
- text | ||
- text-summary | ||
- json | ||
- json-summary | ||
- html | ||
branches: 98 | ||
lines: 98 | ||
functions: 92 | ||
statements: 98 | ||
nyc-arg: | ||
- --all | ||
- --exclude=tools/ | ||
- --exclude=test/ | ||
- --exclude=coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
library 'magic-butler-catalogue' | ||
|
||
def PROJECT_NAME = "compare-coverage-to-main" | ||
def CURRENT_BRANCH = [env.CHANGE_BRANCH, env.BRANCH_NAME]?.find{branch -> branch != null} | ||
def DEFAULT_BRANCH = 'main' | ||
def TRIGGER_PATTERN = ".*@logdnabot.*" | ||
|
||
pipeline { | ||
agent none | ||
|
||
options { | ||
timestamps() | ||
ansiColor 'xterm' | ||
} | ||
|
||
triggers { | ||
issueCommentTrigger(TRIGGER_PATTERN) | ||
} | ||
|
||
environment { | ||
GITHUB_TOKEN = credentials('github-api-token') | ||
NPM_TOKEN = credentials('npm-publish-token') | ||
NPM_CONFIG_CACHE = '.npm' | ||
NPM_CONFIG_USERCONFIG = '.npm/rc' | ||
SPAWN_WRAP_SHIM_ROOT = '.npm' | ||
} | ||
|
||
stages { | ||
stage('Validate PR Source') { | ||
when { | ||
expression { env.CHANGE_FORK } | ||
not { | ||
triggeredBy 'issueCommentCause' | ||
} | ||
} | ||
steps { | ||
error("A maintainer needs to approve this PR for CI by commenting") | ||
} | ||
} | ||
|
||
stage('Test Suite') { | ||
matrix { | ||
axes { | ||
axis { | ||
name 'NODE_VERSION' | ||
values '12', '14', '16' | ||
} | ||
} | ||
|
||
agent { | ||
docker { | ||
image "us.gcr.io/logdna-k8s/node:${NODE_VERSION}-ci" | ||
customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}" | ||
} | ||
} | ||
|
||
stages { | ||
stage('Test') { | ||
environment { | ||
GIT_BRANCH = "${CURRENT_BRANCH}" | ||
BRANCH_NAME = "${CURRENT_BRANCH}" | ||
} | ||
|
||
steps { | ||
sh "mkdir -p ${NPM_CONFIG_CACHE}" | ||
script { | ||
npm.install GITHUB_TOKEN | ||
} | ||
sh 'npm run test:ci' | ||
} | ||
|
||
post { | ||
always { | ||
junit 'coverage/test.xml' | ||
script { | ||
if (NODE_VERSION == '14') { | ||
stash( | ||
name: slugify(BUILD_TAG) | ||
, allowEmpty: true | ||
, includes: 'coverage/*.json' | ||
) | ||
} | ||
} | ||
publishHTML target: [ | ||
allowMissing: false, | ||
alwaysLinkToLastBuild: false, | ||
keepAll: true, | ||
reportDir: 'coverage/lcov-report', | ||
reportFiles: 'index.html', | ||
reportName: "coverage-node-v${NODE_VERSION}" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage('Test Release') { | ||
when { | ||
beforeAgent true | ||
not { | ||
branch DEFAULT_BRANCH | ||
} | ||
} | ||
|
||
agent { | ||
docker { | ||
image "us.gcr.io/logdna-k8s/node:14-ci" | ||
customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}" | ||
} | ||
} | ||
|
||
environment { | ||
GIT_BRANCH = "${CURRENT_BRANCH}" | ||
BRANCH_NAME = "${CURRENT_BRANCH}" | ||
} | ||
|
||
steps { | ||
script { | ||
sh "mkdir -p ${NPM_CONFIG_CACHE}" | ||
unstash name: slugify(BUILD_TAG) | ||
npm.install GITHUB_TOKEN | ||
sh "npm run release -- --dry-run --no-ci --branches ${CURRENT_BRANCH}" | ||
} | ||
} | ||
} | ||
|
||
stage('Release') { | ||
when { | ||
beforeAgent true | ||
branch DEFAULT_BRANCH | ||
not { | ||
changelog '\\[skip ci\\]' | ||
} | ||
} | ||
|
||
agent { | ||
docker { | ||
image "us.gcr.io/logdna-k8s/node:14-ci" | ||
customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}" | ||
} | ||
} | ||
|
||
steps { | ||
script { | ||
sh "mkdir -p ${NPM_CONFIG_CACHE}" | ||
unstash name: slugify(BUILD_TAG) | ||
npm.install GITHUB_TOKEN | ||
sh "npm run release" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright © 2021 LogDNA | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const path = require('path') | ||
const help = require('help')() | ||
const nopt = require('nopt') | ||
const Comparer = require('../index.js') | ||
const known_opts = { | ||
'help': Boolean | ||
, 'version': Boolean | ||
, 'coverage-filepath': path | ||
, 'dry-run': Boolean | ||
, 'owner': String | ||
, 'pr-id': Number | ||
, 'repo': String | ||
} | ||
|
||
const short_hand = { | ||
h: ['--help'] | ||
, v: ['--version'] | ||
, f: ['--coverage-filepath'] | ||
, d: ['--dry-run'] | ||
, o: ['--owner'] | ||
, p: ['--pr-id'] | ||
, r: ['--repo'] | ||
} | ||
|
||
const parsed = nopt(known_opts, short_hand) | ||
|
||
if (parsed.help) { | ||
return help() | ||
} | ||
|
||
if (parsed.version) { | ||
process.stdout.write(`${require('../package').version}`) | ||
return | ||
} | ||
|
||
if (!process.env.GITHUB_TOKEN) { | ||
console.error('Please set the GITHUB_TOKEN env var.') | ||
process.exitCode = 1 | ||
return | ||
} | ||
|
||
if (!parsed.repo) { | ||
console.error('missing --repo flag. Please pass the repository name') | ||
process.exitCode = 1 | ||
return | ||
} | ||
|
||
if (!parsed.owner) { | ||
console.error('missing --owner flag. Please pass the github organization or user.') | ||
process.exitCode = 1 | ||
return | ||
} | ||
|
||
if (!parsed['coverage-filepath']) { | ||
console.error('missing --coverage-filepath flag. ' | ||
+ 'Please pass the path to the coverage-summary.json file.' | ||
) | ||
process.exitCode = 1 | ||
return | ||
} | ||
|
||
const comparer = new Comparer({ | ||
coverage_filepath: parsed['coverage-filepath'] | ||
, dry_run: parsed['dry-run'] | ||
, owner: parsed.owner | ||
, pr_id: parsed['pr-id'] | ||
, repo: parsed.repo | ||
, token: process.env.GITHUB_TOKEN | ||
}) | ||
|
||
/* istanbul ignore next */ | ||
function onError(err) { | ||
console.error(err) | ||
process.nextTick(() => { | ||
throw err | ||
}) | ||
} | ||
|
||
;(async () => { | ||
await comparer.run() | ||
})().catch(onError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
compare-coverage-to-main - Tool to compare coverage for a PR with the main branch | ||
|
||
usage: compare-coverage-to-main -f <path to coverage file> -o <org> -r <repo> -p <pull request id> | ||
|
||
options: | ||
-h, --help show help and usage | ||
-v, --version show version | ||
-f, --coverage-filepath <path> path to new coverage summary | ||
-d, --dry-run if true, does not post comment to PR | ||
-o, --owner <string> the repository owner | ||
-p, --pr-id <number> the PR id | ||
-r, --repo <repository name> the repository name |
Oops, something went wrong.