Skip to content

Commit dbb0634

Browse files
committed
ci: Trigger repo-config migration in merge queue
Add the `merge_group` trigger to the repo-config migration workflow so it can be required by merge queues without running the migration job there. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent f97e24a commit dbb0634

8 files changed

Lines changed: 98 additions & 6 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ But you might still need to adapt your code:
3636

3737
- Added a migration step for api repositories to fix `mkdocs.yml` when the previous `mkdocstrings-python` v2 migration moved only `paths: ["src"]` under `handlers.python.options` but not `paths: ["py"]`.
3838
- Fixed runners for jobs that require Docker and where wrongly converted to `ubuntu-slim` in v0.15.0, changing them back to `ubuntu-24.04` to avoid Docker-related failures. The template and the migration script were both updated to reflect this change.
39+
- Updated the repo-config migration workflow template and migration script so existing repositories also add the `merge_group` trigger and skip the job unless the event is `pull_request_target`, allowing the workflow to be used as a required merge-queue check.

cookiecutter/migrate.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def main() -> None:
3838
"""Run the migration steps."""
3939
# Add a separation line like this one after each migration step.
4040
print("=" * 72)
41+
print("Fixing repo-config migration merge queue trigger...")
42+
migrate_repo_config_migration_merge_group_trigger()
43+
print("=" * 72)
4144
print("Fixing mkdocstrings-python v2 paths for api repos...")
4245
migrate_api_mkdocs_mkdocstrings_paths()
4346
print("=" * 72)
@@ -233,6 +236,70 @@ def migrate_docker_based_runners() -> None:
233236
)
234237

235238

239+
def migrate_repo_config_migration_merge_group_trigger() -> None:
240+
"""Trigger repo-config migration in the merge queue."""
241+
filepath = Path(".github/workflows/repo-config-migration.yaml")
242+
if not filepath.exists():
243+
manual_step(
244+
"Unable to find .github/workflows/repo-config-migration.yaml; if this "
245+
"project uses the repo-config migration workflow, update it to trigger "
246+
"on `merge_group` and skip the job unless the event is "
247+
"`pull_request_target`."
248+
)
249+
return
250+
251+
content = filepath.read_text(encoding="utf-8")
252+
old_on = (
253+
"on:\n"
254+
" pull_request_target:\n"
255+
" types: [opened, synchronize, reopened, labeled, unlabeled]\n"
256+
)
257+
new_on = (
258+
"on:\n"
259+
" merge_group: # To allow using this as a required check for merging\n"
260+
" pull_request_target:\n"
261+
" types: [opened, synchronize, reopened, labeled, unlabeled]\n"
262+
)
263+
old_if = (
264+
" if: contains(github.event.pull_request.title, 'the repo-config group')"
265+
)
266+
new_if = (
267+
" # Skip if it was triggered by the merge queue, we only need it to be present\n"
268+
" if: |\n"
269+
" github.event_name == 'pull_request_target' &&\n"
270+
" contains(github.event.pull_request.title, 'the repo-config group')"
271+
)
272+
273+
updated = content
274+
if old_on in updated:
275+
updated = updated.replace(old_on, new_on, 1)
276+
277+
if old_if in updated:
278+
updated = updated.replace(old_if, new_if, 1)
279+
280+
if updated != content:
281+
replace_file_atomically(filepath, updated)
282+
print(
283+
" Updated .github/workflows/repo-config-migration.yaml: added "
284+
"merge_group trigger"
285+
)
286+
return
287+
288+
if new_on in content and new_if in content:
289+
print(
290+
" Skipped .github/workflows/repo-config-migration.yaml: merge queue "
291+
"trigger already configured"
292+
)
293+
return
294+
295+
manual_step(
296+
"Could not find the expected repo-config migration workflow pattern in "
297+
".github/workflows/repo-config-migration.yaml. If this repository uses "
298+
"that workflow, add the `merge_group` trigger and make the job run only "
299+
"for `pull_request_target` events according to the latest template."
300+
)
301+
302+
236303
def apply_patch(patch_content: str) -> None:
237304
"""Apply a patch using the patch utility."""
238305
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/repo-config-migration.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
name: Repo Config Migration
2121

2222
on:
23+
merge_group: # To allow using this as a required check for merging
2324
pull_request_target:
2425
types: [opened, synchronize, reopened, labeled, unlabeled]
2526

@@ -31,7 +32,10 @@ permissions:
3132
jobs:
3233
repo-config-migration:
3334
name: Migrate Repo Config
34-
if: contains(github.event.pull_request.title, 'the repo-config group')
35+
# Skip if it was triggered by the merge queue, we only need it to be present
36+
if: |
37+
github.event_name == 'pull_request_target' &&
38+
contains(github.event.pull_request.title, 'the repo-config group')
3539
runs-on: ubuntu-24.04
3640
steps:
3741
- name: Generate token

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/repo-config-migration.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
name: Repo Config Migration
2020

2121
on:
22+
merge_group: # To allow using this as a required check for merging
2223
pull_request_target:
2324
types: [opened, synchronize, reopened, labeled, unlabeled]
2425

@@ -30,7 +31,10 @@ permissions:
3031
jobs:
3132
repo-config-migration:
3233
name: Migrate Repo Config
33-
if: contains(github.event.pull_request.title, 'the repo-config group')
34+
# Skip if it was triggered by the merge queue, we only need it to be present
35+
if: |
36+
github.event_name == 'pull_request_target' &&
37+
contains(github.event.pull_request.title, 'the repo-config group')
3438
runs-on: ubuntu-24.04
3539
steps:
3640
- name: Generate token

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/.github/workflows/repo-config-migration.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
name: Repo Config Migration
2020

2121
on:
22+
merge_group: # To allow using this as a required check for merging
2223
pull_request_target:
2324
types: [opened, synchronize, reopened, labeled, unlabeled]
2425

@@ -30,7 +31,10 @@ permissions:
3031
jobs:
3132
repo-config-migration:
3233
name: Migrate Repo Config
33-
if: contains(github.event.pull_request.title, 'the repo-config group')
34+
# Skip if it was triggered by the merge queue, we only need it to be present
35+
if: |
36+
github.event_name == 'pull_request_target' &&
37+
contains(github.event.pull_request.title, 'the repo-config group')
3438
runs-on: ubuntu-24.04
3539
steps:
3640
- name: Generate token

tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/.github/workflows/repo-config-migration.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
name: Repo Config Migration
2020

2121
on:
22+
merge_group: # To allow using this as a required check for merging
2223
pull_request_target:
2324
types: [opened, synchronize, reopened, labeled, unlabeled]
2425

@@ -30,7 +31,10 @@ permissions:
3031
jobs:
3132
repo-config-migration:
3233
name: Migrate Repo Config
33-
if: contains(github.event.pull_request.title, 'the repo-config group')
34+
# Skip if it was triggered by the merge queue, we only need it to be present
35+
if: |
36+
github.event_name == 'pull_request_target' &&
37+
contains(github.event.pull_request.title, 'the repo-config group')
3438
runs-on: ubuntu-24.04
3539
steps:
3640
- name: Generate token

tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/.github/workflows/repo-config-migration.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
name: Repo Config Migration
2020

2121
on:
22+
merge_group: # To allow using this as a required check for merging
2223
pull_request_target:
2324
types: [opened, synchronize, reopened, labeled, unlabeled]
2425

@@ -30,7 +31,10 @@ permissions:
3031
jobs:
3132
repo-config-migration:
3233
name: Migrate Repo Config
33-
if: contains(github.event.pull_request.title, 'the repo-config group')
34+
# Skip if it was triggered by the merge queue, we only need it to be present
35+
if: |
36+
github.event_name == 'pull_request_target' &&
37+
contains(github.event.pull_request.title, 'the repo-config group')
3438
runs-on: ubuntu-24.04
3539
steps:
3640
- name: Generate token

tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/.github/workflows/repo-config-migration.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
name: Repo Config Migration
2020

2121
on:
22+
merge_group: # To allow using this as a required check for merging
2223
pull_request_target:
2324
types: [opened, synchronize, reopened, labeled, unlabeled]
2425

@@ -30,7 +31,10 @@ permissions:
3031
jobs:
3132
repo-config-migration:
3233
name: Migrate Repo Config
33-
if: contains(github.event.pull_request.title, 'the repo-config group')
34+
# Skip if it was triggered by the merge queue, we only need it to be present
35+
if: |
36+
github.event_name == 'pull_request_target' &&
37+
contains(github.event.pull_request.title, 'the repo-config group')
3438
runs-on: ubuntu-24.04
3539
steps:
3640
- name: Generate token

0 commit comments

Comments
 (0)