Skip to content

Commit

Permalink
Move generating patch automerge package rules to post-gen-project hook
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Jun 6, 2024
1 parent 58c9655 commit 3c2281d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
29 changes: 29 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import shutil

Expand All @@ -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")
Expand Down Expand Up @@ -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"))
20 changes: 1 addition & 19 deletions {{ cookiecutter.slug }}/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3c2281d

Please sign in to comment.