diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 4d1ccd8..94f45a3 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,3 +1,4 @@ +import json import os import shutil @@ -7,6 +8,8 @@ create_lib = "{{ cookiecutter.add_lib }}" == "y" add_golden = "{{ cookiecutter.add_golden }}" == "y" +automerge_patch = "{{ cookiecutter.automerge_patch }}" == "y" +automerge_patch_v0 = "{{ cookiecutter.automerge_patch_v0 }}" == "y" if not create_lib: shutil.rmtree("lib") @@ -35,5 +38,31 @@ if not add_golden: shutil.rmtree("tests/golden") +with open("renovate.json", "r", encoding="utf-8") as f: + renovatejson = json.load(f) + +# We always add an empty package rules list +renovatejson["packageRules"] = [] + +if automerge_patch: + # automerge patch PRs + patch_rule = { + "matchUpdateTypes": ["patch"], + "automerge": True, + # NOTE: We can't use Platform Automerge because the repositories are configured manually, + # so we can't be sure the "require status checks" option is always enabled, and without + # that, platformAutomerge does not wait for tests to pass. + "platformAutomerge": False, + labels: ["dependency", "automerge"], + } + if not automerge_patch_v0: + # negative match: do not match versions that match regex `^v?0\.` + patch_rule["matchCurrentVersion"] = "!/^v?0\\./" + + renovatejson["packageRules"].append(patchRule) + +with open("renovate.json", "w", encoding="utf-8") as f: + json.dump(renovatejson, f, indent=2) + if Path(".sync.yml").is_file(): os.unlink(Path(".sync.yml")) diff --git a/{{ cookiecutter.slug }}/renovate.json b/{{ cookiecutter.slug }}/renovate.json index 04905bc..f435d02 100644 --- a/{{ cookiecutter.slug }}/renovate.json +++ b/{{ cookiecutter.slug }}/renovate.json @@ -24,23 +24,5 @@ "labels": [ "dependency" ], - "separateMinorPatch": true, - "packageRules": [ - {%- if cookiecutter.automerge_patch == "y" %} - { - "matchUpdateTypes": ["patch"], - {%- if cookiecutter.automerge_patch_v0 != "y" %} - "matchCurrentVersion": "!/^v?0\\./",{# negative match: do not match versions that match regex `^v?0\.` #} - {%- endif %} - "automerge": true, - {#- We can't use Platform Automerge because the repositories are configured manually, so we can't be sure the "require status checks" option is always enabled, and without that, platformAutomerge does not wait for tests to pass. #} - "platformAutomerge": false, - "labels": [ - "dependency", - "automerge" - ] - } - {%- endif %} - {#- re: SYN-785 - Later rules take precedence, so add more specific package rules below. #} - ] + "separateMinorPatch": true }