Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 12 additions & 78 deletions renovate/readthedocs.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,90 +17,24 @@
},
},
"customManagers": [
// Numeric runtime versions selected by Read the Docs.
{
"customType": "regex",
"description": "Update Read the Docs Python tool versions",
"description": "Update Read the Docs runtimes and Ubuntu build images",
"managerFilePatterns": [
"/(^|/)\\.readthedocs\\.ya?ml$/",
],
"matchStrings": [
"(?:^|\\r?\\n)[ \\t]+python:[ \\t]*[\"']?(?<currentValue>\\d+\\.\\d+)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
],
"datasourceTemplate": "custom.readthedocs-tools",
"depNameTemplate": "python",
"packageNameTemplate": "python",
"versioningTemplate": "semver-coerced",
},
{
"customType": "regex",
"description": "Update Read the Docs Node.js tool versions",
"managerFilePatterns": [
"/(^|/)\\.readthedocs\\.ya?ml$/",
],
"matchStrings": [
"(?:^|\\r?\\n)[ \\t]+nodejs:[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
],
"datasourceTemplate": "custom.readthedocs-tools",
"depNameTemplate": "node",
"packageNameTemplate": "nodejs",
"versioningTemplate": "semver-coerced",
},
{
"customType": "regex",
"description": "Update Read the Docs Rust tool versions",
"managerFilePatterns": [
"/(^|/)\\.readthedocs\\.ya?ml$/",
],
"matchStrings": [
"(?:^|\\r?\\n)[ \\t]+rust:[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
],
"datasourceTemplate": "custom.readthedocs-tools",
"depNameTemplate": "rust",
"packageNameTemplate": "rust",
"versioningTemplate": "semver-coerced",
},
{
"customType": "regex",
"description": "Update Read the Docs Go tool versions",
"managerFilePatterns": [
"/(^|/)\\.readthedocs\\.ya?ml$/",
],
"matchStrings": [
"(?:^|\\r?\\n)[ \\t]+golang:[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
],
"datasourceTemplate": "custom.readthedocs-tools",
"depNameTemplate": "go",
"packageNameTemplate": "golang",
"versioningTemplate": "semver-coerced",
},
{
"customType": "regex",
"description": "Update Read the Docs Ruby tool versions",
"managerFilePatterns": [
"/(^|/)\\.readthedocs\\.ya?ml$/",
],
"matchStrings": [
"(?:^|\\r?\\n)[ \\t]+ruby:[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
],
"datasourceTemplate": "custom.readthedocs-tools",
"depNameTemplate": "ruby-version",
"packageNameTemplate": "ruby",
"versioningTemplate": "semver-coerced",
},
{
"customType": "regex",
"description": "Update Read the Docs Ubuntu build images",
"managerFilePatterns": [
"/(^|/)\\.readthedocs\\.ya?ml$/",
],
"matchStrings": [
"(?:^|\\r?\\n)[ \\t]+os:[ \\t]*[\"']?ubuntu-(?<currentValue>\\d{2}\\.04)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
],
"datasourceTemplate": "custom.readthedocs-os",
"packageNameTemplate": "os",
"depNameTemplate": "readthedocs/ubuntu",
"versioningTemplate": "loose",
// Each key has its own pattern so adjacent pins can match independently.
"(?:^|\\r?\\n)[ \\t]+(?<packageName>python):[ \\t]*[\"']?(?<currentValue>\\d+\\.\\d+)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
"(?:^|\\r?\\n)[ \\t]+(?<packageName>nodejs):[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
"(?:^|\\r?\\n)[ \\t]+(?<packageName>rust):[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
"(?:^|\\r?\\n)[ \\t]+(?<packageName>golang):[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
"(?:^|\\r?\\n)[ \\t]+(?<packageName>ruby):[ \\t]*[\"']?(?<currentValue>\\d+(?:\\.\\d+)*)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
"(?:^|\\r?\\n)[ \\t]+(?<packageName>os):[ \\t]*[\"']?ubuntu-(?<currentValue>\\d{2}\\.04)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)",
],
"datasourceTemplate": "{{#if (equals packageName 'os')}}custom.readthedocs-os{{else}}custom.readthedocs-tools{{/if}}",
"depNameTemplate": "{{#if (equals packageName 'os')}}readthedocs/ubuntu{{else if (equals packageName 'nodejs')}}node{{else if (equals packageName 'golang')}}go{{else if (equals packageName 'ruby')}}ruby-version{{else}}{{{packageName}}}{{/if}}",
"versioningTemplate": "{{#if (equals packageName 'os')}}loose{{else}}semver-coerced{{/if}}",
},
],
}
61 changes: 26 additions & 35 deletions tests/renovate-config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ const condaEnvironmentManager = renovateConfig.customManagers.find(
manager => manager.datasourceTemplate === 'conda'
&& manager.managerFilePatterns.some(pattern => pattern.includes('environment')),
);
const readTheDocsToolManagers = renovateConfig.customManagers.filter(
manager => manager.datasourceTemplate === 'custom.readthedocs-tools',
);
const readTheDocsOsManager = renovateConfig.customManagers.find(
manager => manager.description?.includes('Update Read the Docs Ubuntu build images'),
const readTheDocsManagers = renovateConfig.customManagers.filter(
manager => matchesManagerFilePattern('.readthedocs.yaml', manager.managerFilePatterns),
);

function matchesManagerFilePattern(fileName, patterns) {
Expand Down Expand Up @@ -120,24 +117,14 @@ function extractCondaDependencies(fileName, content) {
return extractRegexPackageFile(content, fileName, condaEnvironmentManager)?.deps ?? [];
}

function extractReadTheDocsToolDependencies(fileName, content) {
assert.equal(readTheDocsToolManagers.length, 5, 'Expected one manager per Read the Docs runtime');
return readTheDocsToolManagers.flatMap(manager => {
assert.ok(
matchesManagerFilePattern(fileName, manager.managerFilePatterns),
`Expected the Read the Docs tool manager to scan ${fileName}`,
);
return extractRegexPackageFile(content, fileName, manager)?.deps ?? [];
});
}

function extractReadTheDocsOsDependencies(fileName, content) {
assert.ok(readTheDocsOsManager, 'Expected to find the Read the Docs OS manager');
function extractReadTheDocsDependencies(fileName, content) {
assert.equal(readTheDocsManagers.length, 1, 'Expected one manager for all Read the Docs pins');
const [manager] = readTheDocsManagers;
assert.ok(
matchesManagerFilePattern(fileName, readTheDocsOsManager.managerFilePatterns),
`Expected the Read the Docs OS manager to scan ${fileName}`,
matchesManagerFilePattern(fileName, manager.managerFilePatterns),
`Expected the Read the Docs manager to scan ${fileName}`,
);
return extractRegexPackageFile(content, fileName, readTheDocsOsManager)?.deps ?? [];
return extractRegexPackageFile(content, fileName, manager)?.deps ?? [];
}

function summarizeDependency(dependency) {
Expand Down Expand Up @@ -699,7 +686,7 @@ test('allows only stable Python releases in Conda environments', async () => {
}
});

test('extracts numeric Read the Docs runtime versions', () => {
test('extracts Read the Docs runtime and build image pins with one manager', () => {
const fileName = '.readthedocs.yaml';
const content = `
version: 2
Expand All @@ -712,7 +699,7 @@ build:
golang: "1.25" # Keep an inline comment.
ruby: "3.4"
`;
const dependencies = extractReadTheDocsToolDependencies(fileName, content);
const dependencies = extractReadTheDocsDependencies(fileName, content);

assert.deepEqual(
dependencies.map(summarizeDependency),
Expand All @@ -722,13 +709,14 @@ build:
expectedDependency('1.91', 'custom.readthedocs-tools', 'rust', 'rust', 'semver-coerced'),
expectedDependency('1.25', 'custom.readthedocs-tools', 'go', 'golang', 'semver-coerced'),
expectedDependency('3.4', 'custom.readthedocs-tools', 'ruby-version', 'ruby', 'semver-coerced'),
expectedDependency('24.04', 'custom.readthedocs-os', 'readthedocs/ubuntu', 'os', 'loose'),
],
);

for (const dependency of dependencies) {
for (const dependency of dependencies.filter(item => item.datasource === 'custom.readthedocs-tools')) {
const newValue = nextTestVersion(dependency.currentValue);
const updatedContent = applyExtractedUpdate(content, dependency, newValue);
const updatedDependencies = extractReadTheDocsToolDependencies(fileName, updatedContent);
const updatedDependencies = extractReadTheDocsDependencies(fileName, updatedContent);
assert.ok(
updatedDependencies.some(updated => (
updated.depName === dependency.depName && updated.currentValue === newValue
Expand All @@ -739,7 +727,7 @@ build:
});

test('ignores moving Read the Docs runtime aliases', () => {
const dependencies = extractReadTheDocsToolDependencies(
const dependencies = extractReadTheDocsDependencies(
'.readthedocs.yaml',
`
build:
Expand Down Expand Up @@ -798,17 +786,18 @@ build:
tools:
python: "3.14"
`;
const dependencies = extractReadTheDocsOsDependencies(fileName, content);
const dependency = extractReadTheDocsDependencies(fileName, content)
.find(item => item.depName === 'readthedocs/ubuntu');

assert.deepEqual(
dependencies.map(summarizeDependency),
[expectedDependency(
summarizeDependency(dependency),
expectedDependency(
'24.04',
'custom.readthedocs-os',
'readthedocs/ubuntu',
'os',
'loose',
)],
),
);

const transformed = await transformReadTheDocsSchema('readthedocs-os', 'os', {
Expand All @@ -823,21 +812,23 @@ build:
},
});
const [update] = filterVersions(
dependencies[0],
dependencies[0].currentValue,
dependency,
dependency.currentValue,
undefined,
transformed.releases,
looseVersioning,
);

assert.equal(update.version, '26.04');
const updatedContent = applyExtractedUpdate(content, dependencies[0], update.version);
const updatedContent = applyExtractedUpdate(content, dependency, update.version);
assert.match(updatedContent, /os: ubuntu-26\.04 # Keep an inline comment\./);
assert.equal(extractReadTheDocsOsDependencies(fileName, updatedContent)[0].currentValue, '26.04');
const updatedDependency = extractReadTheDocsDependencies(fileName, updatedContent)
.find(item => item.depName === dependency.depName);
assert.equal(updatedDependency.currentValue, '26.04');
});

test('ignores moving Read the Docs Ubuntu build image aliases', () => {
const dependencies = extractReadTheDocsOsDependencies(
const dependencies = extractReadTheDocsDependencies(
'.readthedocs.yaml',
`
build:
Expand Down
Loading