Skip to content

Commit

Permalink
fix: use nullish coalescing instead of zod defaults for circleci hook…
Browse files Browse the repository at this point in the history
… options with defaults

the `.partial()` on the hook option objects is overriding the `.default()` on their properties.
short of splitting the schema into an incoming options schema that's meant to be merged from
multiple sources, and an outgoing schema for the final hook options, this is the most
straightforward way of doing this.
  • Loading branch information
apaleslimghost authored and ivomurrell committed Jan 16, 2025
1 parent 77b2c2c commit 02ca200
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
20 changes: 7 additions & 13 deletions lib/schemas/src/hooks/circleci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ export const CircleCiJob = z
command: z.string(),
workspace: z
.object({
persist: z.boolean().default(true),
attach: z.boolean().default(true)
persist: z.boolean().optional(),
attach: z.boolean().optional()
})
.default({
persist: true,
attach: true
}),
.optional(),
steps: z
.object({
pre: z.array(CircleCiStep).default([]),
post: z.array(CircleCiStep).default([])
pre: z.array(CircleCiStep).optional(),
post: z.array(CircleCiStep).optional()
})
.default({
pre: [],
post: []
}),
.optional(),
custom: CircleCiCustom.optional()
})
.partial()
Expand All @@ -47,7 +41,7 @@ export const CircleCiWorkflowJob = z
name: z.string(),
requires: z.array(z.string()),
splitIntoMatrix: z.boolean().optional(),
runOnRelease: z.boolean().default(true),
runOnRelease: z.boolean().optional(),
custom: CircleCiCustom.optional()
})
.partial()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ workflows:
executor: node
requires:
- tool-kit/setup
filters:
tags:
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
- tool-kit/test:
executor: node
requires:
- tool-kit/build
filters:
tags:
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
- tool-kit/deploy-review:
executor: node
requires:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,26 @@ workflows:
executor: node
requires:
- tool-kit/setup
filters:
tags:
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
- tool-kit/test:
executor: node
requires:
- tool-kit/build
filters:
tags:
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
- tool-kit/publish-tag:
executor: node
requires:
- tool-kit/test
context: npm-publish-token
filters:
tags:
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
branches:
ignore: /.*/
context: npm-publish-token
nightly:
when:
and:
Expand Down
6 changes: 3 additions & 3 deletions plugins/circleci/src/circleci-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const generateWorkflowJobs = (
return `${requiredOrb}-${splitIntoMatrix ? '<< matrix.executor >>' : 'node'}`
})
},
workflow.runOnRelease && job.runOnRelease ? tagFilter(tagFilterRegex) : {},
workflow.runOnRelease && (job.runOnRelease ?? true) ? tagFilter(tagFilterRegex) : {},
job.custom
)
}
Expand All @@ -418,7 +418,7 @@ const attachWorkspaceStep = {

const generateJob = (job: CircleCiJob): JobConfig => ({
steps: [
...(job.workspace?.attach ? [attachWorkspaceStep] : []),
...(job.workspace?.attach ?? true ? [attachWorkspaceStep] : []),
...(job.steps?.pre ?? []),
{
run: {
Expand All @@ -427,7 +427,7 @@ const generateJob = (job: CircleCiJob): JobConfig => ({
}
},
...(job.steps?.post ?? []),
...(job.workspace?.persist ? [persistWorkspaceStep] : [])
...(job.workspace?.persist ?? true ? [persistWorkspaceStep] : [])
],
...job.custom
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ workflows:
executor: node
requires:
- tool-kit/setup
filters:
tags:
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
- tool-kit/test:
executor: node
requires:
- tool-kit/build
filters:
tags:
only: /^v\\d+\\.\\d+\\.\\d+(-.+)?/
nightly:
when:
and:
Expand Down
26 changes: 26 additions & 0 deletions plugins/circleci/test/circleci-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,25 @@ describe('CircleCI config hook', () => {
"jobs": {
"test-job": {
"steps": [
{
"attach-workspace": {
"at": ".",
},
},
{
"run": {
"command": "npx dotcom-tool-kit test:local",
"name": "test-job",
},
},
{
"persist_to_workspace": {
"paths": [
".",
],
"root": ".",
},
},
],
},
},
Expand Down Expand Up @@ -217,12 +230,25 @@ describe('CircleCI config hook', () => {
"jobs": {
"test-job": {
"steps": [
{
"attach-workspace": {
"at": ".",
},
},
{
"run": {
"command": "npx dotcom-tool-kit test:local",
"name": "test-job",
},
},
{
"persist_to_workspace": {
"paths": [
".",
],
"root": ".",
},
},
],
},
},
Expand Down

0 comments on commit 02ca200

Please sign in to comment.