From 73b842fe3ae364ca148c08404cdaac4433716c5f Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Thu, 2 Jan 2025 19:06:11 +0100 Subject: [PATCH] feat(manager/github-actions): support registry aliases (#33377) --- docs/usage/configuration-options.md | 1 + lib/modules/manager/github-actions/extract.ts | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index fa7e36e0107e0d..e76873af8a49d0 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -3707,6 +3707,7 @@ This feature works with the following managers: - [`dockerfile`](modules/manager/dockerfile/index.md) - [`droneci`](modules/manager/droneci/index.md) - [`flux`](modules/manager/flux/index.md) +- [`github-actions`](modules/manager/github-actions/index.md) - [`gitlabci`](modules/manager/gitlabci/index.md) - [`helm-requirements`](modules/manager/helm-requirements/index.md) - [`helm-values`](modules/manager/helm-values/index.md) diff --git a/lib/modules/manager/github-actions/extract.ts b/lib/modules/manager/github-actions/extract.ts index c498615e1f6eff..c402dbcbc58ef9 100644 --- a/lib/modules/manager/github-actions/extract.ts +++ b/lib/modules/manager/github-actions/extract.ts @@ -10,7 +10,11 @@ import { GithubRunnersDatasource } from '../../datasource/github-runners'; import { GithubTagsDatasource } from '../../datasource/github-tags'; import * as dockerVersioning from '../../versioning/docker'; import { getDep } from '../dockerfile/extract'; -import type { PackageDependency, PackageFileContent } from '../types'; +import type { + ExtractConfig, + PackageDependency, + PackageFileContent, +} from '../types'; import type { Workflow } from './types'; const dockerActionRe = regEx(/^\s+uses\s*: ['"]?docker:\/\/([^'"]+)\s*$/); @@ -44,7 +48,10 @@ function detectCustomGitHubRegistryUrlsForActions(): PackageDependency { return {}; } -function extractWithRegex(content: string): PackageDependency[] { +function extractWithRegex( + content: string, + config: ExtractConfig, +): PackageDependency[] { const customRegistryUrlsPackageDependency = detectCustomGitHubRegistryUrlsForActions(); logger.trace('github-actions.extractWithRegex()'); @@ -57,7 +64,7 @@ function extractWithRegex(content: string): PackageDependency[] { const dockerMatch = dockerActionRe.exec(line); if (dockerMatch) { const [, currentFrom] = dockerMatch; - const dep = getDep(currentFrom); + const dep = getDep(currentFrom, true, config.registryAliases); dep.depType = 'docker'; deps.push(dep); continue; @@ -126,11 +133,14 @@ function detectDatasource(registryUrl: string): PackageDependency { }; } -function extractContainer(container: unknown): PackageDependency | undefined { +function extractContainer( + container: unknown, + registryAliases: Record | undefined, +): PackageDependency | undefined { if (is.string(container)) { - return getDep(container); + return getDep(container, true, registryAliases); } else if (is.plainObject(container) && is.string(container.image)) { - return getDep(container.image); + return getDep(container.image, true, registryAliases); } return undefined; } @@ -181,6 +191,7 @@ function extractRunners(runner: unknown): PackageDependency[] { function extractWithYAMLParser( content: string, packageFile: string, + config: ExtractConfig, ): PackageDependency[] { logger.trace('github-actions.extractWithYAMLParser()'); const deps: PackageDependency[] = []; @@ -198,14 +209,14 @@ function extractWithYAMLParser( } for (const job of Object.values(pkg?.jobs ?? {})) { - const dep = extractContainer(job?.container); + const dep = extractContainer(job?.container, config.registryAliases); if (dep) { dep.depType = 'container'; deps.push(dep); } for (const service of Object.values(job?.services ?? {})) { - const dep = extractContainer(service); + const dep = extractContainer(service, config.registryAliases); if (dep) { dep.depType = 'service'; deps.push(dep); @@ -221,11 +232,12 @@ function extractWithYAMLParser( export function extractPackageFile( content: string, packageFile: string, + config: ExtractConfig = {}, // TODO: enforce ExtractConfig ): PackageFileContent | null { logger.trace(`github-actions.extractPackageFile(${packageFile})`); const deps = [ - ...extractWithRegex(content), - ...extractWithYAMLParser(content, packageFile), + ...extractWithRegex(content, config), + ...extractWithYAMLParser(content, packageFile, config), ]; if (!deps.length) { return null;