Skip to content

Commit 649eb62

Browse files
fabiobaltierikartben
authored andcommitted
ci: pr_metadata_check: convert DNM logic to python
GitHub seems to have issue with workflow state caching that causes the DNM step to not work properly in few cases and not detecting changes in the DNM tag, forcing people to mess with tags or close/opening PRs, which in turns restarts all workflows. Convert the script to Python so that the tag data is guaranteed to be fresh. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 13808ae commit 649eb62

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

.github/workflows/pr_metadata_check.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,23 @@ jobs:
1818
name: Prevent Merging
1919
runs-on: ubuntu-24.04
2020
steps:
21-
- name: Check for label
22-
if: ${{ contains(github.event.*.labels.*.name, 'DNM') ||
23-
contains(github.event.*.labels.*.name, 'DNM (manifest)') ||
24-
contains(github.event.*.labels.*.name, 'TSC') ||
25-
contains(github.event.*.labels.*.name, 'Architecture Review') ||
26-
contains(github.event.*.labels.*.name, 'dev-review') }}
21+
- name: Checkout
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
26+
with:
27+
python-version: 3.12
28+
cache: pip
29+
cache-dependency-path: scripts/requirements-actions.txt
30+
31+
- name: Install Python dependencies
2732
run: |
28-
echo "Pull request is labeled as 'DNM', 'TSC', 'Architecture Review' or 'dev-review'."
29-
echo "This workflow fails so that the pull request cannot be merged."
30-
exit 1
33+
pip install -r scripts/requirements-actions.txt --require-hashes
34+
35+
- name: Run the check script
36+
run: |
37+
./scripts/ci/do_not_merge.py -p "${{ github.event.pull_request.number }}"
3138
3239
empty_pr_description:
3340
if: ${{ github.event.pull_request.body == '' }}

scripts/ci/do_not_merge.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2025 Google LLC
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import argparse
7+
import os
8+
import sys
9+
10+
import github
11+
12+
DNM_LABELS = ["DNM", "DNM (manifest)", "TSC", "Architecture Review", "dev-review"]
13+
14+
15+
def parse_args(argv):
16+
parser = argparse.ArgumentParser(
17+
description=__doc__,
18+
formatter_class=argparse.RawDescriptionHelpFormatter,
19+
allow_abbrev=False,
20+
)
21+
22+
parser.add_argument("-p", "--pull-request", required=True, type=int, help="The PR number")
23+
24+
return parser.parse_args(argv)
25+
26+
27+
def main(argv):
28+
args = parse_args(argv)
29+
30+
token = os.environ.get('GITHUB_TOKEN', None)
31+
gh = github.Github(token)
32+
repo = gh.get_repo("zephyrproject-rtos/zephyr")
33+
pr = repo.get_pull(args.pull_request)
34+
35+
for label in pr.get_labels():
36+
if label.name in DNM_LABELS:
37+
print(f"Pull request is labeled as \"{label.name}\".")
38+
print("This workflow fails so that the pull request cannot be merged.")
39+
sys.exit(1)
40+
41+
42+
if __name__ == "__main__":
43+
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)