Skip to content

Commit

Permalink
Merge pull request #731 from Financial-Times/pre-post-steps
Browse files Browse the repository at this point in the history
feat(circleci): support pre and post tool kit circleci job steps
  • Loading branch information
apaleslimghost authored Dec 20, 2024
2 parents 432d255 + e5f4b7f commit 2e59b06
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/schemas/src/hooks/circleci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const CircleCiExecutor = z
.required({ name: true })
export type CircleCiExecutor = z.infer<typeof CircleCiExecutor>

const CircleCiStep = z.union([z.string(), z.record(z.record(z.unknown()))])

export const CircleCiJob = z
.object({
name: z.string(),
Expand All @@ -25,6 +27,15 @@ export const CircleCiJob = z
persist: true,
attach: true
}),
steps: z
.object({
pre: z.array(CircleCiStep).default([]),
post: z.array(CircleCiStep).default([])
})
.default({
pre: [],
post: []
}),
custom: CircleCiCustom.optional()
})
.partial()
Expand Down
14 changes: 7 additions & 7 deletions plugins/circleci/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ Options provided in your repository's `.toolkitrc.yml` for this hook are merged
Unless they conflict, your options are appended to options from plugins, allowing you to define custom CircleCI jobs and workflows in your repository that work alongside those from plugins.
#### Hook options

| Property | Description | Type |
| :------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `executors` | an array of additional CircleCI executors to output in the generated config. | _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`image`: `string`</li></ul> |
| `jobs` | an array of additional CircleCI jobs to output in the generated config. these are used for running Tool Kit commands. for running arbitrary shell commands, use `custom`. | _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`command`: `string`</li><li>`workspace`: _Object with properties:_<ul><li>`persist`: `boolean`</li><li>`attach`: `boolean`</li></ul></li><li>`custom`: _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_)</li></ul> |
| `workflows` | an array of additional CircleCI workflows to output in the generated config. these reference jobs defined in the `jobs` option. | _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`jobs`: _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`requires`: `Array<string>`</li><li>`splitIntoMatrix`: `boolean`</li><li>`runOnRelease`: `boolean`</li><li>`custom`: _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_)</li></ul></li><li>`runOnRelease`: `boolean`</li><li>`custom`: _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_)</li></ul> |
| `custom` | arbitrary additional CircleCI configuration that will be merged into the Tool Kit-generated config. | _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_) |
| `disableBaseConfig` | set to `true` to omit the Tool Kit CircleCI boilerplate. should be used along with `custom` to provide your own boilerplate. | `boolean` |
| Property | Description | Type |
| :------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `executors` | an array of additional CircleCI executors to output in the generated config. | _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`image`: `string`</li></ul> |
| `jobs` | an array of additional CircleCI jobs to output in the generated config. these are used for running Tool Kit commands. for running arbitrary shell commands, use `custom`. | _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`command`: `string`</li><li>`workspace`: _Object with properties:_<ul><li>`persist`: `boolean`</li><li>`attach`: `boolean`</li></ul></li><li>`steps`: _Object with properties:_<ul><li>`pre`: `Array<string _or_ _Object with dynamic keys of type_ string _and values of type_ _Object with dynamic keys of type_ string _and values of type_ unknown (_optional & nullable_)>`</li><li>`post`: `Array<string _or_ _Object with dynamic keys of type_ string _and values of type_ _Object with dynamic keys of type_ string _and values of type_ unknown (_optional & nullable_)>`</li></ul></li><li>`custom`: _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_)</li></ul> |
| `workflows` | an array of additional CircleCI workflows to output in the generated config. these reference jobs defined in the `jobs` option. | _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`jobs`: _Array of objects:_<br /><ul><li>`name`: `string`</li><li>`requires`: `Array<string>`</li><li>`splitIntoMatrix`: `boolean`</li><li>`runOnRelease`: `boolean`</li><li>`custom`: _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_)</li></ul></li><li>`runOnRelease`: `boolean`</li><li>`custom`: _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_)</li></ul> |
| `custom` | arbitrary additional CircleCI configuration that will be merged into the Tool Kit-generated config. | _Object with dynamic keys of type_ `string` _and values of type_ `unknown` (_optional & nullable_) |
| `disableBaseConfig` | set to `true` to omit the Tool Kit CircleCI boilerplate. should be used along with `custom` to provide your own boilerplate. | `boolean` |

_All properties are optional._

Expand Down
2 changes: 2 additions & 0 deletions plugins/circleci/src/circleci-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,14 @@ const attachWorkspaceStep = {
const generateJob = (job: CircleCiJob): JobConfig => ({
steps: [
...(job.workspace?.attach ? [attachWorkspaceStep] : []),
...(job.steps?.pre ?? []),
{
run: {
name: job.name,
command: `npx dotcom-tool-kit ${job.command}`
}
},
...(job.steps?.post ?? []),
...(job.workspace?.persist ? [persistWorkspaceStep] : [])
],
...job.custom
Expand Down

0 comments on commit 2e59b06

Please sign in to comment.