Skip to content

Commit 282e326

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 15b52cc commit 282e326

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

cookiecutter/migrate.py

Lines changed: 43 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,46 @@ 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@""0d0d77eac3b54799f31f25a1060ef2c6ebdf9299", # noqa: E501
302+
"frequenz-floss/gh-action-setup-python-with-deps@e4d0b2ef8f5a1612d7827f3abaef17c931d2b946", # noqa: E501
303+
),
304+
]
305+
306+
workflows_dir = Path(".github/workflows")
307+
if not workflows_dir.is_dir():
308+
print(f" Skipped {workflows_dir}: directory not found")
309+
return
310+
311+
for wf in sorted(workflows_dir.iterdir()):
312+
if wf.suffix not in (".yml", ".yaml"):
313+
continue
314+
try:
315+
content = wf.read_text(encoding="utf-8")
316+
except OSError:
317+
continue
318+
319+
new_content = content
320+
for old, new in replacements:
321+
new_content = new_content.replace(old, new)
322+
323+
if new_content != content:
324+
replace_file_atomically(wf, new_content)
325+
print(f" Updated {wf}: normalized GitHub Action hashes")
326+
327+
285328
def migrate_issue_templates() -> None:
286329
"""Update issue template configuration for repository privacy.
287330

0 commit comments

Comments
 (0)