Skip to content

Commit

Permalink
feat!: default to semver-coerced instead of semver (#20573)
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor authored and rarkins committed Mar 4, 2023
1 parent 06936dd commit a6bbf93
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/modules/datasource/gitlab-releases/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Now you may use comments in your `versions.ini` files to automatically update de
NKJS_VERSION=3.4.0
```

By default, `gitlab-releases` uses the `semver` versioning scheme.
By default, `gitlab-releases` uses the `semver-coerced` versioning scheme.
2 changes: 1 addition & 1 deletion lib/modules/datasource/gitlab-tags/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Now you may use comments in your `versions.ini` files to automatically update de
NKJS_VERSION=3.4.0
```

By default, `gitlab-tags` uses the `semver` versioning scheme.
By default, `gitlab-tags` uses the `semver-coerced` versioning scheme.
2 changes: 1 addition & 1 deletion lib/modules/datasource/repology/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ When the operating system package for `gcc` of `Alpine Linux 3.12` is updated, R
<!-- prettier-ignore -->
!!! tip
We recommend you try `loose` or `deb` versioning for distribution packages first.
This is because the version number usually doesn't match Renovate's default `semver` specification.
This is because the version number usually doesn't match Renovate's default `semver-coerced` specification.
6 changes: 3 additions & 3 deletions lib/modules/manager/regex/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Before Renovate can look up a dependency and decide about updates, it needs this

- The dependency's name
- Which `datasource` to use: npm, Docker, GitHub tags, and so on. For how to format this references see [datasource overview](https://docs.renovatebot.com/modules/datasource/#supported-datasources)
- Which version scheme to use: defaults to `semver`, but you may set another value like `pep440`. Supported versioning schemes can be found in the [versioning overview](https://docs.renovatebot.com/modules/versioning/#supported-versioning)
- Which version scheme to use: defaults to `semver-coerced`, but you may set another value like `pep440`. Supported versioning schemes can be found in the [versioning overview](https://docs.renovatebot.com/modules/versioning/#supported-versioning)

Configuration-wise, it works like this:

Expand All @@ -29,7 +29,7 @@ Configuration-wise, it works like this:
- You can optionally have a `packageName` capture group or a `packageNameTemplate` if it differs from `depName`
- You must have either a `datasource` capture group or a `datasourceTemplate` config field
- You can optionally have a `depType` capture group or a `depTypeTemplate` config field
- You can optionally have a `versioning` capture group or a `versioningTemplate` config field. If neither are present, `semver` will be used as the default
- You can optionally have a `versioning` capture group or a `versioningTemplate` config field. If neither are present, `semver-coerced` will be used as the default
- You can optionally have an `extractVersion` capture group or an `extractVersionTemplate` config field
- You can optionally have a `currentDigest` capture group.
- You can optionally have a `registryUrl` capture group or a `registryUrlTemplate` config field
Expand Down Expand Up @@ -119,7 +119,7 @@ You could configure Renovate to update the `Dockerfile` like this:
}
```

We could drop the `versioningTemplate` because Renovate defaults to `semver` versioning.
We could drop the `versioningTemplate` because Renovate defaults to `semver-coerced` versioning.
But we included the `versioningTemplate` config option to show you why we call these fields _templates_: because they are compiled using Handlebars and so can be composed from values you collect in named capture groups.

You should use triple brace `{{{ }}}` templates like `{{{versioning}}}` to be safe.
Expand Down
7 changes: 4 additions & 3 deletions lib/modules/versioning/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loadModules } from '../../util/modules';
import { isVersioningApiConstructor } from './common';
import { GenericVersion, GenericVersioningApi } from './generic';
import * as semverVersioning from './semver';
import * as semverCoercedVersioning from './semver-coerced';
import type { VersioningApi, VersioningApiConstructor } from './types';
import * as allVersioning from '.';

Expand Down Expand Up @@ -57,12 +58,12 @@ describe('modules/versioning/index', () => {
}
});

it('should fallback to semver', () => {
it('should fallback to semver-coerced', () => {
expect(allVersioning.get(undefined)).toBe(
allVersioning.get(semverVersioning.id)
allVersioning.get(semverCoercedVersioning.id)
);
expect(allVersioning.get('unknown')).toBe(
allVersioning.get(semverVersioning.id)
allVersioning.get(semverCoercedVersioning.id)
);
});

Expand Down
16 changes: 12 additions & 4 deletions lib/modules/versioning/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { logger } from '../../logger';
import versionings from './api';
import { isVersioningApiConstructor } from './common';
import * as semverCoerced from './semver-coerced';
import type { VersioningApi, VersioningApiConstructor } from './types';

export * from './types';

const defaultVersioning = semverCoerced;

export const getVersioningList = (): string[] => Array.from(versionings.keys());
/**
* Get versioning map. Can be used to dynamically add new versioning type
Expand All @@ -16,8 +19,10 @@ export const getVersionings = (): Map<

export function get(versioning: string | undefined): VersioningApi {
if (!versioning) {
logger.trace('Missing versioning, using semver as fallback.');
return versionings.get('semver') as VersioningApi;
logger.trace(
`Missing versioning, using ${defaultVersioning.id} as fallback.`
);
return defaultVersioning.api;
}
const [versioningName, ...versioningRest] = versioning.split(':');
const versioningConfig = versioningRest.length
Expand All @@ -26,8 +31,11 @@ export function get(versioning: string | undefined): VersioningApi {

const theVersioning = versionings.get(versioningName);
if (!theVersioning) {
logger.info({ versioning }, 'Unknown versioning - defaulting to semver');
return versionings.get('semver') as VersioningApi;
logger.info(
{ versioning },
`Unknown versioning - defaulting to ${defaultVersioning.id}`
);
return defaultVersioning.api;
}
if (isVersioningApiConstructor(theVersioning)) {
return new theVersioning(versioningConfig);
Expand Down
7 changes: 5 additions & 2 deletions lib/modules/versioning/semver-coerced/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Renovate's Coerced Semantic Versioning is a forgiving variant of [Semantic Versioning 2.0](https://semver.org) with coercion enabled for versions.

This versioning provides a very forgiving translation of inputs in non-strict-SemVer format into strict SemVer. For example, "v1" is coerced into "1.0.0", "2.1" => "2.1.0", "~3.1" => "3.1.0", "1.1-foo" => "1.1.0". Look at the Coercion section of [this page](https://www.npmjs.com/package/semver) for more info on input coercion.
This versioning provides a very forgiving translation of inputs in non-strict-SemVer format into strict SemVer.
For example, "v1" is coerced into "1.0.0", "2.1" => "2.1.0", "~3.1" => "3.1.0", "1.1-foo" => "1.1.0".
Look at the Coercion section of [this page](https://www.npmjs.com/package/semver) for more info on input coercion.

Since this versioning is very forgiving, it doesn't actually provide the coercion for version ranges. The range functions only accept strict SemVer as input and equivalent to those provided by the Renovate's semver versioning.
Since this versioning is very forgiving, it doesn't actually provide the coercion for version ranges.
The range functions only accept strict SemVer as input and equivalent to those provided by the Renovate's semver versioning.
2 changes: 2 additions & 0 deletions lib/util/package-rules/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ describe('util/package-rules/index', () => {

it('checks if matchCurrentVersion selector is valid and satisfies the condition on range overlap', () => {
const config: TestConfig = {
versioning: 'semver',
packageRules: [
{
matchPackageNames: ['test'],
Expand Down Expand Up @@ -699,6 +700,7 @@ describe('util/package-rules/index', () => {

it('checks if matchCurrentVersion selector is valid and satisfies the condition on pinned to range overlap', () => {
const config: TestConfig = {
versioning: 'semver',
packageRules: [
{
matchPackageNames: ['test'],
Expand Down

0 comments on commit a6bbf93

Please sign in to comment.