Skip to content
Snippets Groups Projects
Unverified Commit 06a22629 authored by Jack Pierce's avatar Jack Pierce Committed by GitHub
Browse files

fix(buildkite): inspect all lines for plugin definitions (#15548)

parent 123d4263
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ steps:
# Prebuild the app image, upload it to a registry for later steps
- name: "Docker Build"
plugins:
docker-compose#v1.3.2:
docker-compose#v1.3.2: # Comment at the end....
build: app
image-repository: index.docker.io/org/repo
......
.docker-options: &some-options
propagate-environment: true
copy-checkout: true
.python3-container: &python3-container
ssh://git@github.some-domain.com/some-org/some-plugin#v3.2.7:
some-config: some-value
<<: *some-options
......@@ -49,5 +49,16 @@ describe('modules/manager/buildkite/extract', () => {
expect(res).toHaveLength(1);
expect(res).toEqual([expectedPackageDependency]);
});
it('extracts plugins outside plugins sections', () => {
const res = extractPackageFile(Fixtures.get('pipeline7.yml'))?.deps;
const expectedPackageDependency: PackageDependency = {
currentValue: 'v3.2.7',
datasource: 'github-tags',
depName: 'some-org/some-plugin',
registryUrls: ['https://github.some-domain.com'],
};
expect(res).toEqual([expectedPackageDependency]);
});
});
});
......@@ -9,85 +9,66 @@ export function extractPackageFile(content: string): PackageFile | null {
const deps: PackageDependency[] = [];
try {
const lines = content.split(newlineRegex);
let isPluginsSection = false;
let pluginsIndent = '';
for (let lineNumber = 1; lineNumber <= lines.length; lineNumber += 1) {
const lineIdx = lineNumber - 1;
const line = lines[lineIdx];
const pluginsSection = regEx(
/^(?<pluginsIndent>\s*)(-?\s*)plugins:/
for (const line of lines) {
// Search each line for plugin names
const depLineMatch = regEx(
/^[\s-]*(?<depName>[^#\s]+)#(?<currentValue>[^:]+)/
).exec(line);
if (pluginsSection?.groups) {
logger.trace(`Matched plugins on line ${lineNumber}`);
isPluginsSection = true;
pluginsIndent = pluginsSection.groups.pluginsIndent;
} else if (isPluginsSection) {
logger.debug(`serviceImageLine: "${line}"`);
const { currentIndent } = regEx(/^(?<currentIndent>\s*)/).exec(line)
?.groups ?? /* istanbul ignore next: should never happen */ {
currentIndent: '',
};
const depLineMatch = regEx(
/^\s+(?:-\s+)?(?<depName>[^#]+)#(?<currentValue>[^:]+)/
).exec(line);
if (currentIndent.length <= pluginsIndent.length) {
isPluginsSection = false;
pluginsIndent = '';
} else if (depLineMatch?.groups) {
const { depName, currentValue } = depLineMatch.groups;
logger.trace('depLineMatch');
let skipReason: SkipReason | undefined;
let repo: string | undefined;
const gitPluginMatch = regEx(
/(ssh:\/\/git@|https:\/\/)(?<registry>[^/]+)\/(?<gitPluginName>.*)/
).exec(depName);
if (gitPluginMatch?.groups) {
logger.debug('Examining git plugin');
const { registry, gitPluginName } = gitPluginMatch.groups;
const gitDepName = gitPluginName.replace(regEx('\\.git$'), '');
const dep: PackageDependency = {
depName: gitDepName,
currentValue: currentValue,
registryUrls: ['https://' + registry],
datasource: GithubTagsDatasource.id,
};
deps.push(dep);
continue;
} else if (isVersion(currentValue)) {
const splitName = depName.split('/');
if (splitName.length === 1) {
repo = `buildkite-plugins/${depName}-buildkite-plugin`;
} else if (splitName.length === 2) {
repo = `${depName}-buildkite-plugin`;
} else {
logger.warn(
{ dependency: depName },
'Something is wrong with buildkite plugin name'
);
skipReason = 'invalid-dependency-specification';
}
} else {
logger.debug(
{ currentValue },
'Skipping non-pinned current version'
);
skipReason = 'invalid-version';
}
if (depLineMatch?.groups) {
const { depName, currentValue } = depLineMatch.groups;
logger.trace('depLineMatch');
let skipReason: SkipReason | undefined;
let repo: string | undefined;
logger.debug({ depName }, 'Found BuildKite plugin');
// Plugins may simply be git repos. If so, we need to parse out the registry.
const gitPluginMatch = regEx(
/(ssh:\/\/git@|https:\/\/)(?<registry>[^/]+)\/(?<gitPluginName>.*)/
).exec(depName);
if (gitPluginMatch?.groups) {
logger.debug('Examining git plugin');
const { registry, gitPluginName } = gitPluginMatch.groups;
const gitDepName = gitPluginName.replace(regEx('\\.git$'), '');
const dep: PackageDependency = {
depName,
currentValue,
skipReason,
depName: gitDepName,
currentValue: currentValue,
registryUrls: ['https://' + registry],
datasource: GithubTagsDatasource.id,
};
if (repo) {
dep.datasource = GithubTagsDatasource.id;
dep.packageName = repo;
}
deps.push(dep);
continue;
} else if (isVersion(currentValue)) {
const splitName = depName.split('/');
if (splitName.length === 1) {
repo = `buildkite-plugins/${depName}-buildkite-plugin`;
} else if (splitName.length === 2) {
repo = `${depName}-buildkite-plugin`;
} else {
logger.warn(
{ dependency: depName },
'Something is wrong with BuildKite plugin name'
);
skipReason = 'invalid-dependency-specification';
}
} else {
logger.debug({ currentValue }, 'Skipping non-pinned current version');
skipReason = 'invalid-version';
}
const dep: PackageDependency = {
depName,
currentValue,
skipReason,
};
if (repo) {
dep.datasource = GithubTagsDatasource.id;
dep.packageName = repo;
}
deps.push(dep);
}
}
} catch (err) /* istanbul ignore next */ {
logger.warn({ err }, 'Error extracting buildkite plugins');
logger.warn({ err }, 'Error extracting BuildKite plugins');
}
if (!deps.length) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment