Skip to content

Commit 4b56523

Browse files
authored
feat(mise): add support for github backend (#40706)
* feat(mise): add support for github backend * test(mise): remove redundant github backend test * refactor(mise): flatten nested conditionals in github backend * refactor(mise): only set extractVersion for custom version_prefix * refactor(mise): use escapeRegExp and simplify extractVersion spread
1 parent 03020a2 commit 4b56523

File tree

7 files changed

+177
-2
lines changed

7 files changed

+177
-2
lines changed

lib/modules/manager/mise/backends.spec.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createCargoToolConfig,
44
createDotnetToolConfig,
55
createGemToolConfig,
6+
createGithubToolConfig,
67
createGoToolConfig,
78
createNpmToolConfig,
89
createPipxToolConfig,
@@ -104,6 +105,98 @@ describe('modules/manager/mise/backends', () => {
104105
});
105106
});
106107

108+
describe('createGithubToolConfig()', () => {
109+
it('should create a tooling config with empty options', () => {
110+
expect(
111+
createGithubToolConfig('BurntSushi/ripgrep', '14.1.1', {}),
112+
).toStrictEqual({
113+
packageName: 'BurntSushi/ripgrep',
114+
datasource: 'github-releases',
115+
currentValue: '14.1.1',
116+
});
117+
});
118+
119+
it('should not set extractVersion if the version has leading v', () => {
120+
expect(createGithubToolConfig('cli/cli', 'v2.64.0', {})).toStrictEqual({
121+
packageName: 'cli/cli',
122+
datasource: 'github-releases',
123+
currentValue: 'v2.64.0',
124+
});
125+
});
126+
127+
it('should set extractVersion with custom version_prefix', () => {
128+
expect(
129+
createGithubToolConfig('some/repo', '1.0.0', {
130+
version_prefix: 'release-',
131+
}),
132+
).toStrictEqual({
133+
packageName: 'some/repo',
134+
datasource: 'github-releases',
135+
currentValue: '1.0.0',
136+
extractVersion: '^release\\-(?<version>.+)',
137+
});
138+
});
139+
140+
it('should set extractVersion with version_prefix even if version has leading v', () => {
141+
expect(
142+
createGithubToolConfig('some/repo', 'v1.0.0', {
143+
version_prefix: 'version-',
144+
}),
145+
).toStrictEqual({
146+
packageName: 'some/repo',
147+
datasource: 'github-releases',
148+
currentValue: 'v1.0.0',
149+
extractVersion: '^version\\-(?<version>.+)',
150+
});
151+
});
152+
153+
it('should handle empty version_prefix with version not having v', () => {
154+
expect(
155+
createGithubToolConfig('some/repo', '1.0.0', { version_prefix: '' }),
156+
).toStrictEqual({
157+
packageName: 'some/repo',
158+
datasource: 'github-releases',
159+
currentValue: '1.0.0',
160+
});
161+
});
162+
163+
it('should handle empty version_prefix with version having v', () => {
164+
expect(
165+
createGithubToolConfig('some/repo', 'v1.0.0', { version_prefix: '' }),
166+
).toStrictEqual({
167+
packageName: 'some/repo',
168+
datasource: 'github-releases',
169+
currentValue: 'v1.0.0',
170+
});
171+
});
172+
173+
it('should escape special regex characters in version_prefix', () => {
174+
expect(
175+
createGithubToolConfig('some/repo', '1.0.0', {
176+
version_prefix: 'v1.0+',
177+
}),
178+
).toStrictEqual({
179+
packageName: 'some/repo',
180+
datasource: 'github-releases',
181+
currentValue: '1.0.0',
182+
extractVersion: '^v1\\.0\\+(?<version>.+)',
183+
});
184+
});
185+
186+
it('should escape brackets and parentheses in version_prefix', () => {
187+
expect(
188+
createGithubToolConfig('some/repo', '1.0.0', {
189+
version_prefix: 'prefix[test](v)',
190+
}),
191+
).toStrictEqual({
192+
packageName: 'some/repo',
193+
datasource: 'github-releases',
194+
currentValue: '1.0.0',
195+
extractVersion: '^prefix\\[test\\]\\(v\\)(?<version>.+)',
196+
});
197+
});
198+
});
199+
107200
describe('createGoToolConfig()', () => {
108201
it('should create a tooling config', () => {
109202
expect(createGoToolConfig('github.com/DarthSim/hivemind')).toStrictEqual({

lib/modules/manager/mise/backends.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { isString, isUndefined, isUrlString } from '@sindresorhus/is';
2-
import { regEx } from '../../../util/regex.ts';
1+
import {
2+
isNonEmptyString,
3+
isString,
4+
isUndefined,
5+
isUrlString,
6+
} from '@sindresorhus/is';
7+
import { escapeRegExp, regEx } from '../../../util/regex.ts';
38
import { CrateDatasource } from '../../datasource/crate/index.ts';
49
import { GitRefsDatasource } from '../../datasource/git-refs/index.ts';
510
import { GitTagsDatasource } from '../../datasource/git-tags/index.ts';
@@ -110,6 +115,30 @@ export function createGemToolConfig(name: string): BackendToolingConfig {
110115
};
111116
}
112117

118+
/**
119+
* Create a tooling config for github backend
120+
* @link https://mise.jdx.dev/dev-tools/backends/github.html
121+
*/
122+
export function createGithubToolConfig(
123+
name: string,
124+
version: string,
125+
toolOptions: MiseToolOptions,
126+
): BackendToolingConfig {
127+
let extractVersion: string | undefined = undefined;
128+
const prefix = toolOptions.version_prefix;
129+
130+
if (isNonEmptyString(prefix)) {
131+
extractVersion = `^${escapeRegExp(prefix)}(?<version>.+)`;
132+
}
133+
134+
return {
135+
packageName: name,
136+
datasource: GithubReleasesDatasource.id,
137+
currentValue: version,
138+
...(extractVersion && { extractVersion }),
139+
};
140+
}
141+
113142
/**
114143
* Create a tooling config for go backend
115144
* @link https://mise.jdx.dev/dev-tools/backends/go.html

lib/modules/manager/mise/extract.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,47 @@ describe('modules/manager/mise/extract', () => {
684684
});
685685
});
686686

687+
it('extracts github backend tools', () => {
688+
const content = codeBlock`
689+
[tools]
690+
"github:BurntSushi/ripgrep" = "14.1.1"
691+
"github:cli/cli" = "v2.64.0"
692+
"github:some/repo" = { version_prefix = "release-", version = "1.0.0" }
693+
"github:other/repo[version_prefix=v]" = "2.0.0"
694+
`;
695+
const result = extractPackageFile(content, miseFilename);
696+
expect(result).toMatchObject({
697+
deps: [
698+
{
699+
depName: 'github:BurntSushi/ripgrep',
700+
currentValue: '14.1.1',
701+
packageName: 'BurntSushi/ripgrep',
702+
datasource: 'github-releases',
703+
},
704+
{
705+
depName: 'github:cli/cli',
706+
currentValue: 'v2.64.0',
707+
packageName: 'cli/cli',
708+
datasource: 'github-releases',
709+
},
710+
{
711+
depName: 'github:some/repo',
712+
currentValue: '1.0.0',
713+
packageName: 'some/repo',
714+
datasource: 'github-releases',
715+
extractVersion: '^release\\-(?<version>.+)',
716+
},
717+
{
718+
depName: 'github:other/repo',
719+
currentValue: '2.0.0',
720+
packageName: 'other/repo',
721+
datasource: 'github-releases',
722+
extractVersion: '^v(?<version>.+)',
723+
},
724+
],
725+
});
726+
});
727+
687728
it('provides skipReason for lines with unsupported tooling', () => {
688729
const content = codeBlock`
689730
[tools]

lib/modules/manager/mise/extract.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
createCargoToolConfig,
1717
createDotnetToolConfig,
1818
createGemToolConfig,
19+
createGithubToolConfig,
1920
createGoToolConfig,
2021
createNpmToolConfig,
2122
createPipxToolConfig,
@@ -134,6 +135,8 @@ function getToolConfig(
134135
return createDotnetToolConfig(toolName);
135136
case 'gem':
136137
return createGemToolConfig(toolName);
138+
case 'github':
139+
return createGithubToolConfig(toolName, version, toolOptions);
137140
case 'go':
138141
return createGoToolConfig(toolName);
139142
case 'npm':

lib/modules/manager/mise/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const backendDatasources = {
4444
cargo: [CrateDatasource.id, GitTagsDatasource.id, GitRefsDatasource.id],
4545
dotnet: [NugetDatasource.id],
4646
gem: [RubygemsDatasource.id],
47+
github: [GithubReleasesDatasource.id],
4748
go: [GoDatasource.id],
4849
npm: [NpmDatasource.id],
4950
pipx: [PypiDatasource.id, GithubTagsDatasource.id, GitRefsDatasource.id],

lib/modules/manager/mise/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Renovate's `mise` manager supports the following [backends](https://mise.jdx.dev
6262
- [`asdf`](https://mise.jdx.dev/dev-tools/backends/asdf.html)
6363
- [`aqua`](https://mise.jdx.dev/dev-tools/backends/aqua.html)
6464
- [`cargo`](https://mise.jdx.dev/dev-tools/backends/cargo.html)
65+
- [`gem`](https://mise.jdx.dev/dev-tools/backends/gem.html)
66+
- [`github`](https://mise.jdx.dev/dev-tools/backends/github.html)
6567
- [`go`](https://mise.jdx.dev/dev-tools/backends/go.html)
6668
- [`npm`](https://mise.jdx.dev/dev-tools/backends/npm.html)
6769
- [`pipx`](https://mise.jdx.dev/dev-tools/backends/pipx.html)
@@ -100,6 +102,10 @@ Renovate's `mise` manager does not support the following tool syntax:
100102
The `tag_regex` option is used as `extractVersion`, but the regex engines are not the same between mise and Renovate.
101103
If the version is not updated or updated incorrectly, override `extractVersion` manually in the Renovate config.
102104

105+
- Some of `github` backend tools with [`version_prefix`](https://mise.jdx.dev/dev-tools/backends/github.html) option.
106+
The `version_prefix` option is converted to `extractVersion` by escaping special regex characters.
107+
If the version is not updated or updated incorrectly, override `extractVersion` manually in the Renovate config.
108+
103109
### Supported default registry tool short names
104110

105111
Renovate's `mise` manager can only version these tool short names:

lib/modules/manager/mise/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Toml } from '../../../util/schema-utils/index.ts';
44
const MiseToolOptions = z.object({
55
// ubi backend only
66
tag_regex: z.string().optional(),
7+
// github backend only
8+
version_prefix: z.string().optional(),
79
});
810
export type MiseToolOptions = z.infer<typeof MiseToolOptions>;
911

0 commit comments

Comments
 (0)