From c2f713d7691f2d89804c95ac50d4e617493d88d7 Mon Sep 17 00:00:00 2001 From: Jack Pierce <jackhpierce@gmail.com> Date: Tue, 14 Dec 2021 02:14:13 -0500 Subject: [PATCH] feat(buildkite): support git-hosted plugins (#13042) --- .../buildkite/__fixtures__/pipeline3.yml | 8 ------ .../buildkite/__fixtures__/pipeline5.yml | 6 +++++ .../__snapshots__/extract.spec.ts.snap | 26 +++++++++++++++---- lib/manager/buildkite/extract.spec.ts | 8 +++++- lib/manager/buildkite/extract.ts | 19 +++++++++++--- 5 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 lib/manager/buildkite/__fixtures__/pipeline5.yml diff --git a/lib/manager/buildkite/__fixtures__/pipeline3.yml b/lib/manager/buildkite/__fixtures__/pipeline3.yml index 4158f6806d..fe34280996 100644 --- a/lib/manager/buildkite/__fixtures__/pipeline3.yml +++ b/lib/manager/buildkite/__fixtures__/pipeline3.yml @@ -8,14 +8,6 @@ steps: - wait - # Use the app image built above to run concurrent tests - - name: "Docker Test %n" - command: test.sh - parallelism: 25 - plugins: - https://github.com/buildkite/plugin-docker-compose#v1.3.2: - run: app - - name: "wrong" command: test.sh parallelism: 25 diff --git a/lib/manager/buildkite/__fixtures__/pipeline5.yml b/lib/manager/buildkite/__fixtures__/pipeline5.yml new file mode 100644 index 0000000000..c8876504a0 --- /dev/null +++ b/lib/manager/buildkite/__fixtures__/pipeline5.yml @@ -0,0 +1,6 @@ +steps: + - plugins: + - ssh://git@github.company.com/some-org/some-plugin#v3.2.7: + username: abc + - https://github.company.com/some-third-org/some-third-plugin#v0.0.1: + build: app diff --git a/lib/manager/buildkite/__snapshots__/extract.spec.ts.snap b/lib/manager/buildkite/__snapshots__/extract.spec.ts.snap index a10c85886d..7688b796bf 100644 --- a/lib/manager/buildkite/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/buildkite/__snapshots__/extract.spec.ts.snap @@ -7,11 +7,6 @@ Array [ "depName": "namespace/docker-compose", "skipReason": "invalid-version", }, - Object { - "currentValue": "v1.3.2", - "depName": "https://github.com/buildkite/plugin-docker-compose", - "skipReason": "git-plugin", - }, Object { "currentValue": "v1.3.2", "depName": "github.com/buildkite/plugin-docker-compose", @@ -53,6 +48,27 @@ Array [ ] `; +exports[`manager/buildkite/extract extractPackageFile() extracts git-based plugins 1`] = ` +Array [ + Object { + "currentValue": "v3.2.7", + "datasource": "github-tags", + "depName": "some-org/some-plugin", + "registryUrls": Array [ + "https://github.company.com", + ], + }, + Object { + "currentValue": "v0.0.1", + "datasource": "github-tags", + "depName": "some-third-org/some-third-plugin", + "registryUrls": Array [ + "https://github.company.com", + ], + }, +] +`; + exports[`manager/buildkite/extract extractPackageFile() extracts multiple plugins in same file 1`] = ` Array [ Object { diff --git a/lib/manager/buildkite/extract.spec.ts b/lib/manager/buildkite/extract.spec.ts index 43dd8140be..1fe55b2c65 100644 --- a/lib/manager/buildkite/extract.spec.ts +++ b/lib/manager/buildkite/extract.spec.ts @@ -5,6 +5,7 @@ const pipeline1 = loadFixture('pipeline1.yml'); const pipeline2 = loadFixture('pipeline2.yml'); const pipeline3 = loadFixture('pipeline3.yml'); const pipeline4 = loadFixture('pipeline4.yml'); +const pipeline5 = loadFixture('pipeline5.yml'); describe('manager/buildkite/extract', () => { describe('extractPackageFile()', () => { @@ -24,12 +25,17 @@ describe('manager/buildkite/extract', () => { it('adds skipReason', () => { const res = extractPackageFile(pipeline3).deps; expect(res).toMatchSnapshot(); - expect(res).toHaveLength(3); + expect(res).toHaveLength(2); }); it('extracts arrays of plugins', () => { const res = extractPackageFile(pipeline4).deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(4); }); + it('extracts git-based plugins', () => { + const res = extractPackageFile(pipeline5).deps; + expect(res).toMatchSnapshot(); + expect(res).toHaveLength(2); + }); }); }); diff --git a/lib/manager/buildkite/extract.ts b/lib/manager/buildkite/extract.ts index 2c4ae344b5..6e008b5dbe 100644 --- a/lib/manager/buildkite/extract.ts +++ b/lib/manager/buildkite/extract.ts @@ -37,9 +37,20 @@ export function extractPackageFile(content: string): PackageFile | null { logger.trace('depLineMatch'); let skipReason: SkipReason; let repo: string; - if (depName.startsWith('https://') || depName.startsWith('git@')) { - logger.debug({ dependency: depName }, 'Skipping git plugin'); - skipReason = SkipReason.GitPlugin; + const gitPluginMatch = regEx( + /(ssh:\/\/git@|https:\/\/)(?<registry>[^/]+)\/(?<gitPluginName>.*)/ + ).exec(depName); + if (gitPluginMatch) { + logger.debug('Examining git plugin'); + const { registry, gitPluginName } = gitPluginMatch.groups; + const dep: PackageDependency = { + depName: gitPluginName, + currentValue: currentValue, + registryUrls: ['https://' + registry], + datasource: datasourceGithubTags.id, + }; + deps.push(dep); + continue; } else if (isVersion(currentValue)) { const splitName = depName.split('/'); if (splitName.length === 1) { @@ -76,8 +87,10 @@ export function extractPackageFile(content: string): PackageFile | null { } catch (err) /* istanbul ignore next */ { logger.warn({ err }, 'Error extracting buildkite plugins'); } + if (!deps.length) { return null; } + return { deps }; } -- GitLab