Skip to content

Commit

Permalink
feat(woodpecker): Adding woodpecker v1.x support (#23838)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramigoldvarg authored Aug 29, 2023
1 parent 4ad21ed commit 3dbbc0a
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
103 changes: 103 additions & 0 deletions lib/modules/manager/woodpecker/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,108 @@ describe('modules/manager/woodpecker/extract', () => {
],
});
});

it('extracts the v.1.0.x version', () => {
const res = extractPackageFile(
`
steps:
redis:
image: quay.io/something/redis:alpine
`,
'',
{}
);
expect(res).toEqual({
deps: [
{
depName: 'quay.io/something/redis',
currentValue: 'alpine',
currentDigest: undefined,
replaceString: 'quay.io/something/redis:alpine',
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
},
],
});
});

it('should parse multiple sources of dependencies together', () => {
const res = extractPackageFile(
`
clone:
git:
image: woodpeckerci/plugin-git:latest
steps:
redis:
image: quay.io/something/redis:alpine
`,
'',
{}
);

expect(res).toEqual({
deps: [
{
depName: 'woodpeckerci/plugin-git',
currentValue: 'latest',
currentDigest: undefined,
replaceString: 'woodpeckerci/plugin-git:latest',
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
},
{
depName: 'quay.io/something/redis',
currentValue: 'alpine',
currentDigest: undefined,
replaceString: 'quay.io/something/redis:alpine',
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
},
],
});
});

it('return dependency when an plugin-git is cloned', () => {
const res = extractPackageFile(
`
clone:
git:
image: woodpeckerci/plugin-git:latest
`,
'',
{}
);

expect(res).toEqual({
deps: [
{
depName: 'woodpeckerci/plugin-git',
currentValue: 'latest',
currentDigest: undefined,
replaceString: 'woodpeckerci/plugin-git:latest',
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
},
],
});
});

it('return null when no dependencies are provided', () => {
const res = extractPackageFile(
`
info:
version:
3.5
`,
'',
{}
);

expect(res).toBeNull();
});
});
});
24 changes: 21 additions & 3 deletions lib/modules/manager/woodpecker/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import { getDep } from '../dockerfile/extract';
import type { ExtractConfig, PackageFileContent } from '../types';
import type { WoodpeckerConfig } from './types';

function woodpeckerVersionDecider(
woodpeckerConfig: WoodpeckerConfig
): (keyof WoodpeckerConfig)[] {
const keys = ['clone', 'steps', 'pipeline'];
return Object.keys(woodpeckerConfig).filter((key) =>
keys.includes(key)
) as (keyof WoodpeckerConfig)[];
}

export function extractPackageFile(
content: string,
packageFile: string,
Expand Down Expand Up @@ -37,11 +46,20 @@ export function extractPackageFile(
return null;
}

const pipelineKeys = woodpeckerVersionDecider(config);

if (pipelineKeys.length === 0) {
logger.debug({ packageFile }, "Couldn't identify dependencies");
return null;
}

// Image name/tags for services are only eligible for update if they don't
// use variables and if the image is not built locally
const deps = Object.values(config.pipeline ?? {})
.filter((step) => is.string(step?.image))
.map((step) => getDep(step.image, true, extractConfig.registryAliases));
const deps = pipelineKeys.flatMap((pipelineKey) =>
Object.values(config[pipelineKey] ?? {})
.filter((step) => is.string(step?.image))
.map((step) => getDep(step.image, true, extractConfig.registryAliases))
);

logger.trace({ deps }, 'Woodpecker Configuration image');
return deps.length ? { deps } : null;
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/manager/woodpecker/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export type WoodpeckerConfig = {
pipeline?: Record<string, WoodpeckerStep>;
steps?: Record<string, WoodpeckerStep>;
clone?: Record<string, WoodpeckerStep>;
};

export interface WoodpeckerStep {
Expand Down

0 comments on commit 3dbbc0a

Please sign in to comment.