Skip to content

Commit 75090ee

Browse files
authored
ci: Trigger repo-config migration in merge queue (#537)
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.
2 parents f97e24a + 47db92e commit 75090ee

8 files changed

Lines changed: 119 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: 70 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,73 @@ 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 the workflow to\n"
268+
' # be executed to meet the "Required check" condition for merging, but we\n'
269+
" # don't need to actually run the job, having the job present as Skipped is\n"
270+
" # enough.\n"
271+
" if: |\n"
272+
" github.event_name == 'pull_request_target' &&\n"
273+
" contains(github.event.pull_request.title, 'the repo-config group')"
274+
)
275+
276+
updated = content
277+
if old_on in updated:
278+
updated = updated.replace(old_on, new_on, 1)
279+
280+
if old_if in updated:
281+
updated = updated.replace(old_if, new_if, 1)
282+
283+
if updated != content:
284+
replace_file_atomically(filepath, updated)
285+
print(
286+
" Updated .github/workflows/repo-config-migration.yaml: added "
287+
"merge_group trigger"
288+
)
289+
return
290+
291+
if new_on in content and new_if in content:
292+
print(
293+
" Skipped .github/workflows/repo-config-migration.yaml: merge queue "
294+
"trigger already configured"
295+
)
296+
return
297+
298+
manual_step(
299+
"Could not find the expected repo-config migration workflow pattern in "
300+
".github/workflows/repo-config-migration.yaml. If this repository uses "
301+
"that workflow, add the `merge_group` trigger and make the job run only "
302+
"for `pull_request_target` events according to the latest template."
303+
)
304+
305+
236306
def apply_patch(patch_content: str) -> None:
237307
"""Apply a patch using the patch utility."""
238308
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

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

Lines changed: 8 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,13 @@ 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 the workflow to
36+
# be executed to meet the "Required check" condition for merging, but we
37+
# don't need to actually run the job, having the job present as Skipped is
38+
# enough.
39+
if: |
40+
github.event_name == 'pull_request_target' &&
41+
contains(github.event.pull_request.title, 'the repo-config group')
3542
runs-on: ubuntu-24.04
3643
steps:
3744
- name: Generate token

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

Lines changed: 8 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,13 @@ 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 the workflow to
35+
# be executed to meet the "Required check" condition for merging, but we
36+
# don't need to actually run the job, having the job present as Skipped is
37+
# enough.
38+
if: |
39+
github.event_name == 'pull_request_target' &&
40+
contains(github.event.pull_request.title, 'the repo-config group')
3441
runs-on: ubuntu-24.04
3542
steps:
3643
- name: Generate token

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

Lines changed: 8 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,13 @@ 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 the workflow to
35+
# be executed to meet the "Required check" condition for merging, but we
36+
# don't need to actually run the job, having the job present as Skipped is
37+
# enough.
38+
if: |
39+
github.event_name == 'pull_request_target' &&
40+
contains(github.event.pull_request.title, 'the repo-config group')
3441
runs-on: ubuntu-24.04
3542
steps:
3643
- name: Generate token

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

Lines changed: 8 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,13 @@ 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 the workflow to
35+
# be executed to meet the "Required check" condition for merging, but we
36+
# don't need to actually run the job, having the job present as Skipped is
37+
# enough.
38+
if: |
39+
github.event_name == 'pull_request_target' &&
40+
contains(github.event.pull_request.title, 'the repo-config group')
3441
runs-on: ubuntu-24.04
3542
steps:
3643
- name: Generate token

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

Lines changed: 8 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,13 @@ 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 the workflow to
35+
# be executed to meet the "Required check" condition for merging, but we
36+
# don't need to actually run the job, having the job present as Skipped is
37+
# enough.
38+
if: |
39+
github.event_name == 'pull_request_target' &&
40+
contains(github.event.pull_request.title, 'the repo-config group')
3441
runs-on: ubuntu-24.04
3542
steps:
3643
- name: Generate token

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

Lines changed: 8 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,13 @@ 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 the workflow to
35+
# be executed to meet the "Required check" condition for merging, but we
36+
# don't need to actually run the job, having the job present as Skipped is
37+
# enough.
38+
if: |
39+
github.event_name == 'pull_request_target' &&
40+
contains(github.event.pull_request.title, 'the repo-config group')
3441
runs-on: ubuntu-24.04
3542
steps:
3643
- name: Generate token

0 commit comments

Comments
 (0)