Skip to content

Commit b400edd

Browse files
committed
chore(ci): automated chore_release PR cascade
1 parent e08274b commit b400edd

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Chore Release PR Automation
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened]
6+
workflow_dispatch:
7+
inputs:
8+
chore_release_branches:
9+
description: 'Comma-separated list of chore release branches'
10+
required: true
11+
default: 'chore_release-8.5.0,chore_release-pd-8.5.0'
12+
target_branch:
13+
description: 'Target branch for testing'
14+
required: true
15+
default: 'chore_release-8.5.0'
16+
17+
jobs:
18+
handle-chore-release:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.10'
29+
30+
- name: Set variables for branch and target
31+
id: set-vars
32+
run: |
33+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
34+
echo "chore_release_branches=${{ github.event.inputs.chore_release_branches }}" >> $GITHUB_ENV
35+
echo "target_branch=${{ github.event.inputs.target_branch }}" >> $GITHUB_ENV
36+
else
37+
echo "chore_release_branches=${{ secrets.CHORE_RELEASE_BRANCHES }}" >> $GITHUB_ENV
38+
echo "target_branch=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
39+
fi
40+
41+
- name: Determine downstream chore release PRs
42+
id: downstream
43+
run: |
44+
python scripts/chore_release_pr_gen.py \
45+
--branch-list "$chore_release_branches" \
46+
--target-branch "$target_branch" \
47+
--output-file "$GITHUB_ENV"
48+
49+
- name: Display summary of inputs and downstream branches
50+
run: |
51+
# Set variables for display, using dash if empty
52+
chore_release_branches_display="$chore_release_branches"
53+
if [ -z "$chore_release_branches_display" ]; then chore_release_branches_display='-'; fi
54+
target_branch_display="$target_branch"
55+
if [ -z "$target_branch_display" ]; then target_branch_display='-'; fi
56+
downstream_branches_display="$downstream_branches"
57+
if [ -z "$downstream_branches_display" ]; then downstream_branches_display='-'; fi
58+
59+
echo "| Input | Value |" >> $GITHUB_STEP_SUMMARY
60+
echo "|------------------------|--------------------------|" >> $GITHUB_STEP_SUMMARY
61+
echo "| chore_release_branches | $chore_release_branches_display |" >> $GITHUB_STEP_SUMMARY
62+
echo "| target_branch | $target_branch_display |" >> $GITHUB_STEP_SUMMARY
63+
echo "| downstream_branches | $downstream_branches_display |" >> $GITHUB_STEP_SUMMARY
64+
65+
if [ "$downstream_branches_display" = "-" ]; then
66+
echo "\n### No downstream PRs to open." >> $GITHUB_STEP_SUMMARY
67+
else
68+
echo "\n### Downstream PRs should be opened for:" >> $GITHUB_STEP_SUMMARY
69+
echo "\`$downstream_branches_display\`" >> $GITHUB_STEP_SUMMARY
70+
fi

scripts/chore_release_pr_gen.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import argparse
2+
import os
3+
from typing import List
4+
5+
DEFAULT_BRANCH = "edge"
6+
7+
def parse_branch_list(branch_list_str: str) -> List[str]:
8+
return [b.strip() for b in branch_list_str.split(",") if b.strip()]
9+
10+
def get_downstream_branches(branch_list: List[str], target_branch: str) -> List[str]:
11+
try:
12+
idx = branch_list.index(target_branch)
13+
except ValueError:
14+
return []
15+
downstream = branch_list[idx + 1 :]
16+
if target_branch in branch_list:
17+
if DEFAULT_BRANCH in downstream:
18+
downstream = [b for b in downstream if b != DEFAULT_BRANCH]
19+
downstream.append(DEFAULT_BRANCH)
20+
return downstream
21+
22+
def main():
23+
parser = argparse.ArgumentParser()
24+
parser.add_argument("--branch-list", type=str, required=False)
25+
parser.add_argument("--target-branch", type=str, required=False)
26+
parser.add_argument("--output-file", type=str)
27+
args = parser.parse_args()
28+
29+
branch_list_str = args.branch_list or os.environ.get("CHORE_RELEASE_BRANCHES", "")
30+
target_branch = args.target_branch or os.environ.get("PR_TARGET_BRANCH", "")
31+
32+
branch_list = parse_branch_list(branch_list_str)
33+
downstream = get_downstream_branches(branch_list, target_branch)
34+
downstream_str = ",".join(downstream)
35+
36+
if args.output_file:
37+
with open(args.output_file, "a") as f:
38+
f.write(f"downstream_branches={downstream_str}\n")
39+
else:
40+
print(f"::set-output name=downstream_branches::{downstream_str}")
41+
42+
if __name__ == "__main__":
43+
main()

0 commit comments

Comments
 (0)