From 269a4dd125422841e99ef9140f9afcca30ca2ccb Mon Sep 17 00:00:00 2001 From: Sebastian Poxhofer Date: Fri, 2 Aug 2024 15:48:53 +0200 Subject: [PATCH] fix(manager/circleci): extract executors of CircleCi files again (#30562) --- lib/modules/manager/circleci/extract.spec.ts | 20 ++++++++++++++++++++ lib/modules/manager/circleci/extract.ts | 9 +++++++-- lib/modules/manager/circleci/schema.ts | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/circleci/extract.spec.ts b/lib/modules/manager/circleci/extract.spec.ts index 43443f18d1e659..be62edddf87936 100644 --- a/lib/modules/manager/circleci/extract.spec.ts +++ b/lib/modules/manager/circleci/extract.spec.ts @@ -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', + }, + ]); + }); }); }); diff --git a/lib/modules/manager/circleci/extract.ts b/lib/modules/manager/circleci/extract.ts index dd73d2ac046248..e56da71ea4b39f 100644 --- a/lib/modules/manager/circleci/extract.ts +++ b/lib/modules/manager/circleci/extract.ts @@ -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), diff --git a/lib/modules/manager/circleci/schema.ts b/lib/modules/manager/circleci/schema.ts index 2d6e831c655ea9..2aa96811019fc3 100644 --- a/lib/modules/manager/circleci/schema.ts +++ b/lib/modules/manager/circleci/schema.ts @@ -4,12 +4,14 @@ export const CircleCiDocker = z.object({ image: z.string(), }); +export type CircleCiJob = z.infer; 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(), });