Skip to content

Commit db03d8d

Browse files
committed
scripts/set_assignees.py: set assignee on manifest changes
Parse manifest for changes and set assignees for any manifest entries that has changed. Other changes: - Do not assign to meta area when additional areas are being changed - Cleanup of unused code - Comment where comments are needed. Signed-off-by: Anas Nashif <[email protected]>
1 parent 1baf81c commit db03d8d

File tree

3 files changed

+282
-61
lines changed

3 files changed

+282
-61
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Pull Request Assigner Completion Workflow
2+
3+
# read-write repo token
4+
# access to secrets
5+
on:
6+
workflow_run:
7+
workflows: ["Pull Request Assigner"]
8+
types:
9+
- completed
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
assignment:
16+
name: Pull Request Assignment
17+
runs-on: ubuntu-24.04
18+
if: >
19+
github.event.workflow_run.event == 'pull_request' &&
20+
github.event.workflow_run.conclusion == 'success'
21+
22+
steps:
23+
- name: Check out source code
24+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
25+
with:
26+
fetch-depth: 0
27+
persist-credentials: false
28+
- name: Download artifacts
29+
id: download-artifacts
30+
uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11
31+
with:
32+
workflow: assigner.yml
33+
run_id: ${{ github.event.workflow_run.id }}
34+
if_no_artifact_found: ignore
35+
36+
- name: Load PR number
37+
if: steps.download-artifacts.outputs.found_artifact == 'true'
38+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
39+
with:
40+
script: |
41+
let fs = require("fs");
42+
let pr_number = Number(fs.readFileSync("./pr/NR"));
43+
core.exportVariable("PR_NUM", pr_number);
44+
45+
- name: Check PR number
46+
if: steps.download-artifacts.outputs.found_artifact == 'true'
47+
id: check-pr
48+
uses: carpentries/actions/check-valid-pr@2e20fd5ee53b691e27455ce7ca3b16ea885140e8 # v0.15.0
49+
with:
50+
pr: ${{ env.PR_NUM }}
51+
sha: ${{ github.event.workflow_run.head_sha }}
52+
53+
- name: Validate PR number
54+
if: |
55+
steps.download-artifacts.outputs.found_artifact == 'true' &&
56+
steps.check-pr.outputs.VALID != 'true'
57+
run: |
58+
echo "ABORT: PR number validation failed!"
59+
exit 1
60+
61+
62+
- name: Set up Python
63+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
64+
with:
65+
python-version: 3.12
66+
cache: pip
67+
cache-dependency-path: scripts/requirements-actions.txt
68+
69+
- name: Install Python packages
70+
run: |
71+
pip install -r scripts/requirements-actions.txt --require-hashes
72+
73+
- name: Run assignment script
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.ZB_PR_ASSIGNER_GITHUB_TOKEN }}
76+
run: |
77+
if [ -f "./pr/manifest_areas.json" ]; then
78+
ARGS="--areas ./pr/manifest_areas.json"
79+
else
80+
ARGS=""
81+
fi
82+
python3 scripts/set_assignees.py -P ${{ env.PR_NUM }} -M MAINTAINERS.yml -v \
83+
--repo ${{ github.event.repository.name }} ${ARGS}

.github/workflows/assigner.yml

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Pull Request Assigner
22

33
on:
4-
pull_request_target:
4+
pull_request:
55
types:
66
- opened
77
- synchronize
@@ -24,41 +24,68 @@ jobs:
2424
if: github.event.pull_request.draft == false
2525
runs-on: ubuntu-24.04
2626
permissions:
27-
pull-requests: write # to add assignees to pull requests
2827
issues: write # to add assignees to issues
2928

3029
steps:
31-
- name: Check out source code
32-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
30+
- name: Check out source code
31+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32+
with:
33+
fetch-depth: 0
34+
persist-credentials: false
3335

34-
- name: Set up Python
35-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
36-
with:
37-
python-version: 3.12
38-
cache: pip
39-
cache-dependency-path: scripts/requirements-actions.txt
36+
- name: Set up Python
37+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
38+
with:
39+
python-version: 3.12
40+
cache: pip
41+
cache-dependency-path: scripts/requirements-actions.txt
4042

41-
- name: Install Python packages
42-
run: |
43-
pip install -r scripts/requirements-actions.txt --require-hashes
43+
- name: Install Python packages
44+
run: |
45+
pip install -r scripts/requirements-actions.txt --require-hashes
4446
45-
- name: Run assignment script
46-
env:
47-
GITHUB_TOKEN: ${{ secrets.ZB_PR_ASSIGNER_GITHUB_TOKEN }}
48-
run: |
49-
FLAGS="-v"
50-
FLAGS+=" -o ${{ github.event.repository.owner.login }}"
51-
FLAGS+=" -r ${{ github.event.repository.name }}"
52-
FLAGS+=" -M MAINTAINERS.yml"
53-
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
54-
FLAGS+=" -P ${{ github.event.pull_request.number }}"
55-
elif [ "${{ github.event_name }}" = "issues" ]; then
47+
- name: west setup
48+
if: >
49+
github.event_name == 'pull_request'
50+
run: |
51+
git config --global user.email "[email protected]"
52+
git config --global user.name "Your Name"
53+
west init -l . || true
54+
mkdir -p ./pr
55+
56+
- name: Run assignment script
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
run: |
60+
FLAGS="-v"
61+
FLAGS+=" -o ${{ github.event.repository.owner.login }}"
62+
FLAGS+=" -r ${{ github.event.repository.name }}"
63+
FLAGS+=" -M MAINTAINERS.yml"
64+
if [ "${{ github.event_name }}" = "pull_request" ]; then
65+
FLAGS+=" -P ${{ github.event.pull_request.number }} --manifest -c origin/${{ github.base_ref }}.."
66+
python3 scripts/set_assignees.py $FLAGS
67+
cp -f manifest_areas.json ./pr/
68+
elif [ "${{ github.event_name }}" = "issues" ]; then
5669
FLAGS+=" -I ${{ github.event.issue.number }}"
57-
elif [ "${{ github.event_name }}" = "schedule" ]; then
70+
python3 scripts/set_assignees.py $FLAGS
71+
elif [ "${{ github.event_name }}" = "schedule" ]; then
5872
FLAGS+=" --modules"
59-
else
60-
echo "Unknown event: ${{ github.event_name }}"
61-
exit 1
62-
fi
73+
python3 scripts/set_assignees.py $FLAGS
74+
else
75+
echo "Unknown event: ${{ github.event_name }}"
76+
exit 1
77+
fi
78+
79+
80+
- name: Save PR number
81+
if: >
82+
github.event_name == 'pull_request'
83+
run: |
84+
echo ${{ github.event.number }} > ./pr/NR
85+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
86+
if: >
87+
github.event_name == 'pull_request'
88+
with:
89+
name: pr
90+
path: pr/
6391

64-
python3 scripts/set_assignees.py $FLAGS

0 commit comments

Comments
 (0)