diff --git a/renovate-config.json5 b/renovate-config.json5 index 0eff9ea7..0de48ecc 100644 --- a/renovate-config.json5 +++ b/renovate-config.json5 @@ -69,6 +69,12 @@ "matchCurrentValue": "/^(?:[a-z]+|\\d+)(?:-[a-z]+)?$/", "allowedVersions": "/^(?:[a-z]+|\\d+)(?:-[a-z]+)?$/" }, + // Read the Docs accepts Ubuntu LTS release names, not arbitrary Docker tags. + { + "matchDatasources": ["docker"], + "matchDepNames": ["readthedocs/ubuntu"], + "allowedVersions": "/^\\d{2}\\.04$/", + }, // Group GitHub maintained actions { "groupName": "Official GitHub Actions", @@ -228,6 +234,20 @@ "datasourceTemplate": "ruby-version", "depNameTemplate": "ruby-version", }, + { + "customType": "regex", + "description": "Update Read the Docs Ubuntu build images", + "managerFilePatterns": [ + "/(^|/)\\.readthedocs\\.ya?ml$/", + ], + "matchStrings": [ + "(?:^|\\r?\\n)[ \\t]+os:[ \\t]*[\"']?ubuntu-(?\\d{2}\\.04)[\"']?[ \\t]*(?:#[^\\r\\n]*)?(?:\\r?\\n|$)", + ], + "datasourceTemplate": "docker", + "packageNameTemplate": "ubuntu", + "depNameTemplate": "readthedocs/ubuntu", + "versioningTemplate": "loose", + }, // Annotated GitHub release, tag, or branch values paired with immutable commits. { "customType": "regex", diff --git a/tests/renovate-config.test.mjs b/tests/renovate-config.test.mjs index 090707a4..54dcf523 100644 --- a/tests/renovate-config.test.mjs +++ b/tests/renovate-config.test.mjs @@ -27,7 +27,10 @@ const condaEnvironmentManager = renovateConfig.customManagers.find( && manager.managerFilePatterns.some(pattern => pattern.includes('environment')), ); const readTheDocsToolManagers = renovateConfig.customManagers.filter( - manager => manager.description?.startsWith('Update Read the Docs'), + manager => manager.description?.endsWith('tool versions'), +); +const readTheDocsOsManager = renovateConfig.customManagers.find( + manager => manager.description === 'Update Read the Docs Ubuntu build images', ); function matchesManagerFilePattern(fileName, patterns) { @@ -88,6 +91,15 @@ function extractReadTheDocsToolDependencies(fileName, content) { }); } +function extractReadTheDocsOsDependencies(fileName, content) { + assert.ok(readTheDocsOsManager, 'Expected to find the Read the Docs OS manager'); + assert.ok( + matchesManagerFilePattern(fileName, readTheDocsOsManager.managerFilePatterns), + `Expected the Read the Docs OS manager to scan ${fileName}`, + ); + return extractRegexPackageFile(content, fileName, readTheDocsOsManager)?.deps ?? []; +} + test('groups highlight.js npm and GitHub dependencies', async () => { const githubDependency = extractPackageJson({ devDependencies: { @@ -293,6 +305,57 @@ build: assert.deepEqual(dependencies, []); }); +test('extracts and updates pinned Read the Docs Ubuntu build images', async () => { + const fileName = '.readthedocs.yaml'; + const content = ` +version: 2 +build: + os: ubuntu-24.04 # Keep an inline comment. + tools: + python: "3.14" +`; + const dependencies = extractReadTheDocsOsDependencies(fileName, content); + + assert.deepEqual( + dependencies.map(dependency => ({ + currentValue: dependency.currentValue, + datasource: dependency.datasource, + depName: dependency.depName, + packageName: dependency.packageName, + versioning: dependency.versioning, + })), + [{ + currentValue: '24.04', + datasource: 'docker', + depName: 'readthedocs/ubuntu', + packageName: 'ubuntu', + versioning: 'loose', + }], + ); + + const updatedContent = applyExtractedUpdate(content, dependencies[0], '26.04'); + assert.match(updatedContent, /os: ubuntu-26\.04 # Keep an inline comment\./); + assert.equal(extractReadTheDocsOsDependencies(fileName, updatedContent)[0].currentValue, '26.04'); + + const resolved = await applyPackageRules({ + ...dependencies[0], + packageRules: renovateConfig.packageRules, + }); + assert.equal(resolved.allowedVersions, '/^\\d{2}\\.04$/'); +}); + +test('ignores moving Read the Docs Ubuntu build image aliases', () => { + const dependencies = extractReadTheDocsOsDependencies( + '.readthedocs.yaml', + ` +build: + os: ubuntu-lts-latest +`, + ); + + assert.deepEqual(dependencies, []); +}); + function nextTestVersion(currentValue) { const match = /^(.*?)(\d+)$/.exec(currentValue); assert.ok(match, `Expected a version ending in a number: ${currentValue}`);