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

Feature/release process automation auto publish installer #2822

Draft
wants to merge 4 commits into
base: feature/release-process-automation
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ def nl_separated_bytes_list(val: str) -> List[bytes]:
}
RQ_EXCEPTION_HANDLERS = ["metaci.build.exceptions.maybe_requeue_job"]
CRON_JOBS = {
"execute_active_release_cohorts": {
"func": "metaci.release.tasks.execute_active_release_cohorts_job",
"cron_string": "* * * * *",
},
"autoscale": {
"func": "metaci.build.autoscaling.autoscale",
"cron_string": "* * * * *",
Expand Down
14 changes: 14 additions & 0 deletions metaci/build/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def get_for_user_or_404(self, user, query, perms=None):


class Build(models.Model):
FAILED_STATUSES = [BUILD_STATUSES.error, BUILD_STATUSES.fail]
COMPLETED_STATUSES = [BUILD_STATUSES.success, *FAILED_STATUSES]

repo = models.ForeignKey(
"repository.Repository", related_name="builds", on_delete=models.CASCADE
)
Expand Down Expand Up @@ -728,6 +731,17 @@ def _get_flow_options(self) -> dict:
if push_time:
task_options["start_time"] = push_time.isoformat()

if (
self.build.plan.role == ("publish_installer")
and self.build.release
):
try:
publish_date = self.build.release.production_push_date.isoformat()
except AttributeError:
raise
else:
options["publish_date"] = publish_date

return options

def set_commit_status(self):
Expand Down
36 changes: 35 additions & 1 deletion metaci/build/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,48 @@ def test_get_flow_options__push_production(self):
build_flow.build.release = Release(
repo=build_flow.build.repo,
change_case_template=change_case_template,
version_number="1.0",
)
build_flow.build.release.version_number = "1.0"
build_flow.build.release.save()
options = build_flow._get_flow_options()
assert options["push_all"]["version"] == "1.0"
expected = f"{datetime.date.today().isoformat()}T21:00:00+00:00"
assert options["push_all"]["start_time"] == expected

def test_get_flow_options__publish_installer(self):
build_flow = BuildFlowFactory()
build_flow.build.plan = PlanFactory(
role="publish_installer", change_traffic_control=True
)
build_flow.build.plan.save()
build_flow.build.repo = RepositoryFactory(
default_implementation_steps=[
{
"role": "publish_installer",
"duration": 10,
"push_time": 21,
"start_time": 8,
"start_date_offset": 0,
},
],
)
build_flow.build.repo.save()
planrepo = PlanRepositoryFactory(
plan=build_flow.build.plan, repo=build_flow.build.repo
)
planrepo.save()
change_case_template = ChangeCaseTemplate()
change_case_template.save()
publish_date = datetime.date.today() + datetime.timedelta(days=6)
build_flow.build.release = Release(
repo=build_flow.build.repo,
change_case_template=change_case_template,
production_push_date=publish_date,
version_number="1.0",
)
options = build_flow._get_flow_options()
assert options["publish_date"] == publish_date.isoformat()


def detach_logger(model):
for handler in model.logger.handlers:
Expand Down
18 changes: 18 additions & 0 deletions metaci/plan/migrations/0041_auto_20211123_2247.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.13 on 2021-11-23 22:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('plan', '0040_plan_commit_status_regex'),
]

operations = [
migrations.AlterField(
model_name='plan',
name='role',
field=models.CharField(choices=[('beta_release', 'Beta Release'), ('beta_test', 'Beta Test'), ('deploy', 'Deployment'), ('feature', 'Feature Test'), ('feature_robot', 'Feature Test Robot'), ('publish_installer', 'Publish Installer'), ('other', 'Other'), ('push_sandbox', 'Push Sandbox'), ('push_production', 'Push Production'), ('qa', 'QA Org'), ('release_deploy', 'Release Deploy'), ('release', 'Release'), ('release_test', 'Release Test'), ('scratch', 'Scratch Org')], max_length=17),
),
]
14 changes: 14 additions & 0 deletions metaci/plan/migrations/0043_merge_20211130_2313.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.1.13 on 2021-11-30 23:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('plan', '0042_auto_20211117_0113'),
('plan', '0041_auto_20211123_2247'),
]

operations = [
]
3 changes: 2 additions & 1 deletion metaci/plan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
("deploy", "Deployment"),
("feature", "Feature Test"),
("feature_robot", "Feature Test Robot"),
("publish_installer", "Publish Installer"),
("other", "Other"),
("push_sandbox", "Push Sandbox"),
("push_production", "Push Production"),
Expand Down Expand Up @@ -83,7 +84,7 @@ class Plan(models.Model):
through_fields=("plan", "repo"),
)
trigger = models.CharField(max_length=8, choices=TRIGGER_TYPES)
role = models.CharField(max_length=16, choices=BUILD_ROLES)
role = models.CharField(max_length=17, choices=BUILD_ROLES)
queue = models.CharField(max_length=16, choices=QUEUES, default="default")
regex = models.CharField(max_length=255, null=True, blank=True)
commit_status_regex = models.CharField(
Expand Down
23 changes: 23 additions & 0 deletions metaci/release/migrations/0026_auto_20211123_1841.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.1.13 on 2021-11-23 18:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('release', '0025_auto_20211117_0126'),
]

operations = [
migrations.AddField(
model_name='releasecohort',
name='dependency_graph',
field=models.JSONField(blank=True, null=True),
),
migrations.AddField(
model_name='releasecohort',
name='error_message',
field=models.TextField(blank=True, null=True),
),
]
4 changes: 4 additions & 0 deletions metaci/release/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ReleaseCohort(models.Model):
)
merge_freeze_start = models.DateTimeField(_("Merge Freeze Start Time"))
merge_freeze_end = models.DateTimeField(_("Merge Freeze End Time"))
error_message = models.TextField(null=True, blank=True)
dependency_graph = models.JSONField(null=True, blank=True)

def __str__(self):
return self.name
Expand Down Expand Up @@ -147,6 +149,8 @@ class Release(StatusModel):
("waiting", _("Waiting")),
("blocked", _("Blocked")),
)
FAILED_STATUSES = [STATUS.failed]
COMPLETED_STATUSES = [STATUS.completed, *FAILED_STATUSES]
created = AutoCreatedField(_("created"))
modified = AutoLastModifiedField(_("modified"))
repo = models.ForeignKey(
Expand Down
Loading