Compare commits

...

7 commits

Author SHA1 Message Date
Kay W.
9ec438707e
Merge 153edf5a75 into 73b842fe3a 2025-01-02 21:07:20 +02:00
Michael Kriese
73b842fe3a
feat(manager/github-actions): support registry aliases (#33377) 2025-01-02 18:06:11 +00:00
Kay W.
153edf5a75
Fix lint 2024-12-14 22:56:11 +08:00
Kay W.
e4e54740d1
Update lib/modules/manager/bundler/artifacts.ts
Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
2024-12-14 21:44:43 +08:00
Rhys Arkins
f5118d5c45
Merge branch 'main' into bugfix/fix-lockfile-maintenance-for-composer-manager 2024-12-14 09:59:16 +01:00
Kay W.
103db10e1d
Merge branch 'main' into bugfix/fix-lockfile-maintenance-for-composer-manager 2024-12-07 00:12:01 +08:00
Kayw
bbd3ef5b4c fix: resolve the lockFileMaintenance not working 2024-12-06 20:48:30 +08:00
13 changed files with 59 additions and 23 deletions

View file

@ -3707,6 +3707,7 @@ This feature works with the following managers:
- [`dockerfile`](modules/manager/dockerfile/index.md) - [`dockerfile`](modules/manager/dockerfile/index.md)
- [`droneci`](modules/manager/droneci/index.md) - [`droneci`](modules/manager/droneci/index.md)
- [`flux`](modules/manager/flux/index.md) - [`flux`](modules/manager/flux/index.md)
- [`github-actions`](modules/manager/github-actions/index.md)
- [`gitlabci`](modules/manager/gitlabci/index.md) - [`gitlabci`](modules/manager/gitlabci/index.md)
- [`helm-requirements`](modules/manager/helm-requirements/index.md) - [`helm-requirements`](modules/manager/helm-requirements/index.md)
- [`helm-values`](modules/manager/helm-values/index.md) - [`helm-values`](modules/manager/helm-values/index.md)

View file

@ -93,7 +93,10 @@ export async function updateArtifacts(
const commands: string[] = []; const commands: string[] = [];
if (config.isLockFileMaintenance) { if (
updatedDeps.some((dep) => dep.updateType === 'lockFileMaintenance') ||
config.isLockFileMaintenance
) {
commands.push('bundler lock --update'); commands.push('bundler lock --update');
} else { } else {
const bundlerUpgraded = updatedDeps const bundlerUpgraded = updatedDeps
@ -289,6 +292,7 @@ export async function updateArtifacts(
if ( if (
recursionLimit > 0 && recursionLimit > 0 &&
resolveMatches.length && resolveMatches.length &&
config.updateType !== 'lockFileMaintenance' &&
!config.isLockFileMaintenance !config.isLockFileMaintenance
) { ) {
logger.debug( logger.debug(

View file

@ -725,8 +725,8 @@ describe('modules/manager/composer/artifacts', () => {
updatedDeps: [], updatedDeps: [],
newPackageFileContent: '{}', newPackageFileContent: '{}',
config: { config: {
updateType: 'lockFileMaintenance',
...config, ...config,
isLockFileMaintenance: true,
}, },
}), }),
).toEqual([ ).toEqual([

View file

@ -113,6 +113,8 @@ export async function updateArtifacts({
const file = Json.pipe(PackageFile).parse(newPackageFileContent); const file = Json.pipe(PackageFile).parse(newPackageFileContent);
const isLockFileMaintenance =
config.updateType === 'lockFileMaintenance' || config.isLockFileMaintenance;
const lockFileName = packageFileName.replace(regEx(/\.json$/), '.lock'); const lockFileName = packageFileName.replace(regEx(/\.json$/), '.lock');
const lockfile = await z const lockfile = await z
.string() .string()
@ -174,7 +176,7 @@ export async function updateArtifacts({
const cmd = 'composer'; const cmd = 'composer';
let args: string; let args: string;
if (config.isLockFileMaintenance) { if (isLockFileMaintenance) {
args = 'update'; args = 'update';
} else { } else {
args = args =

View file

@ -10,7 +10,11 @@ import { GithubRunnersDatasource } from '../../datasource/github-runners';
import { GithubTagsDatasource } from '../../datasource/github-tags'; import { GithubTagsDatasource } from '../../datasource/github-tags';
import * as dockerVersioning from '../../versioning/docker'; import * as dockerVersioning from '../../versioning/docker';
import { getDep } from '../dockerfile/extract'; import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFileContent } from '../types'; import type {
ExtractConfig,
PackageDependency,
PackageFileContent,
} from '../types';
import type { Workflow } from './types'; import type { Workflow } from './types';
const dockerActionRe = regEx(/^\s+uses\s*: ['"]?docker:\/\/([^'"]+)\s*$/); const dockerActionRe = regEx(/^\s+uses\s*: ['"]?docker:\/\/([^'"]+)\s*$/);
@ -44,7 +48,10 @@ function detectCustomGitHubRegistryUrlsForActions(): PackageDependency {
return {}; return {};
} }
function extractWithRegex(content: string): PackageDependency[] { function extractWithRegex(
content: string,
config: ExtractConfig,
): PackageDependency[] {
const customRegistryUrlsPackageDependency = const customRegistryUrlsPackageDependency =
detectCustomGitHubRegistryUrlsForActions(); detectCustomGitHubRegistryUrlsForActions();
logger.trace('github-actions.extractWithRegex()'); logger.trace('github-actions.extractWithRegex()');
@ -57,7 +64,7 @@ function extractWithRegex(content: string): PackageDependency[] {
const dockerMatch = dockerActionRe.exec(line); const dockerMatch = dockerActionRe.exec(line);
if (dockerMatch) { if (dockerMatch) {
const [, currentFrom] = dockerMatch; const [, currentFrom] = dockerMatch;
const dep = getDep(currentFrom); const dep = getDep(currentFrom, true, config.registryAliases);
dep.depType = 'docker'; dep.depType = 'docker';
deps.push(dep); deps.push(dep);
continue; continue;
@ -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)) { if (is.string(container)) {
return getDep(container); return getDep(container, true, registryAliases);
} else if (is.plainObject(container) && is.string(container.image)) { } else if (is.plainObject(container) && is.string(container.image)) {
return getDep(container.image); return getDep(container.image, true, registryAliases);
} }
return undefined; return undefined;
} }
@ -181,6 +191,7 @@ function extractRunners(runner: unknown): PackageDependency[] {
function extractWithYAMLParser( function extractWithYAMLParser(
content: string, content: string,
packageFile: string, packageFile: string,
config: ExtractConfig,
): PackageDependency[] { ): PackageDependency[] {
logger.trace('github-actions.extractWithYAMLParser()'); logger.trace('github-actions.extractWithYAMLParser()');
const deps: PackageDependency[] = []; const deps: PackageDependency[] = [];
@ -198,14 +209,14 @@ function extractWithYAMLParser(
} }
for (const job of Object.values(pkg?.jobs ?? {})) { for (const job of Object.values(pkg?.jobs ?? {})) {
const dep = extractContainer(job?.container); const dep = extractContainer(job?.container, config.registryAliases);
if (dep) { if (dep) {
dep.depType = 'container'; dep.depType = 'container';
deps.push(dep); deps.push(dep);
} }
for (const service of Object.values(job?.services ?? {})) { for (const service of Object.values(job?.services ?? {})) {
const dep = extractContainer(service); const dep = extractContainer(service, config.registryAliases);
if (dep) { if (dep) {
dep.depType = 'service'; dep.depType = 'service';
deps.push(dep); deps.push(dep);
@ -221,11 +232,12 @@ function extractWithYAMLParser(
export function extractPackageFile( export function extractPackageFile(
content: string, content: string,
packageFile: string, packageFile: string,
config: ExtractConfig = {}, // TODO: enforce ExtractConfig
): PackageFileContent | null { ): PackageFileContent | null {
logger.trace(`github-actions.extractPackageFile(${packageFile})`); logger.trace(`github-actions.extractPackageFile(${packageFile})`);
const deps = [ const deps = [
...extractWithRegex(content), ...extractWithRegex(content, config),
...extractWithYAMLParser(content, packageFile), ...extractWithYAMLParser(content, packageFile, config),
]; ];
if (!deps.length) { if (!deps.length) {
return null; return null;

View file

@ -161,7 +161,8 @@ export async function updateArtifacts({
} }
if ( if (
config.isLockFileMaintenance && (config.updateType === 'lockFileMaintenance' ||
config.isLockFileMaintenance) &&
(!isGradleBuildFile(packageFileName) || (!isGradleBuildFile(packageFileName) ||
dirname(packageFileName) !== dirname(gradlewFile)) dirname(packageFileName) !== dirname(gradlewFile))
) { ) {
@ -205,7 +206,8 @@ export async function updateArtifacts({
.join(' ')}`; .join(' ')}`;
if ( if (
config.isLockFileMaintenance === true || config.updateType === 'lockFileMaintenance' ||
config.isLockFileMaintenance ||
!updatedDeps.length || !updatedDeps.length ||
isGcvPropsFile(packageFileName) isGcvPropsFile(packageFileName)
) { ) {

View file

@ -48,7 +48,10 @@ export async function updateArtifacts(
}; };
try { try {
if (config.isLockFileMaintenance) { if (
config.updateType === 'lockFileMaintenance' ||
config.isLockFileMaintenance
) {
await exec('jb update', execOptions); await exec('jb update', execOptions);
} else { } else {
const dependencyUrls = updatedDeps.map(dependencyUrl); const dependencyUrls = updatedDeps.map(dependencyUrl);

View file

@ -34,7 +34,6 @@ const dockerAdminConfig = {
process.env.CONTAINERBASE = 'true'; process.env.CONTAINERBASE = 'true';
const config: UpdateArtifactsConfig = {}; const config: UpdateArtifactsConfig = {};
const lockMaintenanceConfig = { ...config, isLockFileMaintenance: true };
const updateInputCmd = `nix \ const updateInputCmd = `nix \
--extra-experimental-features 'nix-command flakes' \ --extra-experimental-features 'nix-command flakes' \
flake lock --update-input nixpkgs`; flake lock --update-input nixpkgs`;
@ -294,7 +293,7 @@ describe('modules/manager/nix/artifacts', () => {
packageFileName: 'flake.nix', packageFileName: 'flake.nix',
updatedDeps: [{ depName: 'nixpkgs' }], updatedDeps: [{ depName: 'nixpkgs' }],
newPackageFileContent: '{}', newPackageFileContent: '{}',
config: lockMaintenanceConfig, config: { updateType: 'lockFileMaintenance', ...config },
}); });
expect(res).toEqual([ expect(res).toEqual([

View file

@ -17,6 +17,9 @@ export async function updateArtifacts({
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> { }: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
const lockFileName = packageFileName.replace(regEx(/\.nix$/), '.lock'); const lockFileName = packageFileName.replace(regEx(/\.nix$/), '.lock');
const existingLockFileContent = await readLocalFile(lockFileName, 'utf8'); const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');
const isLockFileMaintenance =
config.updateType === 'lockFileMaintenance' || config.isLockFileMaintenance;
if (!existingLockFileContent) { if (!existingLockFileContent) {
logger.debug('No flake.lock found'); logger.debug('No flake.lock found');
return null; return null;
@ -35,7 +38,7 @@ export async function updateArtifacts({
cmd += `--extra-access-tokens github.com=${token} `; cmd += `--extra-access-tokens github.com=${token} `;
} }
if (config.isLockFileMaintenance) { if (isLockFileMaintenance) {
cmd += 'flake update'; cmd += 'flake update';
} else { } else {
const inputs = updatedDeps const inputs = updatedDeps

View file

@ -189,7 +189,7 @@ describe('modules/manager/nuget/artifacts', () => {
newPackageFileContent: '{}', newPackageFileContent: '{}',
config: { config: {
...config, ...config,
isLockFileMaintenance: true, updateType: 'lockFileMaintenance',
}, },
}), }),
).toEqual([ ).toEqual([

View file

@ -138,7 +138,11 @@ export async function updateArtifacts({
} }
try { try {
if (updatedDeps.length === 0 && config.isLockFileMaintenance !== true) { if (
updatedDeps.length === 0 &&
config.updateType !== 'lockFileMaintenance' &&
config.isLockFileMaintenance !== true
) {
logger.debug( logger.debug(
`Not updating lock file because no deps changed and no lock file maintenance.`, `Not updating lock file because no deps changed and no lock file maintenance.`,
); );

View file

@ -110,7 +110,10 @@ export async function updateArtifacts({
try { try {
await writeLocalFile(inputFileName, newInputContent); await writeLocalFile(inputFileName, newInputContent);
// TODO(not7cd): use --upgrade option instead deleting // TODO(not7cd): use --upgrade option instead deleting
if (config.isLockFileMaintenance) { if (
config.updateType === 'lockFileMaintenance' ||
config.isLockFileMaintenance
) {
await deleteLocalFile(outputFileName); await deleteLocalFile(outputFileName);
} }
const compileArgs = extractHeaderCommand(existingOutput, outputFileName); const compileArgs = extractHeaderCommand(existingOutput, outputFileName);

View file

@ -135,7 +135,10 @@ export async function updateArtifacts({
} }
try { try {
await writeLocalFile(pipfileName, newPipfileContent); await writeLocalFile(pipfileName, newPipfileContent);
if (config.isLockFileMaintenance) { if (
config.updateType === 'lockFileMaintenance' ||
config.isLockFileMaintenance
) {
await deleteLocalFile(lockFileName); await deleteLocalFile(lockFileName);
} }
const cmd = 'pipenv lock'; const cmd = 'pipenv lock';