[kbn/pm] don't fail when plugins are outside repo (#60164)

* [kbn/pm] don't fail when plugins are outside repo

* remove unused import

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Spencer 2020-03-17 15:25:44 -07:00 committed by GitHub
parent 2367d749c1
commit 32b3861580
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 681 additions and 604 deletions

File diff suppressed because it is too large Load diff

View file

@ -48,6 +48,7 @@
"globby": "^8.0.1", "globby": "^8.0.1",
"has-ansi": "^3.0.0", "has-ansi": "^3.0.0",
"indent-string": "^3.2.0", "indent-string": "^3.2.0",
"is-path-inside": "^3.0.2",
"lodash.clonedeepwith": "^4.5.0", "lodash.clonedeepwith": "^4.5.0",
"log-symbols": "^2.2.0", "log-symbols": "^2.2.0",
"multimatch": "^4.0.0", "multimatch": "^4.0.0",

View file

@ -20,6 +20,7 @@
import Path from 'path'; import Path from 'path';
import multimatch from 'multimatch'; import multimatch from 'multimatch';
import isPathInside from 'is-path-inside';
import { ProjectMap, getProjects, includeTransitiveProjects } from './projects'; import { ProjectMap, getProjects, includeTransitiveProjects } from './projects';
import { Project } from './project'; import { Project } from './project';
@ -121,4 +122,15 @@ export class Kibana {
return filteredProjects; return filteredProjects;
} }
isPartOfRepo(project: Project) {
return (
project.path === this.kibanaProject.path ||
isPathInside(project.path, this.kibanaProject.path)
);
}
isOutsideRepo(project: Project) {
return !this.isPartOfRepo(project);
}
} }

View file

@ -43,7 +43,14 @@ async function getChangesForProjects(projects: ProjectMap, kbn: Kibana, log: Too
const { stdout } = await execa( const { stdout } = await execa(
'git', 'git',
['ls-files', '-dmt', '--', ...Array.from(projects.values()).map(p => p.path)], [
'ls-files',
'-dmt',
'--',
...Array.from(projects.values())
.filter(p => kbn.isPartOfRepo(p))
.map(p => p.path),
],
{ {
cwd: kbn.getAbsolute(), cwd: kbn.getAbsolute(),
} }
@ -84,9 +91,14 @@ async function getChangesForProjects(projects: ProjectMap, kbn: Kibana, log: Too
} }
const sortedRelevantProjects = Array.from(projects.values()).sort(projectBySpecificitySorter); const sortedRelevantProjects = Array.from(projects.values()).sort(projectBySpecificitySorter);
const changesByProject = new Map<Project, Changes>(); const changesByProject = new Map<Project, Changes | undefined>();
for (const project of sortedRelevantProjects) { for (const project of sortedRelevantProjects) {
if (kbn.isOutsideRepo(project)) {
changesByProject.set(project, undefined);
continue;
}
const ownChanges: Changes = new Map(); const ownChanges: Changes = new Map();
const prefix = kbn.getRelative(project.path); const prefix = kbn.getRelative(project.path);
@ -114,6 +126,10 @@ async function getChangesForProjects(projects: ProjectMap, kbn: Kibana, log: Too
/** Get the latest commit sha for a project */ /** Get the latest commit sha for a project */
async function getLatestSha(project: Project, kbn: Kibana) { async function getLatestSha(project: Project, kbn: Kibana) {
if (kbn.isOutsideRepo(project)) {
return;
}
const { stdout } = await execa( const { stdout } = await execa(
'git', 'git',
['log', '-n', '1', '--pretty=format:%H', '--', project.path], ['log', '-n', '1', '--pretty=format:%H', '--', project.path],
@ -175,7 +191,7 @@ function resolveDepsForProject(project: Project, yarnLock: YarnLock, kbn: Kibana
*/ */
async function getChecksum( async function getChecksum(
project: Project, project: Project,
changes: Changes, changes: Changes | undefined,
yarnLock: YarnLock, yarnLock: YarnLock,
kbn: Kibana, kbn: Kibana,
log: ToolingLog log: ToolingLog
@ -185,7 +201,7 @@ async function getChecksum(
log.verbose(`[${project.name}] local sha:`, sha); log.verbose(`[${project.name}] local sha:`, sha);
} }
if (Array.from(changes.values()).includes('invalid')) { if (!changes || Array.from(changes.values()).includes('invalid')) {
log.warning(`[${project.name}] unable to determine local changes, caching disabled`); log.warning(`[${project.name}] unable to determine local changes, caching disabled`);
return; return;
} }
@ -248,7 +264,7 @@ export async function getAllChecksums(kbn: Kibana, log: ToolingLog) {
Array.from(projects.values()).map(async project => { Array.from(projects.values()).map(async project => {
cacheKeys.set( cacheKeys.set(
project.name, project.name,
await getChecksum(project, changesByProject.get(project)!, yarnLock, kbn, log) await getChecksum(project, changesByProject.get(project), yarnLock, kbn, log)
); );
}) })
); );

View file

@ -17576,7 +17576,7 @@ is-path-inside@^2.1.0:
dependencies: dependencies:
path-is-inside "^1.0.2" path-is-inside "^1.0.2"
is-path-inside@^3.0.1: is-path-inside@^3.0.1, is-path-inside@^3.0.2:
version "3.0.2" version "3.0.2"
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.2.tgz#f5220fc82a3e233757291dddc9c5877f2a1f3017" resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.2.tgz#f5220fc82a3e233757291dddc9c5877f2a1f3017"
integrity sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg== integrity sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg==