Skip to content

Commit

Permalink
feat: versionScheme -> versioning (#5504)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 18, 2020
1 parent 5d88d3b commit 485f669
Show file tree
Hide file tree
Showing 88 changed files with 323 additions and 306 deletions.
2 changes: 1 addition & 1 deletion docs/development/adding-a-package-manager.md
Expand Up @@ -35,7 +35,7 @@ This function is mandatory unless you use `extractAllPackageFiles` instead. It t
- dependency name
- dependency type (e.g. dependencies, devDependencies, etc)
- currentValue
- version scheme used (e.g. semver, pep440)
- versioning used (e.g. semver, pep440)

The fields returned here can be customised to suit the package manager, e.g. Dockerfile uses `lineNumber`. Custom fields should be added within a `managerData` object.

Expand Down
6 changes: 3 additions & 3 deletions docs/usage/configuration-options.md
Expand Up @@ -1571,11 +1571,11 @@ When schedules are in use, it generally means "no updates". However there are ca

This defaults to `true`, meaning that Renovate will perform certain "desirable" updates to _existing_ PRs even when outside of schedule. If you wish to disable all updates outside of scheduled hours then configure this field to `false`.

## versionScheme
## versioning

Usually, each language or package manager has a specific type of "version scheme". e.g. JavaScript uses npm's semver implementation, Python uses pep440, etc. At Renovate we have also implemented some of our own, such as `"docker"` to address the most common way people tag versions using Docker, and `"loose"` as a fallback that tries semver first but otherwise just does its best to sort and compare.
Usually, each language or package manager has a specific type of "versioning". e.g. JavaScript uses npm's semver implementation, Python uses pep440, etc. At Renovate we have also implemented some of our own, such as `"docker"` to address the most common way people tag versions using Docker, and `"loose"` as a fallback that tries semver first but otherwise just does its best to sort and compare.

By exposing `versionScheme` to config, it allows you to override the default version scheme for a package manager if you really need. In most cases it would not be recommended, but there are some cases such as Docker or Gradle where versioning is not strictly defined and you may need to specify the versioning type per-package.
By exposing `versioning` to config, it allows you to override the default versioning for a package manager if you really need. In most cases it would not be recommended, but there are some cases such as Docker or Gradle where versioning is not strictly defined and you may need to specify the versioning type per-package.

## vulnerabilityAlerts

Expand Down
10 changes: 5 additions & 5 deletions docs/usage/docker.md
Expand Up @@ -27,15 +27,15 @@ Renovate by default will preserve the precision of Docker images. For example if

Although suffixes in semver indicate pre-releases (e.g. `v1.2.0-alpha.2`), in Docker they typically indicate compatibility, e.g. `12.2.0-alpine`. Renovate defaults to assuming suffixes indicate compatibility so will never _change_ it. e.g. `12.1.0-alpine` might get updated to `12.1.1-alpine` but never `12.1.1` or `12.1.1-stretch`.

If this behaviour does not suit a particular package you have, Renovate allows you to customize the `versionScheme` in use. For example, if you have a Docker image `foo/bar` that sticks to semver versioning and you need Renovate to understand that suffixes indicate pre-releases versions and not compatibility, then you could configure this package rule:
If this behaviour does not suit a particular package you have, Renovate allows you to customize the `versioning` in use. For example, if you have a Docker image `foo/bar` that sticks to semver versioning and you need Renovate to understand that suffixes indicate pre-releases versions and not compatibility, then you could configure this package rule:

```json
{
"packageRules": [
{
"datasources": ["docker"],
"packageNames": ["foo/bar"],
"versionScheme": "semver"
"versioning": "semver"
}
]
}
Expand All @@ -49,15 +49,15 @@ Another example is the official `python` image, which follows `pep440` versionin
{
"datasources": ["docker"],
"packageNames": ["python"],
"versionScheme": "pep440"
"versioning": "pep440"
}
]
}
```

If traditional versioning doesn't work, consider using Renovate's built-in `loose` `versionScheme`. It essentially just does a best effort sort of versions, regardless of whether they contain letters or digits.
If traditional versioning doesn't work, consider using Renovate's built-in `loose` `versioning`. It essentially just does a best effort sort of versions, regardless of whether they contain letters or digits.

Finally, if you use a Docker image that follows a versioning approach not captured by one of our existing version schemes, and which `loose` sorts incorrectly, you could see if the `regex` `versionScheme` can work. It uses regex capture group syntax to let you specify which part of the version string is major, minor, patch, pre-release, or compatibility. See the docs for `versionScheme` for documentation/examples of `regex` versioning in action.
Finally, if you use a Docker image that follows a versioning approach not captured by one of our existing versionings, and which `loose` sorts incorrectly, you could see if the `regex` `versioning` can work. It uses regex capture group syntax to let you specify which part of the version string is major, minor, patch, pre-release, or compatibility. See the docs for `versioning` for documentation/examples of `regex` versioning in action.

## Digest Pinning

Expand Down
22 changes: 10 additions & 12 deletions lib/config/definitions.ts
@@ -1,10 +1,8 @@
import { RenovateConfigStage } from './common';
import {
VERSION_SCHEME_DOCKER,
VERSION_SCHEME_PEP440,
VERSION_SCHEME_SEMVER,
} from '../constants/version-schemes';
import { getVersionSchemeList } from '../versioning';
import * as dockerVersioning from '../versioning/docker';
import * as pep440Versioning from '../versioning/pep440';
import * as semverVersioning from '../versioning/semver';
import { getVersioningList } from '../versioning';
import { PLATFORM_TYPE_GITHUB } from '../constants/platforms';
import { platformList } from '../platform';

Expand Down Expand Up @@ -633,11 +631,11 @@ const options: RenovateOptions[] = [
env: false,
},
{
name: 'versionScheme',
description: 'Version scheme to use for filtering and comparisons',
name: 'versioning',
description: 'versioning to use for filtering and comparisons',
type: 'string',
allowedValues: getVersionSchemeList(),
default: VERSION_SCHEME_SEMVER,
allowedValues: getVersioningList(),
default: semverVersioning.id,
cli: false,
env: false,
},
Expand Down Expand Up @@ -1462,7 +1460,7 @@ const options: RenovateOptions[] = [
stage: 'package',
type: 'object',
default: {
versionScheme: VERSION_SCHEME_DOCKER,
versioning: dockerVersioning.id,
managerBranchPrefix: 'docker-',
commitMessageTopic: '{{{depName}}} Docker tag',
major: { enabled: false },
Expand Down Expand Up @@ -1508,7 +1506,7 @@ const options: RenovateOptions[] = [
stage: 'package',
type: 'object',
default: {
versionScheme: VERSION_SCHEME_PEP440,
versioning: pep440Versioning.id,
},
mergeable: true,
cli: false,
Expand Down
4 changes: 4 additions & 0 deletions lib/config/migration.ts
Expand Up @@ -173,6 +173,10 @@ export function migrateConfig(
migratedConfig.extends[i] = 'config:js-lib';
}
}
} else if (key === 'versionScheme') {
isMigrated = true;
migratedConfig.versioning = val;
delete migratedConfig.versionScheme;
} else if (
key === 'automergeType' &&
is.string(val) &&
Expand Down
18 changes: 0 additions & 18 deletions lib/constants/version-schemes.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/datasource/common.ts
Expand Up @@ -11,7 +11,7 @@ export interface PkgReleaseConfig extends Config {
depType?: string;
lookupType?: string;
npmrc?: string;
versionScheme?: string;
versioning?: string;
}

export type DigestConfig = Config;
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/github/index.ts
Expand Up @@ -162,7 +162,7 @@ export async function getDigest(
/**
* github.getPkgReleases
*
* This function can be used to fetch releases with a customisable version scheme (e.g. semver) and with either tags or releases.
* This function can be used to fetch releases with a customisable versioning (e.g. semver) and with either tags or releases.
*
* This function will:
* - Fetch all tags or releases (depending on configuration)
Expand Down
14 changes: 6 additions & 8 deletions lib/datasource/index.ts
@@ -1,6 +1,6 @@
import { logger } from '../logger';
import { addMetaData } from './metadata';
import * as versioning from '../versioning';
import * as allVersioning from '../versioning';

import {
Datasource,
Expand All @@ -10,7 +10,7 @@ import {
ReleaseResult,
DigestConfig,
} from './common';
import { VERSION_SCHEME_SEMVER } from '../constants/version-schemes';
import * as semverVersioning from '../versioning/semver';
import { loadModules } from '../util/modules';

export * from './common';
Expand Down Expand Up @@ -73,12 +73,10 @@ export async function getPkgReleases(
if (!res) {
return res;
}
const versionScheme =
config && config.versionScheme
? config.versionScheme
: VERSION_SCHEME_SEMVER;
// Filter by version scheme
const version = versioning.get(versionScheme);
const versioning =
config && config.versioning ? config.versioning : semverVersioning.id;
// Filter by versioning
const version = allVersioning.get(versioning);
// Return a sorted list of valid Versions
function sortReleases(release1: Release, release2: Release): number {
return version.sortVersions(release1.version, release2.version);
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/maven/index.spec.ts
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import { resolve } from 'path';
import * as datasource from '..';
import { DATASOURCE_FAILURE } from '../../constants/error-messages';
import { VERSION_SCHEME_LOOSE } from '../../constants/version-schemes';
import * as looseVersioning from '../../versioning/loose';
import { DATASOURCE_MAVEN } from '../../constants/data-binary-source';
import * as hostRules from '../../util/host-rules';

Expand Down Expand Up @@ -34,7 +34,7 @@ const MYSQL_MAVEN_MYSQL_POM = fs.readFileSync(
);

const config = {
versionScheme: VERSION_SCHEME_LOOSE,
versioning: looseVersioning.id,
datasource: DATASOURCE_MAVEN,
};

Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/packagist/index.spec.ts
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import _got from '../../util/got';
import * as datasource from '..';
import * as _hostRules from '../../util/host-rules';
import { VERSION_SCHEME_COMPOSER } from '../../constants/version-schemes';
import * as composerVersioning from '../../versioning/composer';
import { DATASOURCE_PACKAGIST } from '../../constants/data-binary-source';

jest.mock('../../util/got');
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('datasource/packagist', () => {
hostRules.hosts = jest.fn(() => []);
global.repoCache = {};
config = {
versionScheme: VERSION_SCHEME_COMPOSER,
versioning: composerVersioning.id,
datasource: DATASOURCE_PACKAGIST,
registryUrls: [
'https://composer.renovatebot.com',
Expand Down
14 changes: 7 additions & 7 deletions lib/datasource/sbt/index.spec.ts
Expand Up @@ -4,7 +4,7 @@ import nock from 'nock';
import { getPkgReleases } from '.';
import { DEFAULT_MAVEN_REPO } from '../../manager/maven/extract';
import { parseIndexDir, SBT_PLUGINS_REPO } from './util';
import { VERSION_SCHEME_IVY } from '../../constants/version-schemes';
import * as ivyVersioning from '../../versioning/ivy';
import { DATASOURCE_SBT } from '../../constants/data-binary-source';

const mavenIndexHtml = fs.readFileSync(
Expand Down Expand Up @@ -101,15 +101,15 @@ describe('datasource/sbt', () => {
it('returns null in case of errors', async () => {
expect(
await getPkgReleases({
versionScheme: VERSION_SCHEME_IVY,
versioning: ivyVersioning.id,
datasource: DATASOURCE_SBT,
lookupName: 'org.scalatest:scalatest',
registryUrls: ['https://failed_repo/maven'],
})
).toEqual(null);
expect(
await getPkgReleases({
versionScheme: VERSION_SCHEME_IVY,
versioning: ivyVersioning.id,
datasource: DATASOURCE_SBT,
lookupName: 'org.scalatest:scalaz',
depType: 'plugin',
Expand All @@ -120,7 +120,7 @@ describe('datasource/sbt', () => {
it('fetches releases from Maven', async () => {
expect(
await getPkgReleases({
versionScheme: VERSION_SCHEME_IVY,
versioning: ivyVersioning.id,
datasource: DATASOURCE_SBT,
lookupName: 'org.scalatest:scalatest',
registryUrls: [
Expand All @@ -138,7 +138,7 @@ describe('datasource/sbt', () => {
});
expect(
await getPkgReleases({
versionScheme: VERSION_SCHEME_IVY,
versioning: ivyVersioning.id,
datasource: DATASOURCE_SBT,
lookupName: 'org.scalatest:scalatest_2.12',
registryUrls: [DEFAULT_MAVEN_REPO, SBT_PLUGINS_REPO],
Expand All @@ -154,7 +154,7 @@ describe('datasource/sbt', () => {
it('fetches sbt plugins', async () => {
expect(
await getPkgReleases({
versionScheme: VERSION_SCHEME_IVY,
versioning: ivyVersioning.id,
datasource: DATASOURCE_SBT,
lookupName: 'org.foundweekends:sbt-bintray',
depType: 'plugin',
Expand All @@ -170,7 +170,7 @@ describe('datasource/sbt', () => {
});
expect(
await getPkgReleases({
versionScheme: VERSION_SCHEME_IVY,
versioning: ivyVersioning.id,
datasource: DATASOURCE_SBT,
lookupName: 'org.foundweekends:sbt-bintray_2.12',
depType: 'plugin',
Expand Down

0 comments on commit 485f669

Please sign in to comment.