create-typescript-app 2.77.1 → 2.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,7 @@ import { blockRepositoryBranchRuleset } from "./blockRepositoryBranchRuleset.mjs
|
|
|
6
6
|
import { createMultiWorkflowFile, zMultiWorkflowJobPermissions } from "./files/createMultiWorkflowFile.mjs";
|
|
7
7
|
import { createSoloWorkflowFile } from "./files/createSoloWorkflowFile.mjs";
|
|
8
8
|
import { formatYaml } from "./files/formatYaml.mjs";
|
|
9
|
+
import { groupParallelJobs } from "./files/groupParallelJobs.mjs";
|
|
9
10
|
import { withPreviously } from "./files/withPreviously.mjs";
|
|
10
11
|
import { z } from "zod";
|
|
11
12
|
// src/blocks/blockGitHubActionsCI.ts
|
|
@@ -31,9 +32,10 @@ const blockGitHubActionsCI = base.createBlock({
|
|
|
31
32
|
}
|
|
32
33
|
}, { run: "pnpm install --prod --engine-strict --ignore-scripts" }]
|
|
33
34
|
}].toSorted((a, b) => a.name.localeCompare(b.name));
|
|
35
|
+
const ciJobs = jobsWithEnginesCheck && groupParallelJobs(jobsWithEnginesCheck);
|
|
34
36
|
const prReviewLabelsUses = resolveUses("JoshuaKGoldberg/pr-review-labels-action", "v0.1.0", options.workflowsVersions);
|
|
35
37
|
return {
|
|
36
|
-
addons: [blockRepositoryBranchRuleset({ requiredStatusChecks:
|
|
38
|
+
addons: [blockRepositoryBranchRuleset({ requiredStatusChecks: ciJobs?.map((job) => job.name) })],
|
|
37
39
|
files: { ".github": {
|
|
38
40
|
actions: { prepare: { "action.yaml": withPreviously(formatYaml({
|
|
39
41
|
description: "Prepares the repo for a typical CI job",
|
|
@@ -57,8 +59,8 @@ const blockGitHubActionsCI = base.createBlock({
|
|
|
57
59
|
}
|
|
58
60
|
}), ["action.yml"]) } },
|
|
59
61
|
workflows: {
|
|
60
|
-
"ci.yaml": withPreviously(
|
|
61
|
-
jobs:
|
|
62
|
+
"ci.yaml": withPreviously(ciJobs && createMultiWorkflowFile({
|
|
63
|
+
jobs: ciJobs,
|
|
62
64
|
name: "CI",
|
|
63
65
|
workflowsVersions: options.workflowsVersions
|
|
64
66
|
}), ["ci.yml"]),
|
|
@@ -17,12 +17,16 @@ export interface MultiWorkflowJobOptions {
|
|
|
17
17
|
permissions?: z.infer<typeof zMultiWorkflowJobPermissions>;
|
|
18
18
|
steps: MultiWorkflowJobStep[];
|
|
19
19
|
}
|
|
20
|
-
export type MultiWorkflowJobStep = {
|
|
20
|
+
export type MultiWorkflowJobStep = ({
|
|
21
|
+
env?: Record<string, string>;
|
|
21
22
|
if?: string;
|
|
23
|
+
name?: string;
|
|
22
24
|
} & ({
|
|
23
25
|
run: string;
|
|
24
26
|
} | {
|
|
25
27
|
uses: string;
|
|
26
28
|
with?: Record<string, string>;
|
|
27
|
-
})
|
|
29
|
+
})) | {
|
|
30
|
+
parallel: MultiWorkflowJobStep[];
|
|
31
|
+
};
|
|
28
32
|
export declare function createMultiWorkflowFile({ jobs, name, workflowsVersions }: MultiWorkflowFileOptions): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createJobName } from "./createJobName.mjs";
|
|
2
|
+
// src/blocks/files/groupParallelJobs.ts
|
|
3
|
+
const maximumParallelSteps = 10;
|
|
4
|
+
function groupParallelJobs(jobs) {
|
|
5
|
+
if (jobs.some((job) => createJobName(job.name) === "ci")) return jobs;
|
|
6
|
+
const parallelSteps = [];
|
|
7
|
+
const separateJobs = [];
|
|
8
|
+
let needsBuild = false;
|
|
9
|
+
for (const job of jobs) {
|
|
10
|
+
const builds = isBuildStep(job.steps[0]);
|
|
11
|
+
const steps = builds ? job.steps.slice(1) : job.steps;
|
|
12
|
+
if (canRunInParallel(job) && (builds ? steps.length <= 1 : steps.length === 1) && steps.every(canStepRunInParallel) && parallelSteps.length < maximumParallelSteps) {
|
|
13
|
+
needsBuild ||= builds;
|
|
14
|
+
parallelSteps.push(...steps.map((step) => ({
|
|
15
|
+
...step,
|
|
16
|
+
name: job.name
|
|
17
|
+
})));
|
|
18
|
+
} else separateJobs.push(job);
|
|
19
|
+
}
|
|
20
|
+
if (separateJobs.length === jobs.length) return jobs;
|
|
21
|
+
return [{
|
|
22
|
+
name: "CI",
|
|
23
|
+
steps: [...needsBuild ? [{ run: "pnpm build" }] : [], ...parallelSteps.length > 1 ? [{ parallel: parallelSteps }] : parallelSteps]
|
|
24
|
+
}, ...separateJobs].toSorted((a, b) => a.name.localeCompare(b.name));
|
|
25
|
+
}
|
|
26
|
+
function canRunInParallel(job) {
|
|
27
|
+
return !job.checkoutWith && !job.if && !job.permissions;
|
|
28
|
+
}
|
|
29
|
+
function canStepRunInParallel(step) {
|
|
30
|
+
return !("if" in step && step.if);
|
|
31
|
+
}
|
|
32
|
+
function isBuildStep(step) {
|
|
33
|
+
return !!step && Object.keys(step).length === 1 && "run" in step && step.run === "pnpm build";
|
|
34
|
+
}
|
|
35
|
+
export { groupParallelJobs };
|