fix(manager/circleci): extract executors of CircleCi files again (#30562)

This commit is contained in:
Sebastian Poxhofer 2024-08-02 15:48:53 +02:00 committed by GitHub
parent f0c2067798
commit 269a4dd125
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 2 deletions

View file

@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from '.';
@ -78,5 +79,24 @@ describe('modules/manager/circleci/extract', () => {
},
]);
});
it('extracts executors', () => {
const res = extractPackageFile(codeBlock`
executors:
my-executor:
docker:
- image: cimg/ruby:3.0.3-browsers`);
expect(res?.deps).toEqual([
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentValue: '3.0.3-browsers',
datasource: 'docker',
depName: 'cimg/ruby',
depType: 'docker',
replaceString: 'cimg/ruby:3.0.3-browsers',
},
]);
});
});
});

View file

@ -5,7 +5,7 @@ import { OrbDatasource } from '../../datasource/orb';
import * as npmVersioning from '../../versioning/npm';
import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFileContent } from '../types';
import { CircleCiFile } from './schema';
import { CircleCiFile, type CircleCiJob } from './schema';
export function extractPackageFile(
content: string,
@ -30,7 +30,12 @@ export function extractPackageFile(
});
}
for (const job of Object.values(parsed.jobs ?? {})) {
// extract environments
const environments: CircleCiJob[] = [
Object.values(parsed.executors ?? {}),
Object.values(parsed.jobs ?? {}),
].flat();
for (const job of environments) {
for (const dockerElement of coerceArray(job.docker)) {
deps.push({
...getDep(dockerElement.image),

View file

@ -4,12 +4,14 @@ export const CircleCiDocker = z.object({
image: z.string(),
});
export type CircleCiJob = z.infer<typeof CircleCiJob>;
export const CircleCiJob = z.object({
docker: z.array(CircleCiDocker).optional(),
});
export const CircleCiFile = z.object({
aliases: z.array(CircleCiDocker).optional(),
executors: z.record(z.string(), CircleCiJob).optional(),
jobs: z.record(z.string(), CircleCiJob).optional(),
orbs: z.record(z.string()).optional(),
});