Skip to content

Commit ffb8b12

Browse files
committed
Use a random day of the week for Dependabot updates
To avoid dependabot updates flooding users notification with updates to all projects at the same time, we use a random day of the week for running the updates. For this we add a `random_weekday` global variable to the Jinja2 environment that will be available in all templates. The random value is calculated once, so it will be the same each time is used during the same run. When running inside `pytest` we always use Monday to make the tests reproduceable and we also use Monday for this project. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 4ebffa7 commit ffb8b12

File tree

8 files changed

+44
-0
lines changed

8 files changed

+44
-0
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "weekly"
7+
day: "monday"
78
labels:
89
- "part:tooling"
910
- "type:tech-debt"
@@ -34,6 +35,7 @@ updates:
3435
directory: "/"
3536
schedule:
3637
interval: "monthly"
38+
day: "monday"
3739
labels:
3840
- "part:tooling"
3941
- "type:tech-debt"

cookiecutter/local_extensions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"""
99

1010
import json as _json
11+
import os as _os
1112
import pathlib as _pathlib
13+
import random as _random
1214

1315
from jinja2 import Environment as _Environment
1416
from jinja2.ext import Extension as _Extension
@@ -35,6 +37,11 @@ def __init__(self, environment: _Environment):
3537
"""
3638
super().__init__(environment)
3739
self._register_filters()
40+
self.environment.globals.update(
41+
{
42+
"random_weekday": self._get_random_weekday(),
43+
}
44+
)
3845

3946
def parse(self, parser: _Parser) -> _Node | list[_Node]:
4047
"""Parse tags declared by this extension.
@@ -95,6 +102,27 @@ def _get_from_json(self, key: str) -> str:
95102
with open("../cookiecutter.json", encoding="utf8") as cookiecutter_json_file:
96103
return str(_json.load(cookiecutter_json_file)[key])
97104

105+
def _get_random_weekday(self) -> str:
106+
"""Get a random weekday.
107+
108+
Returns:
109+
A random weekday.
110+
"""
111+
# Make sure tests are reproduceable
112+
if _os.environ.get("PYTEST_CURRENT_TEST") is not None:
113+
return "monday"
114+
return _random.choice(
115+
[
116+
"monday",
117+
"tuesday",
118+
"wednesday",
119+
"thursday",
120+
"friday",
121+
"saturday",
122+
"sunday",
123+
]
124+
)
125+
98126
def _as_identifier_filter(self, name: str) -> str:
99127
"""Convert a name to a valid identifier.
100128

cookiecutter/{{cookiecutter.github_repo_name}}/.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "monthly"
7+
day: "{{ random_weekday }}"
78
labels:
89
- "part:tooling"
910
- "type:tech-debt"
@@ -34,6 +35,7 @@ updates:
3435
directory: "/"
3536
schedule:
3637
interval: "monthly"
38+
day: "{{ random_weekday }}"
3739
labels:
3840
- "part:tooling"
3941
- "type:tech-debt"
@@ -52,6 +54,7 @@ updates:
5254
- dependency-name: "submodules/frequenz-api-common"
5355
schedule:
5456
interval: "monthly"
57+
day: "{{ random_weekday }}"
5558
labels:
5659
- "part:tooling"
5760
- "type:tech-debt"

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "monthly"
7+
day: "monday"
78
labels:
89
- "part:tooling"
910
- "type:tech-debt"
@@ -34,6 +35,7 @@ updates:
3435
directory: "/"
3536
schedule:
3637
interval: "monthly"
38+
day: "monday"
3739
labels:
3840
- "part:tooling"
3941
- "type:tech-debt"

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "monthly"
7+
day: "monday"
78
labels:
89
- "part:tooling"
910
- "type:tech-debt"
@@ -34,6 +35,7 @@ updates:
3435
directory: "/"
3536
schedule:
3637
interval: "monthly"
38+
day: "monday"
3739
labels:
3840
- "part:tooling"
3941
- "type:tech-debt"
@@ -51,6 +53,7 @@ updates:
5153
- dependency-name: "submodules/frequenz-api-common"
5254
schedule:
5355
interval: "monthly"
56+
day: "monday"
5457
labels:
5558
- "part:tooling"
5659
- "type:tech-debt"

tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "monthly"
7+
day: "monday"
78
labels:
89
- "part:tooling"
910
- "type:tech-debt"
@@ -34,6 +35,7 @@ updates:
3435
directory: "/"
3536
schedule:
3637
interval: "monthly"
38+
day: "monday"
3739
labels:
3840
- "part:tooling"
3941
- "type:tech-debt"

tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "monthly"
7+
day: "monday"
78
labels:
89
- "part:tooling"
910
- "type:tech-debt"
@@ -34,6 +35,7 @@ updates:
3435
directory: "/"
3536
schedule:
3637
interval: "monthly"
38+
day: "monday"
3739
labels:
3840
- "part:tooling"
3941
- "type:tech-debt"

tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "monthly"
7+
day: "monday"
78
labels:
89
- "part:tooling"
910
- "type:tech-debt"
@@ -34,6 +35,7 @@ updates:
3435
directory: "/"
3536
schedule:
3637
interval: "monthly"
38+
day: "monday"
3739
labels:
3840
- "part:tooling"
3941
- "type:tech-debt"

0 commit comments

Comments
 (0)