diff --git a/renovate/README.md b/renovate/README.md new file mode 100644 index 00000000..e781dd0b --- /dev/null +++ b/renovate/README.md @@ -0,0 +1,156 @@ +# Renovate + +## CPM package lock + +The shared CPM preset reads annotated `package-lock.cmake` files at the repository root or in a +subdirectory. Projects including build-deps, Sunshine, Moonlight-XboxOG, libvirtualhid, and lizardbyte-common +inherit the preset through `local>LizardByte/.github:renovate-config` in `renovate.json`. [CPM preset](cmake.json5). + +When adding a lock file to a project, commit it, load it with `CPMUsePackageLock` after including CPM, and call +`CPMGetPackage` with the first argument of `CPMDeclarePackage`. Set `NAME` to the name accepted by `find_package` +when the dependency supports local packages. If a project includes a shared lock file, update the pin in the +repository that owns it. Sunshine includes shared FFmpeg pins this way. +[Sunshine CMake setup](https://github.com/LizardByte/Sunshine/blob/master/CMakeLists.txt). + +### Annotation layout + +1. Start each dependency block with a comment naming the dependency. +2. Add `# renovate: datasource=... depName=...` directly below it. Use the upstream project for `depName`. +3. For version or tag pins, keep optional keys in the order `packageName`, `versioning`, `extractVersion`, `registryUrl`. Put them on the `# renovate:` line or on consecutive `# key=value` lines. +4. Follow the metadata with `set(NAME_VERSION ...)` or `set(NAME_TAG ...)`, and place `CPMDeclarePackage(...)` + below the tracked assignments. + +### GitHub tags + +For `github-tags`, Renovate derives `owner/repo` from a literal GitHub HTTPS URL on the `GIT_REPOSITORY` line. +The `.git` suffix is optional. This allows `depName` to identify the upstream project when CPM fetches from a +mirror. An explicit `packageName=owner/repo` takes precedence. When neither is present, including declarations +that use `GITHUB_REPOSITORY` or an archive `URL`, Renovate uses `depName`. +[SVT-AV1 in build-deps](https://github.com/LizardByte/build-deps/blob/master/package-lock.cmake). + +Store the full tag in `NAME_TAG`, or use `extractVersion` with a named `version` group to store a version +without the tag prefix. Reconstruct the tag in the declaration when storing only the version. +[SDL in libvirtualhid](https://github.com/LizardByte/libvirtualhid/blob/master/package-lock.cmake). + +```cmake +# SDL +# renovate: datasource=github-tags depName=libsdl-org/SDL versioning=semver +# extractVersion=^release-(?\d+\.\d+\.\d+)$ +set(SDL3_VERSION 3.4.12) +CPMDeclarePackage(SDL3 + NAME SDL3 + VERSION ${SDL3_VERSION} + GITHUB_REPOSITORY libsdl-org/SDL + GIT_TAG release-${SDL3_VERSION} +) +``` + +### Release archives with SHA256 checksums + +Use a datasource that can supply the archive digest, such as `github-release-attachments`. Put +`set(NAME_SHA256 ...)` immediately after the version or tag assignment and pass its value to `URL_HASH`. +[Boost in Sunshine](https://github.com/LizardByte/Sunshine/blob/master/package-lock.cmake). + +```cmake +# Boost +# renovate: datasource=github-release-attachments depName=boostorg/boost +# versioning=regex:^boost-(?\d+)\.(?\d+)\.(?\d+)$ +set(BOOST_TAG boost-1.92.0) +set(BOOST_SHA256 9bed76128d4e46755dbe818487788c6fceb6f72b378f4daa49b7e1e600d9088d) +string(REGEX REPLACE "^boost-" "" BOOST_VERSION "${BOOST_TAG}") +CPMDeclarePackage(Boost + NAME Boost + VERSION ${BOOST_VERSION} + URL https://github.com/boostorg/boost/releases/download/${BOOST_TAG}/${BOOST_TAG}-cmake.tar.xz + URL_HASH SHA256=${BOOST_SHA256} + DOWNLOAD_ONLY YES +) +``` + +### Git branch commits + +For `git-refs`, add `# ref=` after the metadata and set `NAME_COMMIT` to the full 40-character hash. +Renovate uses the full literal URL on the `GIT_REPOSITORY` line of the package declaration. To override it +or supply the URL for a declaration that uses a variable, put `packageName=` before `# ref=`. +The build stays pinned to the hash while Renovate follows the branch. +[Moonlight-XboxOG lock file](https://github.com/LizardByte/Moonlight-XboxOG/blob/master/package-lock.cmake), +[build-deps lock file](https://github.com/LizardByte/build-deps/blob/master/package-lock.cmake). + +```cmake +# x264 +# renovate: datasource=git-refs depName=videolan/x264 +# ref=stable +set(X264_COMMIT b35605ace3ddf7c1a5d67a2eb553f034aef41d55) +CPMDeclarePackage(x264 + NAME x264 + GIT_REPOSITORY https://github.com/LizardByte-infrastructure/x264.git + GIT_TAG ${X264_COMMIT} + DOWNLOAD_ONLY YES +) +``` + +## Flatpak modules + +The shared Flatpak preset reads annotated JSON sources under `packaging/linux/flatpak/modules/`, +including nested modules. Projects inherit it through `local>LizardByte/.github:renovate-config` in +`renovate.json`. [Flatpak preset](flatpak.json5). + +### Annotation layout + +1. Add an `x-renovate` object to each source Renovate should update. Place it immediately before + `url`. +2. List `datasource` and `depName` first, followed by `packageName` and `versioning` when needed. + Renovate uses `depName` for the lookup unless you supply `packageName`. +3. Keep the fields for the pin together and in order. For Git sources, use `url`, then `tag` or + `branch`, then `commit`. For GitHub release assets, use `url` followed by `sha256`. +4. Keep `x-checker-data` for Flatpak External Data Checker after the pin fields. + +For a source maintained through Flatpak External Data Checker, you can record that choice with +`"x-renovate": {"depName": "libtirpc", "enabled": false}`. + +### Git tags and branches + +Use `github-tags` for a GitHub tag pinned by commit. For a mirrored project, set `depName` to the +upstream name and `packageName` to the mirror's GitHub `owner/repo`. Flatpak checks out the Git +repository specified by `url`. + +```json +{ + "type": "git", + "x-renovate": { + "datasource": "github-tags", + "depName": "xorg/xserver", + "packageName": "LizardByte-infrastructure/xserver", + "versioning": "regex:^xorg-server-(?[0-9]+)[.](?[0-9]+)[.](?[0-9]+)$" + }, + "url": "https://github.com/LizardByte-infrastructure/xserver.git", + "tag": "xorg-server-21.1.13", + "commit": "be2767845d6ed3c6dbd25a151051294d0908a995" +} +``` + +To follow a branch, use `git-refs`, set `packageName` to the full Git URL, use `exact` versioning, +and specify `branch` followed by the pinned `commit`. + +### GitHub release assets + +Use `github-release-attachments` for an archive or file from a GitHub release. Keep the full tag +in the download URL so Renovate can update the URL and SHA-256 together. Set `versioning` for +nonstandard tags. + +```json +{ + "type": "archive", + "x-renovate": { + "datasource": "github-release-attachments", + "depName": "boostorg/boost", + "versioning": "regex:^boost-(?[0-9]+)[.](?[0-9]+)[.](?[0-9]+)(?[.][A-Za-z0-9.-]+)?$" + }, + "url": "https://github.com/boostorg/boost/releases/download/boost-1.92.0/boost-1.92.0-cmake.tar.xz", + "sha256": "9bed76128d4e46755dbe818487788c6fceb6f72b378f4daa49b7e1e600d9088d" +} +``` + +Use the same `depName` and compatible versioning across sources that track the same dependency. +Renovate can then group matching updates from different architecture assets and the CPM lock +into one pull request. diff --git a/renovate/cmake.json5 b/renovate/cmake.json5 index 4d16f061..afcaf88e 100644 --- a/renovate/cmake.json5 +++ b/renovate/cmake.json5 @@ -2,20 +2,31 @@ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "description": "Annotated CPM package lock dependencies", "customManagers": [ - // CPM Package Lock { + "description": "CPM package lock version and tag pins", "customType": "regex", "managerFilePatterns": ["/(^|\/)package-lock.cmake$/"], + "matchStringsStrategy": "recursive", "matchStrings": [ - // Version or tag assignments may be followed by a checksum. + // Read the GitHub repository from the declaration when available. + "# renovate:[^\\r\\n]*(?:\\s*\\r?\\n[ \\t]*#[^\\r\\n]*)*\\s+set\\([A-Za-z0-9_]+_(?:VERSION|TAG)\\s+[^)]+\\)(?:\\s+set\\([A-Za-z0-9_]+_SHA256\\s+[^)]+\\))?(?:\\s+(?:[a-z_][a-z0-9_]*\\([^\\r\\n]*\\)\\s+)*CPMDeclarePackage\\([^)]*?\\r?\\n[ \\t]*GIT_REPOSITORY[ \\t]+\"?https://github\\.com/(?[A-Za-z0-9-]+/[A-Za-z0-9_.-]+?)(?:\\.git)?/?\"?(?:[ \\t\\r\\n)]|$))?", + // Limit Renovate's replacement to the metadata, version, and optional checksum. "# renovate: datasource=(?[a-zA-Z0-9-._]+?) depName=(?[^\\s]+?)(?:(?:[ \\t]+|\\s*\\r?\\n#\\s*)packageName=(?[^\\s]+?))?(?:(?:[ \\t]+|\\s*\\r?\\n#\\s*)versioning=(?[^\\s]+?))?(?:(?:[ \\t]+|\\s*\\r?\\n#\\s*)extractVersion=(?[^\\s]+?))?(?:(?:[ \\t]+|\\s*\\r?\\n#\\s*)registryUrl=(?[^\\s]+?))?\\s+set\\([A-Za-z0-9_]+?_(?:VERSION|TAG)\\s+\\\"?(?[^\\\"\\s\\)]+)\\\"?\\s*\\)(?:\\s+set\\([A-Za-z0-9_]+?_SHA256\\s+\"?(?[a-fA-F0-9]{64})\"?\\s*\\))?", + ], + "packageNameTemplate": "{{#if packageName}}{{{packageName}}}{{else if (and (equals datasource 'github-tags') githubRepository)}}{{{githubRepository}}}{{else}}{{{depName}}}{{/if}}", + "versioningTemplate": "{{#if versioning}}{{{versioning}}}{{/if}}" + }, + { + "description": "CPM package lock commit pins", + "customType": "regex", + "managerFilePatterns": ["/(^|\/)package-lock.cmake$/"], + "matchStrings": [ // Commit pins can supply an explicit URL or use the package declaration. "# renovate: datasource=(?[a-zA-Z0-9-._]+) depName=(?\\S+)(?:(?:[ \\t]+|\\s*\\r?\\n#\\s*)packageName=(?\\S+))?\\s+# ref=(?\\S+)\\s+set\\([A-Za-z0-9_]+_COMMIT\\s+\"?(?[a-fA-F0-9]{40})\"?\\s*\\)(?:\\s+(?:[a-z_][a-z0-9_]*\\([^\\r\\n]*\\)\\s+)*CPMDeclarePackage\\([^)]*?\\r?\\n[ \\t]*GIT_REPOSITORY[ \\t]+\"?(?[^\"$\\s()]+)\"?)?", ], - // Skip commit pins without a repository and fall back to the name for tagged dependencies. - "depNameTemplate": "{{#if depName}}{{{depName}}}{{else if packageName}}{{{commitDepName}}}{{else if gitRepository}}{{{commitDepName}}}{{/if}}", - "packageNameTemplate": "{{#if packageName}}{{{packageName}}}{{else if gitRepository}}{{{gitRepository}}}{{else}}{{{depName}}}{{/if}}", - "versioningTemplate": "{{#if versioning}}{{{versioning}}}{{/if}}" + // Skip commit pins without a repository. + "depNameTemplate": "{{#if (or packageName gitRepository)}}{{{commitDepName}}}{{/if}}", + "packageNameTemplate": "{{#if packageName}}{{{packageName}}}{{else}}{{{gitRepository}}}{{/if}}" }, ], } diff --git a/renovate/default.json5 b/renovate/default.json5 index 56514af8..f41a3c27 100644 --- a/renovate/default.json5 +++ b/renovate/default.json5 @@ -19,6 +19,7 @@ "github>LizardByte/.github//renovate/python.json5", "github>LizardByte/.github//renovate/readthedocs.json5", "github>LizardByte/.github//renovate/cmake.json5", + "github>LizardByte/.github//renovate/flatpak.json5", "github>LizardByte/.github//renovate/jekyll.json5", ], } diff --git a/renovate/flatpak.json5 b/renovate/flatpak.json5 new file mode 100644 index 00000000..506b98b2 --- /dev/null +++ b/renovate/flatpak.json5 @@ -0,0 +1,30 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "description": "Flatpak sources annotated with x-renovate", + "customManagers": [ + { + "customType": "regex", + "managerFilePatterns": ["packaging/linux/flatpak/modules/**/*.json"], + "matchStringsStrategy": "recursive", + "matchStrings": [ + // Put x-renovate immediately before the URL. List datasource, depName, and the optional packageName and versioning in that order. + '"x-renovate"\\s*:\\s*\\{\\s*"datasource"\\s*:\\s*"(?[a-z0-9_.-]+)"\\s*,\\s*"depName"\\s*:\\s*"(?[^"]+)"(?:\\s*,\\s*"packageName"\\s*:\\s*"(?[^"]+)")?(?:\\s*,\\s*"versioning"\\s*:\\s*"(?[^"]+)")?\\s*\\}\\s*,\\s*"url"\\s*:\\s*"[^"]+"(?:\\s*,\\s*"(?:tag|branch|commit|sha256)"\\s*:\\s*"[^"]+")+', + // Replace the pinned Git ref and commit or the release tag in the download URL and its SHA-256. + '"url"\\s*:\\s*"(?:(?:https://github[.]com/[^/"]+/[^/"]+/releases/download/(?[^/"]+)/[^"]+)"\\s*,\\s*"sha256"|[^"]+"\\s*,\\s*"(?:tag|branch)"\\s*:\\s*"(?[^"]+)"\\s*,\\s*"commit")\\s*:\\s*"(?[a-fA-F0-9]{40}(?:[a-fA-F0-9]{24})?)"', + ], + "packageNameTemplate": "{{#if packageName}}{{{packageName}}}{{else}}{{{depName}}}{{/if}}", + "versioningTemplate": "{{#if versioning}}{{{replace '(\\x5c){2}' '$1' versioning}}}{{/if}}", + "currentValueTemplate": "{{#if gitRef}}{{{gitRef}}}{{else}}{{{archiveTag}}}{{/if}}", + }, + ], + "packageRules": [ + { + "matchManagers": ["custom.regex"], + "matchFileNames": ["packaging/linux/flatpak/modules/**/*.json"], + "matchDatasources": ["github-release-attachments"], + // The datasource can return the old checksum if it cannot identify the pinned asset. + "matchJsonata": ["newValue != currentValue and newDigest and newDigest = currentDigest"], + "enabled": false, + }, + ], +} diff --git a/tests/renovate-config.test.mjs b/tests/renovate-config.test.mjs index 9146e4e1..82c22778 100644 --- a/tests/renovate-config.test.mjs +++ b/tests/renovate-config.test.mjs @@ -1,5 +1,7 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; import test, {mock} from 'node:test'; import JSON5 from 'json5'; @@ -10,16 +12,24 @@ import {defaultConfig as ansibleDefaults, extractPackageFile as extractAnsiblePa import {defaultConfig as ansibleGalaxyDefaults, extractPackageFile as extractAnsibleGalaxyPackageFile} from 'renovate/dist/modules/manager/ansible-galaxy/index.js'; import {extractPackageFile as extractCdnUrlPackageFile} from 'renovate/dist/modules/manager/cdnurl/index.js'; import {massageCustomDatasourceConfig} from 'renovate/dist/modules/datasource/custom/utils.js'; +import {GithubReleaseAttachmentsDatasource} from 'renovate/dist/modules/datasource/github-release-attachments/index.js'; +import {GithubReleasesDatasource} from 'renovate/dist/modules/datasource/github-releases/index.js'; import {extractPackageFile as extractRegexPackageFile} from 'renovate/dist/modules/manager/custom/regex/index.js'; import {extractPackageJson} from 'renovate/dist/modules/manager/npm/extract/common/package-file.js'; import {getExpression} from 'renovate/dist/util/jsonata.js'; import {compile} from 'renovate/dist/util/template/index.js'; import {applyPackageRules} from 'renovate/dist/util/package-rules/index.js'; +import {matchRegexOrGlobList} from 'renovate/dist/util/string-match.js'; import {filterVersions} from 'renovate/dist/workers/repository/process/lookup/filter.js'; import {GlobalConfig} from 'renovate/dist/config/global.js'; +import {getConfig} from 'renovate/dist/config/defaults.js'; +import {mergeChildConfig} from 'renovate/dist/config/utils.js'; import {resolveConfigPresets} from 'renovate/dist/config/presets/index.js'; import {init as initPresetCache} from 'renovate/dist/util/cache/memory/index.js'; import {GithubHttp} from 'renovate/dist/util/http/github.js'; +import {lookupUpdates} from 'renovate/dist/workers/repository/process/lookup/index.js'; +import {doAutoReplace} from 'renovate/dist/workers/repository/update/branch/auto-replace.js'; +import {branchifyUpgrades} from 'renovate/dist/workers/repository/updates/branchify.js'; const rootConfig = JSON.parse(fs.readFileSync('renovate-config.json', 'utf8')); const {config: renovateConfig} = await resolveLocalPresets(rootConfig); @@ -69,13 +79,7 @@ const readTheDocsOsManager = renovateConfig.customManagers.find( ); function matchesManagerFilePattern(fileName, patterns) { - return patterns.some(pattern => { - const closingSlash = pattern.lastIndexOf('/'); - assert.equal(pattern[0], '/', `Expected a regex managerFilePattern: ${pattern}`); - assert.ok(closingSlash > 0, `Expected a closing slash in managerFilePattern: ${pattern}`); - - return new RegExp(pattern.slice(1, closingSlash), pattern.slice(closingSlash + 1)).test(fileName); - }); + return matchRegexOrGlobList(fileName, patterns); } function extractNpmDependencies(manager, fileName, content) { @@ -230,13 +234,20 @@ test('extracts a GitHub branch and jsDelivr commit from a composite action', () ); }); -test('extracts an annotated branch and commit from a CPM package lock', () => { - const fileName = 'cmake/package-lock.cmake'; - const manager = renovateConfig.customManagers.find( - item => item.managerFilePatterns.some(pattern => pattern.includes('package-lock.cmake')), +function extractCpmDependencies(fileName, content) { + const managers = renovateConfig.customManagers.filter( + manager => Array.isArray(manager.managerFilePatterns) + && manager.managerFilePatterns.some(pattern => pattern.includes('package-lock.cmake')), ); - assert.ok(manager, 'Expected to find the CPM package lock custom manager'); - assert.ok(matchesManagerFilePattern(fileName, manager.managerFilePatterns)); + assert.equal(managers.length, 2, 'Expected one CPM manager for version pins and one for commit pins'); + return managers.flatMap(manager => { + assert.ok(matchesManagerFilePattern(fileName, manager.managerFilePatterns)); + return extractRegexPackageFile(content, fileName, manager)?.deps ?? []; + }); +} + +test('extracts annotated versions and commits from a CPM package lock', () => { + const fileName = 'cmake/package-lock.cmake'; const commit = '63a9e6a216796aeba2535a3bac8e79ba5d95166d'; const checksum = 'a'.repeat(64); @@ -250,13 +261,32 @@ test('extracts an annotated branch and commit from a CPM package lock', () => { '', '# renovate: datasource=github-tags depName=example/library versioning=semver', 'set(EXAMPLE_LIBRARY_VERSION 1.2.3)', + 'file(GLOB EXAMPLE_LIBRARY_PATCHES "${PATCH_DIRECTORY}/library/*.patch")', + 'CPMDeclarePackage(library', + ' NAME library', + ' GIT_REPOSITORY "https://github.com/example-mirror/library-1.2.3.git"', + ' GIT_TAG ${EXAMPLE_LIBRARY_VERSION}', + ')', + '', + '# renovate: datasource=github-tags depName=example/override', + '# packageName=example/explicit', + 'set(EXAMPLE_OVERRIDE_TAG v2.0.0)', + 'CPMDeclarePackage(override', + ' GIT_REPOSITORY https://github.com/example-mirror/override', + ')', '', '# renovate: datasource=github-releases depName=example/download versioning=semver', 'set(EXAMPLE_DOWNLOAD_TAG 2.3.4)', `set(EXAMPLE_DOWNLOAD_SHA256 "${checksum}")`, + 'CPMDeclarePackage(download', + ' URL https://example.com/archive.tar.gz', + ')', + 'CPMDeclarePackage(other', + ' GIT_REPOSITORY https://github.com/example/unrelated.git', + ')', ].join('\r\n'); - const dependencies = extractRegexPackageFile(content, fileName, manager)?.deps ?? []; - assert.equal(dependencies.length, 3); + const dependencies = extractCpmDependencies(fileName, content); + assert.equal(dependencies.length, 4); const port = dependencies.find(dependency => dependency.depName === 'example/port'); assert.ok(port); @@ -266,19 +296,22 @@ test('extracts an annotated branch and commit from a CPM package lock', () => { assert.equal(port.currentDigest, commit); const library = dependencies.find(dependency => dependency.depName === 'example/library'); assert.ok(library); + assert.equal(library.packageName, 'example-mirror/library-1.2.3'); assert.equal(library.currentValue, '1.2.3'); + assert.doesNotMatch(library.replaceString, /CPMDeclarePackage|GIT_REPOSITORY/); + const override = dependencies.find(dependency => dependency.depName === 'example/override'); + assert.ok(override); + assert.equal(override.packageName, 'example/explicit'); const download = dependencies.find(dependency => dependency.depName === 'example/download'); assert.ok(download); assert.equal(download.datasource, 'github-releases'); + assert.equal(download.packageName, 'example/download'); assert.equal(download.currentValue, '2.3.4'); assert.equal(download.currentDigest, checksum); }); test('reads a CPM git-ref repository URL from its package declaration', () => { const fileName = 'package-lock.cmake'; - const manager = renovateConfig.customManagers.find( - item => item.managerFilePatterns.some(pattern => pattern.includes('package-lock.cmake')), - ); const commit = '63a9e6a216796aeba2535a3bac8e79ba5d95166d'; const content = [ '# renovate: datasource=git-refs depName=example/port', @@ -301,7 +334,7 @@ test('reads a CPM git-ref repository URL from its package declaration', () => { ' GIT_REPOSITORY https://github.com/example/unrelated.git', ')', ].join('\r\n'); - const dependencies = extractRegexPackageFile(content, fileName, manager)?.deps ?? []; + const dependencies = extractCpmDependencies(fileName, content); assert.deepEqual(dependencies.map(dependency => ({ currentDigest: dependency.currentDigest, currentValue: dependency.currentValue, @@ -317,6 +350,141 @@ test('reads a CPM git-ref repository URL from its package declaration', () => { }]); }); +test('extracts annotated Flatpak Git pins and ignores sources without metadata', () => { + const fileName = 'packaging/linux/flatpak/modules/xvfb/xvfb.json'; + const manager = renovateConfig.customManagers.find( + item => matchesManagerFilePattern(fileName, item.managerFilePatterns), + ); + const digest = 'a'.repeat(40); + const content = JSON.stringify({ + sources: [ + { + type: 'git', + 'x-renovate': { + datasource: 'github-tags', + depName: 'miniupnp/miniupnp', + versioning: 'regex:^miniupnpc_(?\\d+)_(?\\d+)_(?\\d+)$', + }, + url: 'https://github.com/miniupnp/miniupnp.git', + tag: 'miniupnpc_2_3_4', + commit: digest, + }, + {type: 'git', url: 'https://github.com/avahi/avahi', tag: 'v0.8', commit: digest}, + ], + modules: [{sources: [ + { + type: 'git', + 'x-renovate': { + datasource: 'git-refs', + depName: 'example/port', + packageName: 'https://github.com/example/port.git', + versioning: 'exact', + }, + url: 'https://github.com/example/port.git', + branch: 'main', + commit: digest, + }, + {type: 'file', path: 'xvfb-run'}, + ]}], + }, null, 2); + + const deps = extractRegexPackageFile(content, fileName, manager).deps; + const miniupnp = deps.find(dep => dep.depName === 'miniupnp/miniupnp'); + assert.equal(miniupnp.datasource, 'github-tags'); + assert.equal(miniupnp.packageName, 'miniupnp/miniupnp'); + assert.equal(miniupnp.currentDigest, digest); + const versioning = getVersioning(miniupnp.versioning); + assert.ok(versioning.isCompatible('miniupnpc_2_3_5', miniupnp.currentValue)); + assert.ok(!versioning.isCompatible('miniupnpd_2_3_5', miniupnp.currentValue)); + assert.ok(!versioning.isVersion('miniupnpc_2_3_5_test')); + + const port = deps.find(dep => dep.depName === 'example/port'); + assert.deepEqual(summarizeDependency(port), expectedDependency( + 'main', 'git-refs', 'example/port', 'https://github.com/example/port.git', 'exact', + )); + assert.equal(deps.length, 2); +}); + +test('updates both FFmpeg assets and the matching CPM release in one branch', async t => { + const packageFile = 'packaging/linux/flatpak/modules/ffmpeg.json'; + const lockFile = 'package-lock.cmake'; + const oldVersion = 'v2026.1004.34232'; + const newVersion = 'v2026.1017.131201'; + const depName = 'LizardByte/build-deps'; + const names = ['Linux-x86_64-ffmpeg.tar.gz', 'Linux-aarch64-ffmpeg.tar.gz']; + const oldDigests = ['a'.repeat(64), 'b'.repeat(64)]; + const newDigests = ['c'.repeat(64), 'd'.repeat(64)]; + t.mock.method(GithubReleasesDatasource.prototype, 'getReleases', async ({packageName}) => { + assert.equal(packageName, depName); + return { + sourceUrl: `https://github.com/${depName}`, + releases: [{version: oldVersion}, {version: newVersion}], + }; + }); + t.mock.method(GithubReleaseAttachmentsDatasource.prototype, 'getDigest', async (dependency, version) => { + assert.equal(dependency.packageName, depName); + return version === oldVersion ? dependency.currentDigest : newDigests[oldDigests.indexOf(dependency.currentDigest)]; + }); + + const manifest = {sources: names.map((name, i) => ({ + type: 'file', + 'x-renovate': {datasource: 'github-release-attachments', depName, versioning: 'semver'}, + url: `https://github.com/${depName}/releases/download/${oldVersion}/${name}`, + sha256: oldDigests[i], + 'dest-filename': 'ffmpeg.tar.gz', + }))}; + const content = JSON.stringify(manifest, null, 2); + const lockContent = [ + `# renovate: datasource=github-release-attachments depName=${depName} versioning=semver`, + `set(FFMPEG_TAG ${oldVersion})`, + `set(FFMPEG_SHA256 ${oldDigests[0]})`, + ].join('\n'); + const config = {...mergeChildConfig(getConfig(), renovateConfig), errors: [], warnings: []}; + const packageFiles = []; + for (const [file, fileContent] of [[packageFile, content], [lockFile, lockContent]]) { + const extracted = config.customManagers + .filter(item => matchesManagerFilePattern(file, item.managerFilePatterns)) + .map(item => extractRegexPackageFile(fileContent, file, item)) + .find(Boolean); + assert.ok(extracted, `Expected to extract dependencies from ${file}`); + for (const dependency of extracted.deps) { + const result = await lookupUpdates({...config, ...extracted, ...dependency, manager: 'regex', packageFile: file}); + const {val, err} = result.unwrap(); + assert.ifError(err); + Object.assign(dependency, val); + const expectedDigest = newDigests[oldDigests.indexOf(dependency.currentDigest)]; + assert.deepEqual(dependency.updates.map(({newValue, newDigest}) => [newValue, newDigest]), [ + [newVersion, expectedDigest], + ]); + } + packageFiles.push({...extracted, packageFile: file}); + } + + const {branches} = await branchifyUpgrades(config, {regex: packageFiles}); + assert.equal(branches.length, 1); + const [{upgrades}] = branches; + assert.equal(upgrades.length, 3); + const localDir = fs.mkdtempSync(path.join(os.tmpdir(), 'renovate-flatpak-')); + const originalGlobalConfig = GlobalConfig.get(); + GlobalConfig.set({...originalGlobalConfig, localDir}); + t.after(() => { + GlobalConfig.set(originalGlobalConfig); + fs.rmSync(localDir, {recursive: true}); + }); + + let newContent = content; + for (const upgrade of upgrades.filter(item => item.packageFile === packageFile)) { + newContent = await doAutoReplace(upgrade, newContent, false, newContent === content); + } + assert.deepEqual(JSON.parse(newContent).sources, manifest.sources.map((source, i) => ({ + ...source, + url: source.url.replace(oldVersion, newVersion), + sha256: newDigests[i], + }))); + const newLock = await doAutoReplace(upgrades.find(item => item.packageFile === lockFile), lockContent, false); + assert.equal(newLock, lockContent.replace(oldVersion, newVersion).replace(oldDigests[0], newDigests[0])); +}); + test('extracts and updates pinned conda-forge dependencies from environment files', () => { const fileName = 'environment.yml'; const content = `