Skip to content

Commit

Permalink
feat(manager/github-actions): support registry aliases (#33377)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Jan 2, 2025
1 parent 60754ce commit 73b842f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 22 additions & 10 deletions lib/modules/manager/github-actions/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*$/);
Expand Down Expand Up @@ -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()');
Expand All @@ -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;
Expand Down Expand Up @@ -126,11 +133,14 @@ function detectDatasource(registryUrl: string): PackageDependency {
};
}

function extractContainer(container: unknown): PackageDependency | undefined {
function extractContainer(
container: unknown,
registryAliases: Record<string, string> | 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;
}
Expand Down Expand Up @@ -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[] = [];
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 73b842f

Please sign in to comment.