Skip to content

Commit

Permalink
Allow selectively enabling patch dependency automerge for v0.x depend…
Browse files Browse the repository at this point in the history
…encies

This commit introduces a new cookiecutter argument
`automerge_patch_v0_regexp_allowlist` which can be used to selectively
enable patch automerging for v0.x dependencies.

The template expects that the content of the new argument is a string
which contains zero or more regexp patterns separated by semicolons.

If global automerging of patch updates for v0.x dependencies is
disabled, but `automerge_patch_v0_regexp_allowlist` isn't empty, the
template generates an additional package rule that enables automerge
only for dependencies that are currently v0.x and which match one of the
provided patterns.

This rule is not required and therefore not generated when
`automerge_patch_v0` is enabled. If you want to disable automerging for
some v0.x patch level updates but automerge those patch level updates
for v0.x dependencies by default, you can specify patterns for which no
patch level updates should be merged in cookiecutter argument
`automerge_patch_regexp_blocklist`.
  • Loading branch information
simu committed Jun 7, 2024
1 parent f58f61e commit 4a11211
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"automerge_patch_v0": "n",

"automerge_patch_regexp_blocklist": "",
"automerge_patch_v0_regexp_allowlist": "",

"copyright_holder": "VSHN AG <[email protected]>",
"copyright_year": "1950",
Expand Down
29 changes: 29 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
automerge_patch_v0 = "{{ cookiecutter.automerge_patch_v0 }}" == "y"

automerge_patch_regexp_blocklist = "{{ cookiecutter.automerge_patch_regexp_blocklist }}"
automerge_patch_v0_regexp_allowlist = (
"{{ cookiecutter.automerge_patch_v0_regexp_allowlist }}"
)

if not create_lib:
shutil.rmtree("lib")
Expand Down Expand Up @@ -99,6 +102,32 @@

renovatejson["packageRules"].append(patch_rule)

# If automerging of patch updates for v0.x dependencies is disabled by default, but automerging
# is requested for some v0.x package patterns, we generate an additional package rule that
# enables automerge only for dependencies that are currently v0.x and which match one of the
# provided patterns.
# This rule is not required and therefore not generated when `automerge_patch_v0` is enabled
# globally. If you want to disable automerging for some v0.x patch level updates but merge those
# updates by default, you can specify patterns for which no patch level updates should be merged
# in cookiecutter argument `automerge_patch_regexp_blocklist`.
if not automerge_patch_v0 and len(automerge_patch_v0_regexp_allowlist) > 0:
patterns = automerge_patch_v0_regexp_allowlist.split(";")
patch_v0_rule = {
"matchUpdateTypes": ["patch"],
# only apply for packages whose current version matches `v?0\.`
"matchCurrentVersion": "/^v?0\\./",
"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,
# NOTE: We need to add all the labels we want here, renovate doesn't inherit globally
# specified labels for package rules
"labels": ["dependency", "automerge"],
"matchPackagePatterns": patterns,
}
renovatejson["packageRules"].append(patch_v0_rule)

# NOTE: Later rules in `packageRules` take precedence

with open("renovate.json", "w", encoding="utf-8") as f:
Expand Down

0 comments on commit 4a11211

Please sign in to comment.