Skip to content

Commit

Permalink
feat(versioning/regex): add revision as fifth capture group (#21555)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Apr 18, 2023
1 parent 60ac8c7 commit 4fa199e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
20 changes: 15 additions & 5 deletions lib/modules/versioning/regex/index.spec.ts
@@ -1,16 +1,26 @@
import { VersioningApi, get } from '..';
import { get } from '..';
import { CONFIG_VALIDATION } from '../../../constants/error-messages';

describe('modules/versioning/regex/index', () => {
describe('regex versioning', () => {
const regex: VersioningApi = get(
const regex = get(
'regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?<prerelease>[^.-]+)?(?:-(?<compatibility>.*))?$'
);

it('requires a valid configuration to be initialized', () => {
expect(() => get('regex:not a regex')).toThrow();
});

it('works without config', () => {
const re = get('regex');
expect(re.isValid('alpine')).toBeFalse();
});

it('works with missing version', () => {
const re = get('regex:^(?<major>\\d+)?(?<compabillity>.+)');
expect(re.isValid('alpine')).toBeTrue();
});

describe('throws', () => {
for (const re of [
'^(?<major>\\d+)(',
Expand Down Expand Up @@ -43,7 +53,7 @@ describe('modules/versioning/regex/index', () => {
${'1.2.aardvark-foo'} | ${false}
${'1.2a2.3'} | ${false}
`('isValid("$version") === $expected', ({ version, expected }) => {
expect(!!regex.isValid(version)).toBe(expected);
expect(regex.isValid(version)).toBe(expected);
});

test.each`
Expand Down Expand Up @@ -342,9 +352,9 @@ describe('modules/versioning/regex/index', () => {
);
});

describe('Supported 4th number as build', () => {
describe('Supported 4th number as build and 5th as revision', () => {
const re = get(
'regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(:?-(?<compatibility>.*-r)(?<build>\\d+))?$'
'regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(:?-(?<compatibility>.+)(?<build>\\d+)-r(?<revision>\\d+))?$'
);

test.each`
Expand Down
6 changes: 5 additions & 1 deletion lib/modules/versioning/regex/index.ts
Expand Up @@ -71,7 +71,8 @@ export class RegExpVersioningApi extends GenericVersioningApi<RegExpVersion> {
return null;
}

const { major, minor, patch, build, prerelease, compatibility } = groups;
const { major, minor, patch, build, revision, prerelease, compatibility } =
groups;
const release = [
typeof major === 'undefined' ? 0 : Number.parseInt(major, 10),
typeof minor === 'undefined' ? 0 : Number.parseInt(minor, 10),
Expand All @@ -80,6 +81,9 @@ export class RegExpVersioningApi extends GenericVersioningApi<RegExpVersion> {

if (build) {
release.push(Number.parseInt(build, 10));
if (revision) {
release.push(Number.parseInt(revision, 10));
}
}

return {
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/versioning/regex/readme.md
Expand Up @@ -5,6 +5,7 @@ The valid capture groups for `regex` versioning are:

- `major`, `minor`, and `patch`: at least one of these must be provided. When determining whether a package has updates, these values will be compared in the standard semantic versioning fashion. If any of these fields are omitted, they will be treated as if they were `0` -- in this way, you can describe versioning schemes with up to three incrementing values.
- `build`: this capture group can be used after you've already used the `major`, `minor` and `patch` capture groups and need a fourth version part. `build` updates are handled like `patch` updates.
- `revision`: this capture group can be used after you've already used the `build` capture groups and need a fifth version part. `revision` updates are handled like `patch` updates.
- `prerelease`: this value, if captured, will mark a given release as a prerelease (e.g. unstable). If this value is captured and you have configured `"ignoreUnstable": true`, the given release will be skipped.
- `compatibility`: this value defines the "build compatibility" of a given dependency. A proposed Renovate update will never change the specified compatibility value. For example, if you are pinning to `1.2.3-linux` (and `linux` is captured as the compatibility value), Renovate will not update you to `1.2.4-osx`.

Expand Down Expand Up @@ -37,15 +38,15 @@ Here is another example, this time for handling `python` Docker images, which us
}
```

Here is another example, this time for handling Bitnami Docker images, which use build indicators as well as version suffixes for compatibility:
Here is another example, this time for handling Bitnami Docker images, which use `build` and `revision` indicators as well as version suffixes for compatibility:

```json
{
"packageRules": [
{
"matchDatasources": ["docker"],
"matchPackagePrefixes": ["bitnami/"],
"versioning": "regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(:?-(?<compatibility>.*-r)(?<build>\\d+))?$"
"versioning": "regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(:?-(?<compatibility>.+)(?<build>\\d+)-r(?<revision>\\d+))?$"
}
]
}
Expand Down

0 comments on commit 4fa199e

Please sign in to comment.