Skip to content

Commit

Permalink
feat(preset): support _VERSION updates within bitbucket pipelines (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed May 10, 2024
1 parent 9499673 commit 760291c
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
121 changes: 121 additions & 0 deletions lib/config/presets/internal/regex-managers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,127 @@ import { extractPackageFile } from '../../../modules/manager/custom/regex';
import { presets } from './regex-managers';

describe('config/presets/internal/regex-managers', () => {
describe('Update `_VERSION` variables in Bitbucket Pipelines', () => {
const customManager =
presets['bitbucketPipelinesVersions'].customManagers?.[0];

it(`find dependencies in file`, async () => {
const fileContent = codeBlock`
script:
# renovate: datasource=docker depName=node versioning=docker
- export NODE_VERSION=18
# renovate: datasource=npm depName=pnpm
- export PNPM_VERSION="7.25.1"
# renovate: datasource=npm depName=yarn
- export YARN_VERSION 3.3.1
# renovate: datasource=custom.hashicorp depName=consul
- export CONSUL_VERSION 1.3.1
# renovate: datasource=github-releases depName=kubernetes-sigs/kustomize versioning=regex:^(?<compatibility>.+)/v(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)$ extractVersion=^kustomize/(?<version>.+)$
- export KUSTOMIZE_VERSION v5.2.1
- pipe: something/cool:latest
variables:
# renovate: datasource=docker depName=node versioning=docker
NODE_VERSION: 18
# renovate: datasource=npm depName=pnpm
PNPM_VERSION:"7.25.1"
# renovate: datasource=npm depName=yarn
YARN_VERSION: '3.3.1'
- echo $NODE_VERSION
`;

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

expect(res?.deps).toMatchObject([
{
currentValue: '18',
datasource: 'docker',
depName: 'node',
replaceString:
'# renovate: datasource=docker depName=node versioning=docker\n - export NODE_VERSION=18\n',
versioning: 'docker',
},
{
currentValue: '7.25.1',
datasource: 'npm',
depName: 'pnpm',
replaceString:
'# renovate: datasource=npm depName=pnpm\n - export PNPM_VERSION="7.25.1"\n',
},
{
currentValue: '3.3.1',
datasource: 'npm',
depName: 'yarn',
replaceString:
'# renovate: datasource=npm depName=yarn\n - export YARN_VERSION 3.3.1\n',
},
{
currentValue: '1.3.1',
datasource: 'custom.hashicorp',
depName: 'consul',
replaceString:
'# renovate: datasource=custom.hashicorp depName=consul\n - export CONSUL_VERSION 1.3.1\n',
},
{
currentValue: 'v5.2.1',
datasource: 'github-releases',
depName: 'kubernetes-sigs/kustomize',
replaceString:
'# renovate: datasource=github-releases depName=kubernetes-sigs/kustomize versioning=regex:^(?<compatibility>.+)/v(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)$ extractVersion=^kustomize/(?<version>.+)$\n - export KUSTOMIZE_VERSION v5.2.1\n',
extractVersion: '^kustomize/(?<version>.+)$',
versioning:
'regex:^(?<compatibility>.+)/v(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)$',
},
{
currentValue: '18',
datasource: 'docker',
depName: 'node',
replaceString:
'# renovate: datasource=docker depName=node versioning=docker\n NODE_VERSION: 18\n',
versioning: 'docker',
},
{
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",
},
]);
});

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

describe('Update `_VERSION` variables in Dockerfiles', () => {
const customManager = presets['dockerfileVersions'].customManagers?.[0];

Expand Down
12 changes: 12 additions & 0 deletions lib/config/presets/internal/regex-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ export const presets: Record<string, Preset> = {
description:
'Update `$schema` version in `biome.json` configuration files.',
},
bitbucketPipelinesVersions: {
customManagers: [
{
customType: 'regex',
fileMatch: ['(^|/)bitbucket-pipelines\\.ya?ml$'],
matchStrings: [
'# renovate: datasource=(?<datasource>[a-z-.]+?) depName=(?<depName>[^\\s]+?)(?: (lookupName|packageName)=(?<packageName>[^\\s]+?))?(?: versioning=(?<versioning>[^\\s]+?))?(?: extractVersion=(?<extractVersion>[^\\s]+?))?(?: registryUrl=(?<registryUrl>[^\\s]+?))?\\s+.*\\s+[A-Za-z0-9_]+?_VERSION[ =:]\\s?["\']?(?<currentValue>.+?)["\']?\\s',
],
},
],
description: 'Update `_VERSION` variables in Bitbucket Pipelines',
},
dockerfileVersions: {
customManagers: [
{
Expand Down

0 comments on commit 760291c

Please sign in to comment.