Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPP-2313 Add proper support for custom jobs in CircleCI #753

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ivomurrell
Copy link
Contributor

Description

Our initial 4.0 release of Tool Kit only contained minimal support for defining custom jobs in CircleCI. They didn't define the executor the job would run in, resulting in CircleCI validation errors unless they were added explicitly in a custom block, so even calling it 'minimal support' might be a stretch. This PR adds proper support for the execution property, as well as adding a splitIntoMatrix option to jobs which works the same as it does for workflow jobs. Efforts have also been made to refactor the code so that it's easier to follow.

This now allows us to generate a CircleCI config for next-preflight using Tool Kit config exclusively without manual intervention.

Closes #740, as this PR carries on from the changes made in that PR.

Checklist:

  • My commit messages are conventional commits, for example: feat(circleci): add support for nightly workflows, fix: set Heroku app name for staging apps too

@ivomurrell ivomurrell requested a review from a team as a code owner January 9, 2025 17:05
@ivomurrell ivomurrell force-pushed the generated-job-executors branch 2 times, most recently from 51fa35c to 3b2e670 Compare January 14, 2025 18:30
@ivomurrell ivomurrell force-pushed the generated-job-executors branch from 3b2e670 to 31ec896 Compare January 22, 2025 16:29
Our previous logic for guessing whether to prepend our Tool Kit orb
namespace to a workflow job didn't account for approval jobs, which
don't need to be declared in a `jobs` stanza ahead of time.

Also add some comments justifying why we're inferring whether to prepend
the Tool Kit namespace as the logic is getting increasingly complicated.
All jobs specified in a CircleCI config need to have an execution
environment assigned to it. Let's use the default node executor for our
generated jobs, including a matrix of the node executors if appropriate.
This increases the complexity of the workflow job logic even further so
I've refactored the code significantly as part of this in an effort to
make it more readable.
This means we can reuse the aggregate error formatting instead of
rewriting another version. It also means that the details field of
ToolKitErrors can be preserved.
@ivomurrell ivomurrell force-pushed the generated-job-executors branch from 31ec896 to 93d6d49 Compare January 22, 2025 16:43
Copy link
Contributor

@meel-io meel-io left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pairing on this one. I have a better understanding of how this plugin works now.

The refactors made the code much more readable too. Thanks

// value to if it's from the orb or if it's a custom job that needs to be
// run for multiple Node versions
prefixedName.startsWith('tool-kit/') ||
(runsOnMultipleNodeVersions && customJob && (customJob.splitIntoMatrix ?? true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I was a little confused about this logic.

So a custom job that runs on multiple node versions will split into a matrix unless we opt out in the job definition or the workflow job definition? Opting out only at the workflow level will still set one executor.

Opting out at the job definition level won't set any executors because it should have been added at the job level by generateJob. Is that right?

If that's so, maybe expanding a bit more on why we return none for custom jobs would be useful.

plugins/circleci/src/circleci-config.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants