-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Build: Add BuildConfig model for deduplicated config storage #12646
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
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/simplify-config-attribute-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+223
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
036a60e
Initial plan
Copilot 054385c
Add BuildConfig model and readthedocs_yaml_data field to Build model
Copilot e1a19aa
Address code review feedback: fix imports and BuildConfig consistency
Copilot f44e7f4
Address PR feedback: always populate readthedocs_yaml_data and remove…
Copilot bfd043d
Run pre-commit on files
humitos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
readthedocs/builds/migrations/0066_add_buildconfig_model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Generated by Django 5.2.9 on 2025-12-09 17:33 | ||
|
|
||
| import django.db.models.deletion | ||
| import django_extensions.db.fields | ||
| from django.db import migrations | ||
| from django.db import models | ||
| from django_safemigrate import Safe | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| safe = Safe.before_deploy() | ||
|
|
||
| dependencies = [ | ||
| ("builds", "0065_task_executed_at"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="BuildConfig", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
| ), | ||
| ), | ||
| ( | ||
| "created", | ||
| django_extensions.db.fields.CreationDateTimeField( | ||
| auto_now_add=True, verbose_name="created" | ||
| ), | ||
| ), | ||
| ( | ||
| "modified", | ||
| django_extensions.db.fields.ModificationDateTimeField( | ||
| auto_now=True, verbose_name="modified" | ||
| ), | ||
| ), | ||
| ( | ||
| "data", | ||
| models.JSONField( | ||
| help_text="The rendered YAML configuration used in the build", | ||
| unique=True, | ||
| verbose_name="Configuration data", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "verbose_name": "Build configuration", | ||
| "verbose_name_plural": "Build configurations", | ||
| }, | ||
| ), | ||
| migrations.AddField( | ||
| model_name="build", | ||
| name="readthedocs_yaml_data", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| help_text="The rendered YAML configuration used in the build", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="builds", | ||
| to="builds.buildconfig", | ||
| verbose_name="Build configuration data", | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """Tests for BuildConfig model and Build.readthedocs_yaml_data field.""" | ||
|
|
||
| import django_dynamic_fixture as fixture | ||
| import pytest | ||
|
|
||
| from readthedocs.builds.models import Build | ||
| from readthedocs.builds.models import BuildConfig | ||
| from readthedocs.builds.models import Version | ||
| from readthedocs.projects.models import Project | ||
|
|
||
|
|
||
| @pytest.mark.django_db | ||
| class TestBuildReadthedocsYamlData: | ||
| """Test Build.readthedocs_yaml_data field and integration.""" | ||
|
|
||
| def test_build_saves_with_config_creates_buildconfig(self): | ||
| """Test that saving a Build with config creates BuildConfig.""" | ||
| project = fixture.get(Project) | ||
| config_data = {"build": {"os": "ubuntu-22.04"}, "python": {"version": "3.11"}} | ||
|
|
||
| build = fixture.get(Build, project=project) | ||
| build.config = config_data | ||
| build.save() | ||
|
|
||
| # Check that both old and new fields are populated | ||
| assert build._config == config_data | ||
| assert build.readthedocs_yaml_data.data == config_data | ||
|
|
||
| def test_build_with_same_config_reuses_buildconfig(self): | ||
| """Test that builds with same config reuse the same BuildConfig.""" | ||
| project = fixture.get(Project) | ||
| config_data = {"build": {"os": "ubuntu-22.04"}, "python": {"version": "3.11"}} | ||
|
|
||
| # Create first build | ||
| build1 = fixture.get(Build, project=project) | ||
| build1.config = config_data | ||
| build1.save() | ||
|
|
||
| # Create second build with same config | ||
| build2 = fixture.get(Build, project=project) | ||
| build2.config = config_data | ||
| build2.save() | ||
|
|
||
| # Both should reference the same BuildConfig | ||
| assert build1.readthedocs_yaml_data.pk == build2.readthedocs_yaml_data.pk | ||
| assert BuildConfig.objects.count() == 1 | ||
|
|
||
| def test_build_with_different_config_creates_new_buildconfig(self): | ||
| """Test that builds with different configs create separate BuildConfigs.""" | ||
| project = fixture.get(Project) | ||
| config_data1 = {"build": {"os": "ubuntu-22.04"}, "python": {"version": "3.11"}} | ||
| config_data2 = {"build": {"os": "ubuntu-20.04"}, "python": {"version": "3.10"}} | ||
|
|
||
| # Create first build | ||
| build1 = fixture.get(Build, project=project) | ||
| build1.config = config_data1 | ||
| build1.save() | ||
|
|
||
| # Create second build with different config | ||
| build2 = fixture.get(Build, project=project) | ||
| build2.config = config_data2 | ||
| build2.save() | ||
|
|
||
| # Should have different BuildConfigs | ||
| assert build1.readthedocs_yaml_data.pk != build2.readthedocs_yaml_data.pk | ||
| assert BuildConfig.objects.count() == 2 | ||
|
|
||
| def test_build_without_config_does_not_create_buildconfig(self): | ||
| """Test that a Build without config doesn't create a BuildConfig.""" | ||
| project = fixture.get(Project) | ||
| build = fixture.get(Build, project=project) | ||
|
|
||
| # Build has no config set | ||
| build.save() | ||
|
|
||
| assert build._config is None | ||
| assert build.readthedocs_yaml_data is None | ||
| assert BuildConfig.objects.count() == 0 | ||
|
|
||
| def test_build_with_config_reference_uses_same_buildconfig(self): | ||
| """Test that a Build with config reference (old style) reuses the same BuildConfig.""" | ||
| project = fixture.get(Project) | ||
| version = fixture.get(Version, project=project) | ||
| config_data = {"build": {"os": "ubuntu-22.04"}} | ||
|
|
||
| # Create a build with actual config | ||
| build1 = fixture.get(Build, project=project, version=version) | ||
| build1.config = config_data | ||
| build1.save() | ||
|
|
||
| # Create a build with same config on the same version | ||
| # (which will use the reference style in _config) | ||
| build2 = fixture.get(Build, project=project, version=version) | ||
| build2.config = config_data | ||
| build2.save() | ||
|
|
||
| # build2 should have a reference in _config, not actual data | ||
| assert Build.CONFIG_KEY in build2._config | ||
| # Both builds should have the same BuildConfig | ||
| assert build1.readthedocs_yaml_data is not None | ||
| assert build2.readthedocs_yaml_data is not None | ||
| assert build1.readthedocs_yaml_data.pk == build2.readthedocs_yaml_data.pk | ||
| # There should only be one BuildConfig created | ||
| assert BuildConfig.objects.count() == 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we OK with this name? Other alternatives are:
readthedocs_yaml(no_dataat the end)yaml_configconfig_yamlconfig_filecc @ericholscher what do you think?