Skip to content

Commit

Permalink
feat!: categories (#16534)
Browse files Browse the repository at this point in the history
Closes #13953

Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

BREAKING CHANGE: languages are now called categories instead
  • Loading branch information
secustor authored and rarkins committed Jul 4, 2023
1 parent 3923e7e commit 19259a0
Show file tree
Hide file tree
Showing 101 changed files with 455 additions and 361 deletions.
8 changes: 2 additions & 6 deletions docs/development/adding-a-package-manager.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Adding a Package Manager

This document explains how to add a new language/package manager.
This document explains how to add a new package manager.

## Code structure

Expand All @@ -21,7 +21,7 @@ The manager's `index.ts` file supports the following values or functions:
| `extractPackageFile` | | yes |
| `extractAllPackageFiles` | yes | yes |
| `getRangeStrategy` | yes | |
| `language` | yes | |
| `categories` | yes | |
| `supportsLockFileMaintenance` | yes | |
| `updateArtifacts` | yes | yes |
| `updateDependency` | yes | |
Expand Down Expand Up @@ -80,10 +80,6 @@ The `npm` manager uses the `getRangeStrategy` function to pin `devDependencies`

If left undefined, then a default `getRangeStrategy` will be used that always returns "replace".

### `language` (optional)

This is used when more than one package manager shares settings from a common language.

### `supportsLockFileMaintenance` (optional)

Set to `true` if this package manager needs to update lock files in addition to package files.
Expand Down
68 changes: 11 additions & 57 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,24 +763,6 @@ Descriptions fields embedded within presets are also collated as part of the onb

Add to this object if you wish to define rules that apply only to PRs that update digests.

## docker

Add config here if you wish it to apply to Docker package managers Dockerfile and Docker Compose.
If instead you mean to apply settings to any package manager that updates using the Docker _datasource_, use a package rule instead, e.g.

```json
{
"packageRules": [
{
"matchDatasources": ["docker"],
"labels": ["docker-update"]
}
]
}
```

## dotnet

## draftPR

If you want the PRs created by Renovate to be considered as drafts rather than normal PRs, you could add this property to your `renovate.json`:
Expand Down Expand Up @@ -1132,16 +1114,6 @@ If you need to modify this path, for example in order to ignore directories, you
}
```

## golang

Configuration added here applies for all Go-related updates.
The only supported package manager for Go is the native Go Modules (the `gomod` manager).

For self-hosted users, `GOPROXY`, `GONOPROXY`, `GOPRIVATE` and `GOINSECURE` environment variables are supported ([reference](https://go.dev/ref/mod#module-proxy)).

Usage of `direct` will fallback to the Renovate-native release fetching mechanism.
Also we support the `off` keyword which will stop any fetching immediately.

## group

The default configuration for groups are essentially internal to Renovate and you normally shouldn't need to modify them.
Expand Down Expand Up @@ -1664,14 +1636,6 @@ Currently this applies to the `minimumReleaseAge` check only.
The `flexible` mode can result in "flapping" of Pull Requests, for example: a pending PR with version `1.0.3` is first released but then downgraded to `1.0.2` once it passes `minimumReleaseAge`.
We recommend that you use the `strict` mode, and enable the `dependencyDashboard` so that you can see suppressed PRs.

## java

Use this configuration option for shared config across all Java projects (Gradle and Maven).

## js

Use this configuration option for shared config across npm/Yarn/pnpm and meteor package managers.

## labels

By default, Renovate won't add any labels to PRs.
Expand Down Expand Up @@ -1810,12 +1774,6 @@ This works because Renovate will add a "renovate/stability-days" pending status

Add to this object if you wish to define rules that apply only to minor updates.

## node

Using this configuration option allows you to apply common configuration and policies across all Node.js version updates even if managed by different package managers (`npm`, `yarn`, etc.).

Check out our [Node.js documentation](https://docs.renovatebot.com/node) for a comprehensive explanation of how the `node` option can be used.

## npmToken

See [Private npm module support](./getting-started/private-packages.md) for details on how this is used.
Expand Down Expand Up @@ -2055,17 +2013,23 @@ See also `matchPackagePrefixes`.

The above will match all package names starting with `eslint` but exclude ones starting with `eslint-foo`.

### matchLanguages
### matchCategories

Use `matchCategories` to restrict rules to a particular language or group.
Matching is done using "any" logic, i.e. "match any of the following categories".
The categories can be found in the [manager documentation](./modules/manager/index.md).

Use this field to restrict rules to a particular language. e.g.
<!-- prettier-ignore -->
!!! note
Rules with `matchCategories` are only applied _after_ extraction of dependencies.
If you want to configure which managers are being extracted at all, use `enabledManagers` instead.

```json
{
"packageRules": [
{
"matchPackageNames": ["request"],
"matchLanguages": ["python"],
"enabled": false
"matchCategories": ["python"],
"addLabels": ["py"]
}
]
}
Expand Down Expand Up @@ -2528,8 +2492,6 @@ For example to replace the npm package `jade` with version `2.0.0` of the packag

Add to this object if you wish to define rules that apply only to patch updates.

## php

## pin

Add to this object if you wish to define rules that apply only to PRs that pin dependencies.
Expand Down Expand Up @@ -2864,10 +2826,6 @@ Set `pruneBranchAfterAutomerge` to `false` to keep the branch after automerging.
Configure to `false` to disable deleting orphan branches and autoclosing PRs.
Defaults to `true`.

## python

Currently the only Python package manager is `pip` - specifically for `requirements.txt` and `requirements.pip` files, or any file that matches the pattern `requirements-*.(txt|pip)` - so adding any config to this `python` object is essentially the same as adding it to the `pip_requirements` object instead.

## rangeStrategy

Behavior:
Expand Down Expand Up @@ -3314,10 +3272,6 @@ Renovate's "rollback" feature exists to propose a downgrade to the next-highest
Renovate does not create these rollback PRs by default, so this functionality needs to be opted-into.
We recommend you do this selectively with `packageRules` and not globally.

## ruby

## rust

## schedule

The `schedule` option allows you to define times of week or month for Renovate updates.
Expand Down
9 changes: 9 additions & 0 deletions docs/usage/golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ description: Go modules support in Renovate

Renovate supports upgrading dependencies in `go.mod` files and their accompanying `go.sum` checksums.

If you're self-hosting Renovate, you may use these environment variables:

- `GOPROXY`
- `GONOPROXY`
- `GOPRIVATE`
- `GOINSECURE`

To learn what these variables do, read the [Go Modules Reference about the`GOPROXY` protocol](https://go.dev/ref/mod#module-proxy).

## How It Works

1. Renovate searches in each repository for any `go.mod` files
Expand Down
12 changes: 4 additions & 8 deletions lib/config/__snapshots__/validation.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,10 @@ exports[`config/validation validateConfig(config) errors if invalid combinations
]
`;

exports[`config/validation validateConfig(config) errors if language or manager objects are nested 1`] = `
exports[`config/validation validateConfig(config) errors if manager objects are nested 1`] = `
[
{
"message": "The "docker" object can only be configured at the top level of a config but was found inside "major.minor"",
"topic": "Configuration Error",
},
{
"message": "The "gradle" object can only be configured at the top level of a config but was found inside "java"",
"message": "The "gradle" object can only be configured at the top level of a config but was found inside "maven"",
"topic": "Configuration Error",
},
]
Expand Down Expand Up @@ -233,11 +229,11 @@ exports[`config/validation validateConfig(config) returns nested errors 1`] = `
exports[`config/validation validateConfig(config) selectors outside packageRules array trigger errors 1`] = `
[
{
"message": "docker.minor.matchDepNames: matchDepNames should be inside a \`packageRule\` only",
"message": "ansible.minor.matchDepNames: matchDepNames should be inside a \`packageRule\` only",
"topic": "Configuration Error",
},
{
"message": "docker.minor.matchPackageNames: matchPackageNames should be inside a \`packageRule\` only",
"message": "ansible.minor.matchPackageNames: matchPackageNames should be inside a \`packageRule\` only",
"topic": "Configuration Error",
},
{
Expand Down
13 changes: 5 additions & 8 deletions lib/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logger } from '../logger';
import { get, getLanguageList, getManagerList } from '../modules/manager';
import { get, getManagerList } from '../modules/manager';
import * as options from './options';
import type {
AllConfig,
Expand All @@ -17,18 +17,15 @@ export function getManagerConfig(
): ManagerConfig {
let managerConfig: ManagerConfig = {
...config,
language: null,
manager,
};
const language = get(manager, 'language');
if (language) {
// TODO: fix types #7154
managerConfig = mergeChildConfig(managerConfig, config[language] as any);
managerConfig.language = language;
const categories = get(manager, 'categories');
if (categories) {
managerConfig.categories = categories;
}
// TODO: fix types #7154
managerConfig = mergeChildConfig(managerConfig, config[manager] as any);
for (const i of getLanguageList().concat(getManagerList())) {
for (const i of getManagerList()) {
delete managerConfig[i];
}
return managerConfig;
Expand Down
2 changes: 1 addition & 1 deletion lib/config/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ describe('config/migration', () => {
matchBaseBranches: ['master'],
matchDatasources: ['orb'],
matchDepTypes: ['peerDependencies'],
matchLanguages: ['python'],
matchCategories: ['python'],
matchManagers: ['dockerfile'],
matchPackageNames: ['foo'],
matchPackagePatterns: ['^bar'],
Expand Down
50 changes: 50 additions & 0 deletions lib/config/migrations/custom/package-rules-migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,54 @@ describe('config/migrations/custom/package-rules-migration', () => {
}
);
});

it('should migrate languages to categories', () => {
expect(PackageRulesMigration).toMigrate(
{
packageRules: [
{
matchLanguages: ['docker', 'js'],
addLabels: ['docker'],
},
{
languages: ['java'],
addLabels: ['java'],
},
],
},
{
packageRules: [
{
matchCategories: ['docker', 'js'],
addLabels: ['docker'],
},
{
matchCategories: ['java'],
addLabels: ['java'],
},
],
}
);
});

it('should migrate single match rule', () => {
expect(PackageRulesMigration).toMigrate(
{
packageRules: [
{
matchLanguages: ['python'],
addLabels: ['py'],
},
],
},
{
packageRules: [
{
matchCategories: ['python'],
addLabels: ['py'],
},
],
}
);
});
});
3 changes: 2 additions & 1 deletion lib/config/migrations/custom/package-rules-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export const renameMap = {
matchFiles: 'matchFileNames',
matchPaths: 'matchFileNames',
paths: 'matchFileNames',
languages: 'matchLanguages',
languages: 'matchCategories',
matchLanguages: 'matchCategories',
baseBranchList: 'matchBaseBranches',
managers: 'matchManagers',
datasources: 'matchDatasources',
Expand Down

0 comments on commit 19259a0

Please sign in to comment.