Skip to content
Snippets Groups Projects
Unverified Commit 4cfb6b29 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

fix(bitrise): Streamline Zod schema (#33769)

parent 55b8d0e1
No related branches found
No related tags found
No related merge requests found
import is from '@sindresorhus/is';
import { logger } from '../../../logger';
import { parseSingleYaml } from '../../../util/yaml';
import type { PackageDependency, PackageFileContent } from '../types';
import type { PackageFileContent } from '../types';
import { BitriseFile } from './schema';
import { parseStep } from './utils';
export function extractPackageFile(
content: string,
packageFile: string,
): PackageFileContent | null {
const deps: PackageDependency[] = [];
try {
const parsed = parseSingleYaml(content, {
customSchema: BitriseFile,
});
const workflows = Object.values(parsed.workflows);
for (const workflow of workflows) {
const steps = workflow.steps.flatMap((step) => Object.keys(step));
for (const step of steps) {
const dep = parseStep(step, parsed.default_step_lib_source);
if (!is.nullOrUndefined(dep)) {
deps.push(dep);
}
}
}
} catch (err) {
const deps = BitriseFile.catch(({ error: err }) => {
logger.debug({ err, packageFile }, `Failed to parse Bitrise YAML config`);
}
return [];
}).parse(content);
if (!deps.length) {
return null;
......
import { z } from 'zod';
import { filterMap } from '../../../util/filter-map';
import { Yaml } from '../../../util/schema-utils';
import { parseStep } from './utils';
export const BitriseStep = z.record(z.string(), z.unknown());
export const BitriseWorkflow = z.object({
steps: z.array(BitriseStep),
});
export const BitriseFile = z.object({
default_step_lib_source: z.string().optional(),
workflows: z.record(z.string(), BitriseWorkflow),
});
export const BitriseFile = Yaml.pipe(
z
.object({
default_step_lib_source: z.string().optional(),
workflows: z
.record(
z
.object({
steps: z
.array(z.record(z.unknown()).transform((x) => Object.keys(x)))
.transform((steps) => steps.flat()),
})
.transform(({ steps }) => steps),
)
.transform((x) => Object.values(x).flat()),
})
.transform(({ default_step_lib_source: defaultRegistry, workflows }) =>
filterMap(workflows, (workflow) => parseStep(workflow, defaultRegistry)),
),
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment