Skip to content

Commit

Permalink
feat(presets): add regex preset for gitlab pipeline versions (#24510)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
3 people committed Sep 28, 2023
1 parent 5f82d9d commit 93b3a7a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
77 changes: 76 additions & 1 deletion lib/config/presets/internal/regex-managers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,81 @@ describe('config/presets/internal/regex-managers', () => {
});
});

describe('Update `_VERSION` environment variables in GitLab pipeline file', () => {
const customManager = presets['gitlabPipelineVersions'].customManagers?.[0];

it(`find dependencies in file`, async () => {
const fileContent = codeBlock`
variables:
# renovate: datasource=node depName=node versioning=node
NODE_VERSION: 18.13.0
# renovate: datasource=npm depName=pnpm
PNPM_VERSION: "7.25.1"
# renovate: datasource=npm depName=yarn
YARN_VERSION: '3.3.1'
# renovate: datasource=custom.hashicorp depName=consul
CONSUL_VERSION: 1.3.1
lint:
image: node:\${NODE_VERSION}
script:
- npm install -g pnpm@\${PNPM_VERSION}
`;

const res = await extractPackageFile(
fileContent,
'gitlab-ci.yml',
customManager!
);

expect(res?.deps).toMatchObject([
{
currentValue: '18.13.0',
datasource: 'node-version',
depName: 'node',
replaceString:
'# renovate: datasource=node depName=node versioning=node\n NODE_VERSION: 18.13.0\n',
versioning: 'node',
},
{
currentValue: '7.25.1',
datasource: 'npm',
depName: 'pnpm',
replaceString:
'# renovate: datasource=npm depName=pnpm\n PNPM_VERSION: "7.25.1"\n',
},
{
currentValue: '3.3.1',
datasource: 'npm',
depName: 'yarn',
replaceString:
"# renovate: datasource=npm depName=yarn\n YARN_VERSION: '3.3.1'\n",
},
{
currentValue: '1.3.1',
datasource: 'custom.hashicorp',
depName: 'consul',
replaceString:
'# renovate: datasource=custom.hashicorp depName=consul\n CONSUL_VERSION: 1.3.1\n',
},
]);
});

describe('matches regexes patterns', () => {
it.each`
path | expected
${'.gitlab-ci.yaml'} | ${true}
${'.gitlab-ci.yml'} | ${true}
${'foo.yaml'} | ${false}
${'foo.yml'} | ${false}
${'.gitlab/ci.yml'} | ${false}
${'includes/gitlab-ci.yml'} | ${false}
`('$path', ({ path, expected }) => {
expect(regexMatches(path, customManager!.fileMatch)).toBe(expected);
});
});
});

describe('Update `appVersion` value in Helm chart Chart.yaml', () => {
const customManager =
presets['helmChartYamlAppVersions'].customManagers?.[0];
Expand Down Expand Up @@ -246,7 +321,7 @@ describe('config/presets/internal/regex-managers', () => {
<groovy.version>4.0.10</groovy.version>
<!-- renovate: datasource=docker depName=mongo -->
<mongo.container.version>4.4.6</mongo.container.version>
<mongo.container.version>4.4.6</mongo.container.version>
`;

const res = await extractPackageFile(
Expand Down
13 changes: 13 additions & 0 deletions lib/config/presets/internal/regex-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ export const presets: Record<string, Preset> = {
description:
'Update `_VERSION` environment variables in GitHub Action files.',
},
gitlabPipelineVersions: {
customManagers: [
{
customType: 'regex',
fileMatch: ['\\.gitlab-ci\\.ya?ml$'],
matchStrings: [
'# renovate: datasource=(?<datasource>[a-z-.]+?) depName=(?<depName>[^\\s]+?)(?: (?:packageName)=(?<packageName>[^\\s]+?))?(?: versioning=(?<versioning>[a-z-0-9]+?))?\\s+[A-Za-z0-9_]+?_VERSION\\s*:\\s*["\']?(?<currentValue>.+?)["\']?\\s',
],
},
],
description:
'Update `_VERSION` environment variables in GitLab pipeline file.',
},
helmChartYamlAppVersions: {
customManagers: [
{
Expand Down

0 comments on commit 93b3a7a

Please sign in to comment.