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

split ci files #4027

Open
wants to merge 19 commits into
base: andy/fix-precommit-hook
Choose a base branch
from
Open

split ci files #4027

wants to merge 19 commits into from

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Jul 5, 2024

CircleCI doesn't have direct support for splitting a config file into multiple, so this adds support for it a bit more manually:

It adds logic to our pre-commit hook to concatenate files in a configuration folder.
This only runs if files in that folder have changed.

This is the basic file structure:
image

So all of the files in that folder, in order, comprise the config.yml file that looks pretty much identical to the one we had before.

This approach does take two assumptions:

  1. developers will understand that they shouldn't edit the config.yml file directly (there's a warning in the file itself, and we could get fancier and detect this with git I suppose?)
  2. developers will use the pre-commit hook (which... we should in any case, there's a reason we have it)

@aboedo aboedo added the ci label Jul 5, 2024
@aboedo aboedo requested a review from joshdholtz July 5, 2024 21:34
@aboedo aboedo self-assigned this Jul 5, 2024
@aboedo aboedo changed the title Andy/split ci files split ci files Jul 5, 2024
@aboedo
Copy link
Member Author

aboedo commented Jul 5, 2024

@joshdholtz tagged you for early thoughts since you had had a stab at this in the past

Comment on lines 1448 to 1450



Copy link
Member Author

Choose a reason for hiding this comment

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

lol guess I had a ton of line breaks at the end of the other files.

But the idea is for this one to get generated from the others

@@ -0,0 +1,1194 @@
orbs:
Copy link
Member Author

Choose a reason for hiding this comment

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

this is an exact copy of the other config file minus the workflows part

@@ -0,0 +1,252 @@
workflows:
Copy link
Member Author

Choose a reason for hiding this comment

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

and here is just the workflows part

@@ -82,3 +82,34 @@ if [ $SHOULD_FAIL_PRECOMMIT -ne 0 ]; then
else
verify_no_included_apikeys
fi


# Function to concatenate CircleCI configuration files
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm generally allergic to bash, I might study porting all the logic into ruby at some point

@@ -0,0 +1,56 @@
aliases:
Copy link
Member Author

Choose a reason for hiding this comment

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

this is just cut/paste from what used to be only in config.yml

Comment on lines +85 to +88

# CircleCI doesn't let us split a config file into multiple, so we have a pre-commit hook that does it for us
# so that the file doesn't become unmanageable.
concatenate_circleci_configs() {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the only file with real changes aside from the original config.yml changes, so those are the only two ones worth really reviewing

@aboedo aboedo marked this pull request as ready for review July 5, 2024 22:02
@aboedo aboedo requested a review from a team July 5, 2024 22:02
@aboedo
Copy link
Member Author

aboedo commented Jul 5, 2024

the diff makes this look big but there really are only 2 small files worth reviewing in here, the rest are mostly ignorable in they're cut / paste from the original config.yml file

@@ -1,11 +1,20 @@
# This file is generated automatically by concatenating the files in the .circleci/configuration/ directory.
# DO NOT EDIT this file directly. Instead, edit the files in the .circleci/configuration/ directory and rely on the pre-commit hook to update this file.
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if we should add a test job to make sure this file matches the output from the individual configuration files, to make sure it's not outdated/it's changed accidentally.


# CircleCI doesn't let us split a config file into multiple, so we have a pre-commit hook that does it for us
# so that the file doesn't become unmanageable.
concatenate_circleci_configs() {
Copy link
Contributor

@tonidero tonidero Jul 8, 2024

Choose a reason for hiding this comment

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

Might be worth extracting this to a separate script and just call it from the pre-commit.sh? Specially if we follow my other suggestion about adding a test job to make sure the combined file matches the individual files.

Copy link
Member

@JayShortway JayShortway left a comment

Choose a reason for hiding this comment

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

Major improvement! Had 1 suggestion.


# CircleCI doesn't let us split a config file into multiple, so we have a pre-commit hook that does it for us
# so that the file doesn't become unmanageable.
concatenate_circleci_configs() {
Copy link
Member

@JayShortway JayShortway Jul 8, 2024

Choose a reason for hiding this comment

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

Could we use a CircleCI setup job to generate the final CircleCI config file instead? This would avoid the need for a pre-commit hook, and keep the CircleCI-related logic self contained (and running on CI instead of locally, the concatenation that is).

Here's an example for exactly our use case.

In this example, a script is used to generate a YAML configuration file. The continuation orb is used to continue the pipeline using the generated configuration.

@vegaro vegaro added pr:other and removed pr:ci labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants