Skip to content

Commit e8270a9

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 <anas.nashif@intel.com>
1 parent 014a2f3 commit e8270a9

File tree

3 files changed

+270
-61
lines changed

3 files changed

+270
-61
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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: zephyrproject-rtos/action-python-env@ace91a63fd503cd618ff1eb83fbcf302dabd7d44 # main
64+
with:
65+
python-version: 3.12
66+
67+
- name: Run assignment script
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.ZB_PR_ASSIGNER_GITHUB_TOKEN }}
70+
run: |
71+
if [ -f "./pr/manifest_areas.json" ]; then
72+
ARGS="--areas ./pr/manifest_areas.json"
73+
else
74+
ARGS=""
75+
fi
76+
python3 scripts/set_assignees.py -P ${{ env.PR_NUM }} -M MAINTAINERS.yml -v \
77+
--repo ${{ github.event.repository.name }} ${ARGS}

.github/workflows/assigner.yml

Lines changed: 51 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,62 @@ 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: zephyrproject-rtos/action-python-env@ace91a63fd503cd618ff1eb83fbcf302dabd7d44 # main
38+
with:
39+
python-version: 3.12
4040

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

64-
python3 scripts/set_assignees.py $FLAGS

0 commit comments

Comments
 (0)