Skip to content

Commit

Permalink
Add the vcs info
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneseymour committed Apr 1, 2020
1 parent f07b34f commit 4179bff
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/dev/code_coverage/ingest_coverage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export function runCoverageIngestionCli() {
if (flags.path === '') throw createFlagError('please provide a single --path flag');
if (flags.verbose) log.verbose(`Verbose logging enabled`);

const jsonSummaryPath = resolve(ROOT, flags.path);
parseAndProcess({ jsonSummaryPath }, log);
const resolveRoot = resolve.bind(null, ROOT);
const jsonSummaryPath = resolveRoot(flags.path);
const vcsInfoFilePath = resolveRoot('VCS_INFO.txt');
parseAndProcess({ jsonSummaryPath, vcsInfoFilePath }, log);
},
{
description: `
Expand Down
42 changes: 32 additions & 10 deletions src/dev/code_coverage/ingest_coverage/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

import { fromEventPattern, of } from 'rxjs';
import { concatMap, delay, map } from 'rxjs/operators';
import { fromEventPattern, of, fromEvent } from 'rxjs';
import { concatMap, delay, map, takeUntil } from 'rxjs/operators';
import jsonStream from './json_stream';
import { pipe, noop, green } from './utils';
import { pipe, noop, green, always } from './utils';
import { ingest } from './ingest';
import {
staticSite,
Expand All @@ -31,8 +31,11 @@ import {
buildId,
coveredFilePath,
ciRunUrl,
itemizeVcs,
} from './transforms';
import { resolve } from 'path';
import { createReadStream } from 'fs';
import readline from 'readline';

const KIBANA_ROOT_PATH = '../../../..';
const KIBANA_ROOT = resolve(__dirname, KIBANA_ROOT_PATH);
Expand All @@ -43,19 +46,15 @@ const addPrePopulatedTimeStamp = addTimeStamp(process.env.TIME_STAMP);
const prokStatsTimeStampBuildId = pipe(statsAndstaticSiteUrl, buildId, addPrePopulatedTimeStamp);
const addTestRunnerAndStaticSiteUrl = pipe(testRunner, staticSite(staticSiteUrlBase));

export default ({ jsonSummaryPath }, log) => {
log.debug(`### Code coverage ingestion set to delay for: ${green(ms)} ms`);
log.debug(`### KIBANA_ROOT: \n\t${green(KIBANA_ROOT)}`);
log.debug(`### Ingesting from summary json: \n\t[${green(jsonSummaryPath)}]`);

validateRoot(KIBANA_ROOT, log);

const execute = jsonSummaryPath => log => vcsInfo => {
const objStream = jsonStream(jsonSummaryPath).on('done', noop);
const itemizeVcsInfo = itemizeVcs(vcsInfo);

fromEventPattern(_ => objStream.on('node', '!.*', _))
.pipe(
map(prokStatsTimeStampBuildId),
map(coveredFilePath),
map(itemizeVcsInfo),
map(ciRunUrl),
map(addJsonSummaryPath(jsonSummaryPath)),
map(addTestRunnerAndStaticSiteUrl),
Expand All @@ -64,6 +63,29 @@ export default ({ jsonSummaryPath }, log) => {
.subscribe(ingest(log));
};

export default ({ jsonSummaryPath, vcsInfoFilePath }, log) => {
log.debug(`### Code coverage ingestion set to delay for: ${green(ms)} ms`);
log.debug(`### KIBANA_ROOT: \n\t${green(KIBANA_ROOT)}`);
log.debug(`### Ingesting from summary json: \n\t[${green(jsonSummaryPath)}]`);

validateRoot(KIBANA_ROOT, log);

const vcsInfo = [];
const vcsInfoLines$ = vcsInfoFilePath => {
const rl = readline.createInterface({ input: createReadStream(vcsInfoFilePath) });
return fromEvent(rl, 'line').pipe(takeUntil(fromEvent(rl, 'close')));
};

const executeWithPath = execute(jsonSummaryPath)(log);
const mutate = x => vcsInfo.push(x.trimStart().trimEnd());

vcsInfoLines$(vcsInfoFilePath).subscribe(
mutate,
err => console.log('Error: %s', err),
always(executeWithPath(vcsInfo))
);
};

function validateRoot(x, log) {
return /kibana$/.test(x) ? noop() : log.warning(`!!! 'kibana' NOT FOUND in ROOT: ${x}\n`);
}
8 changes: 8 additions & 0 deletions src/dev/code_coverage/ingest_coverage/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ export const ciRunUrl = obj => {
};
};

export const itemizeVcs = vcsInfo => obj => {
const [branch, sha, author, commitMsg] = vcsInfo;
return {
...obj,
vcs: { branch, sha, author, commitMsg },
};
};

export const testRunner = obj => {
const { jsonSummaryPath } = obj;

Expand Down

0 comments on commit 4179bff

Please sign in to comment.