mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 23:11:31 +00:00
19306f7e17
* refactor(manager/helmv3): share generateHelmEnvs with kustomize Move kustomize's generateHelmEnvs into helmv3/common.ts and delete the kustomize copy. The merged function always sets the three HELM_* path variables and sets HELM_EXPERIMENTAL_OCI unless a helm constraint is present and proves helm >= 3.8 (which ignores the variable). Behaviour change: kustomize now sets HELM_EXPERIMENTAL_OCI when the helm constraint is unknown (previously it only set it for a known constraint below 3.8). helmv3 and helmfile now omit the variable once a resolved helm constraint proves helm >= 3.8. * refactor(manager/helmv3): share OCI registry login helper with helmfile Extract a shared generateRegistryLoginCmd(name, registry) helper in helmv3/common.ts that strips the oci:// prefix, derives the host and looks up the matching host rule before delegating to generateLoginCmd. helmv3/artifacts.ts and helmfile/artifacts.ts now both call this helper instead of each building a RepositoryRule inline, removing the stale oci:// TODO. helmfile/utils.ts loses its duplicate generateRegistryLoginCmd, and its unrelated isOCIRegistry(repository) (checking the oci flag) is renamed to isOciRepositoryFlagSet so it no longer collides in name with helmv3/oci.ts's prefix-based isOCIRegistry(string), which helmfile/extract.ts also imports. Addresses audit finding M8. Generated `helm registry login` commands are unchanged, proved by the existing artifacts specs passing with their original expectations untouched. * fix(manager): share one local Helm chart path check helmfile, flux, fleet and terraform each decided differently whether a Helm chart reference points at a local path. fleet and terraform used terraform's checkIfStringIsPath, whose regex was unanchored with unescaped dots, so it matched any string containing a slash followed by a non-slash character. Add isLocalChartPath to helmv3/utils.ts with helmfile's prefix check and use it in all four managers. This drops the fleet to terraform dependency and removes checkIfStringIsPath, which had no other users. * refactor(manager/helm-requirements): reuse helmv3 alias and repository helpers Replace the duplicated alias-resolution and repository-classification logic in helm-requirements/extract.ts with the shared isAlias, resolveAlias and parseRepository helpers from helmv3/utils.ts (audit finding M9). Behaviour is unchanged: same skipReasons, same registryUrls, same handling of a missing repository or missing registryAliases config. * refactor(manager/dockerfile): add an options form of getDep for CI managers `getDep()` gains an overload taking a `GetDepOptions` object with `specifyReplaceString`, `registryAliases` and `depType`, replacing the opaque boolean second positional argument at the CI manager call sites. The positional form keeps working for all other callers. Migrated: bitbucket-pipelines, droneci, circleci, github-actions, azure-pipelines and woodpecker. Behaviour changes: - azure-pipelines container resources now honour `registryAliases`, which `extractContainer()` previously ignored - woodpecker dependencies now carry `depType: 'docker'`, matching the other CI managers * refactor(manager/woodpecker): do not set depType on docker image deps * refactor(manager/dockerfile): drop the positional getDep signature * refactor(manager/helm-requirements): reuse helmv3 alias and repository helpers Replace the duplicated alias-resolution and repository-classification logic in helm-requirements/extract.ts with the shared isAlias, resolveAlias and parseRepository helpers from helmv3/utils.ts (audit finding M9). Behaviour is unchanged: same skipReasons, same registryUrls, same handling of a missing repository or missing registryAliases config.
117 lines
3.7 KiB
TypeScript
117 lines
3.7 KiB
TypeScript
import upath from 'upath';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import { isNotNullOrUndefined } from '../../../util/array.ts';
|
|
import { regEx } from '../../../util/regex.ts';
|
|
import { LooseArray } from '../../../util/schema-utils/index.ts';
|
|
import { getDep } from '../dockerfile/extract.ts';
|
|
import type {
|
|
ExtractConfig,
|
|
PackageDependency,
|
|
PackageFileContent,
|
|
} from '../types.ts';
|
|
import * as bazelrc from './bazelrc.ts';
|
|
import { RuleToCratePackageDep } from './parser/crate.ts';
|
|
import { parse } from './parser/index.ts';
|
|
import { RuleToMavenPackageDep, fillRegistryUrls } from './parser/maven.ts';
|
|
import { RuleToDockerPackageDep } from './parser/oci.ts';
|
|
import type { ResultFragment } from './parser/types.ts';
|
|
import * as rules from './rules.ts';
|
|
import {
|
|
GitRepositoryToPackageDep,
|
|
RuleToBazelModulePackageDep,
|
|
} from './rules.ts';
|
|
import { transformRulesImgCalls } from './rules-img.ts';
|
|
|
|
export async function extractPackageFile(
|
|
content: string,
|
|
packageFile: string,
|
|
config?: ExtractConfig,
|
|
): Promise<PackageFileContent | null> {
|
|
try {
|
|
const records = parse(content);
|
|
const pfc = await extractBazelPfc(records, packageFile);
|
|
const gitRepositoryDeps = extractGitRepositoryDeps(records);
|
|
const mavenDeps = extractMavenDeps(records);
|
|
const dockerDeps = LooseArray(RuleToDockerPackageDep)
|
|
.transform((deps) =>
|
|
deps.map((dep) => {
|
|
// Reconstruct the image reference from parsed data
|
|
const imageRef = `${dep.packageName}${dep.currentValue ? `:${dep.currentValue}` : ''}${dep.currentDigest ? `@${dep.currentDigest}` : ''}`;
|
|
// Use getDep to handle registry aliases properly
|
|
const processedDep = getDep(imageRef, {
|
|
specifyReplaceString: false,
|
|
registryAliases: config?.registryAliases,
|
|
});
|
|
return {
|
|
...processedDep,
|
|
depType: 'oci_pull',
|
|
depName: dep.depName, // Keep the original name field from bazel
|
|
replaceString: dep.replaceString, // Keep the original replace string
|
|
};
|
|
}),
|
|
)
|
|
.parse(records);
|
|
const rulesImgDeps = transformRulesImgCalls(records);
|
|
const crateDeps = LooseArray(RuleToCratePackageDep).parse(records);
|
|
|
|
if (gitRepositoryDeps.length) {
|
|
pfc.deps.push(...gitRepositoryDeps);
|
|
}
|
|
|
|
if (mavenDeps.length) {
|
|
pfc.deps.push(...mavenDeps);
|
|
}
|
|
|
|
if (dockerDeps.length) {
|
|
pfc.deps.push(...dockerDeps);
|
|
}
|
|
|
|
if (rulesImgDeps.length) {
|
|
pfc.deps.push(...rulesImgDeps);
|
|
}
|
|
|
|
if (crateDeps.length) {
|
|
pfc.deps.push(...crateDeps);
|
|
}
|
|
|
|
return pfc.deps.length ? pfc : null;
|
|
} catch (err) {
|
|
logger.debug({ err, packageFile }, 'Failed to parse bazel module file.');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function extractBazelPfc(
|
|
records: ResultFragment[],
|
|
packageFile: string,
|
|
): Promise<PackageFileContent> {
|
|
const pfc: PackageFileContent = LooseArray(RuleToBazelModulePackageDep)
|
|
.transform(rules.toPackageDependencies)
|
|
.transform((deps) => ({ deps }))
|
|
.parse(records);
|
|
|
|
const registryUrls = (await bazelrc.read(upath.dirname(packageFile)))
|
|
// Ignore any entries for custom configurations
|
|
.filter((ce) => ce.config === undefined)
|
|
.map((ce) => ce.getOption('registry')?.value)
|
|
.map((url) => url?.replace(regEx(/^["']|["']$/g), ''))
|
|
.filter(isNotNullOrUndefined);
|
|
if (registryUrls.length) {
|
|
pfc.registryUrls = registryUrls;
|
|
}
|
|
|
|
return pfc;
|
|
}
|
|
|
|
function extractGitRepositoryDeps(
|
|
records: ResultFragment[],
|
|
): PackageDependency[] {
|
|
return LooseArray(GitRepositoryToPackageDep).parse(records);
|
|
}
|
|
|
|
function extractMavenDeps(records: ResultFragment[]): PackageDependency[] {
|
|
return LooseArray(RuleToMavenPackageDep)
|
|
.transform(fillRegistryUrls)
|
|
.parse(records);
|
|
}
|