Skip to content

Commit 2d68af4

Browse files
committed
Add migration step to normalize hashes
Add a migration script step to update the GitHub Action hashes for `gh-action-setup-git` and `gh-action-setup-python-with-deps` to point to the actual commit object instead of the annotated tag object. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent f735dc8 commit 2d68af4

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

cookiecutter/migrate.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def main() -> None:
5454
print("Updating auxiliary GitHub workflows...")
5555
migrate_auxiliary_workflows()
5656
print("=" * 72)
57+
print("Normalizing GitHub Action hashes...")
58+
migrate_gh_actions_hashes()
59+
print("=" * 72)
5760
print("Updating issue template configuration...")
5861
migrate_issue_templates()
5962
print("=" * 72)
@@ -282,6 +285,47 @@ def migrate_auxiliary_workflows() -> None:
282285
)
283286

284287

288+
def migrate_gh_actions_hashes() -> None:
289+
"""Update GitHub Action hashes to point to the actual commit object.
290+
291+
The hashes we were using are the annotated git tag object, but
292+
Dependabot likes to have the pins to the actual commit object the
293+
tag points to, not the tag itself.
294+
"""
295+
replacements = [
296+
(
297+
"frequenz-floss/gh-action-setup-git@16952aac3ccc01d27412fe0dea3ea946530dcace",
298+
"frequenz-floss/gh-action-setup-git@f9d86a01228ee1cadaac5224d4d7626f1eb23f90",
299+
),
300+
(
301+
"frequenz-floss/gh-action-setup-python-with-deps@"
302+
"0d0d77eac3b54799f31f25a1060ef2c6ebdf9299", # noqa: E501
303+
"frequenz-floss/gh-action-setup-python-with-deps@e4d0b2ef8f5a1612d7827f3abaef17c931d2b946", # noqa: E501
304+
),
305+
]
306+
307+
workflows_dir = Path(".github/workflows")
308+
if not workflows_dir.is_dir():
309+
print(f" Skipped {workflows_dir}: directory not found")
310+
return
311+
312+
for wf in sorted(workflows_dir.iterdir()):
313+
if wf.suffix not in (".yml", ".yaml"):
314+
continue
315+
try:
316+
content = wf.read_text(encoding="utf-8")
317+
except OSError:
318+
continue
319+
320+
new_content = content
321+
for old, new in replacements:
322+
new_content = new_content.replace(old, new)
323+
324+
if new_content != content:
325+
replace_file_atomically(wf, new_content)
326+
print(f" Updated {wf}: normalized GitHub Action hashes")
327+
328+
285329
def migrate_issue_templates() -> None:
286330
"""Update issue template configuration for repository privacy.
287331

0 commit comments

Comments
 (0)