Skip to content

Commit 0ce01a1

Browse files
fabiobaltierinashif
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 944d900 commit 0ce01a1

File tree

2 files changed

+82
-10
lines changed

2 files changed

+82
-10
lines changed
Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
1-
name: Do Not Merge
1+
name: PR Metadata Check
22

33
on:
44
pull_request:
5-
types: [synchronize, opened, reopened, labeled, unlabeled]
5+
types:
6+
- synchronize
7+
- opened
8+
- reopened
9+
- labeled
10+
- unlabeled
11+
- edited
12+
13+
permissions:
14+
contents: read
615

716
jobs:
817
do-not-merge:
9-
if: ${{ contains(github.event.*.labels.*.name, 'DNM') ||
10-
contains(github.event.*.labels.*.name, 'TSC') ||
11-
contains(github.event.*.labels.*.name, 'Architecture Review') ||
12-
contains(github.event.*.labels.*.name, 'dev-review') }}
1318
name: Prevent Merging
14-
runs-on: ubuntu-22.04
19+
runs-on: ubuntu-24.04
20+
steps:
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
32+
run: |
33+
pip install -r scripts/requirements-actions.txt --require-hashes
34+
35+
- name: Run the check script
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: |
39+
./scripts/ci/do_not_merge.py -p "${{ github.event.pull_request.number }}"
40+
41+
empty_pr_description:
42+
if: ${{ github.event.pull_request.body == '' }}
43+
name: PR Description
44+
runs-on: ubuntu-24.04
1545
steps:
16-
- name: Check for label
46+
- name: Check for PR description
1747
run: |
18-
echo "Pull request is labeled as 'DNM', 'TSC', 'Architecture Review' or 'dev-review'."
19-
echo "This workflow fails so that the pull request cannot be merged."
48+
echo "Pull request description cannot be empty."
2049
exit 1

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)