1+ name : ' Update Release PR'
2+
3+ on :
4+ pull_request :
5+ branches :
6+ - master
7+
8+ jobs :
9+ update-pr :
10+ runs-on : ubuntu-latest
11+ steps :
12+ - uses : actions/checkout@v4
13+ with :
14+ fetch-depth : 0
15+ ref : ${{ github.event.pull_request.head.ref }}
16+
17+ - name : Check if branch is release branch and add label if needed
18+ uses : actions/github-script@v7
19+ id : check_branch
20+ with :
21+ github-token : ${{ secrets.GITHUB_TOKEN }}
22+ script : |
23+ const { issue: { number: issueNumber }, repo: { owner, repo } } = context;
24+ const branchName = '${{ github.event.pull_request.head.ref }}';
25+
26+ console.log(`Branch name: ${branchName}`);
27+
28+ // Check if branch follows 'release/xxx' pattern
29+ const isReleaseBranch = branchName.startsWith('release/');
30+
31+ if (isReleaseBranch) {
32+ console.log('This is a release branch');
33+
34+ // Get current labels
35+ const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
36+ owner,
37+ repo,
38+ issue_number: issueNumber
39+ });
40+
41+ // Check if 'release' label is already applied
42+ const hasReleaseLabel = currentLabels.some(label => label.name === 'release');
43+
44+ if (!hasReleaseLabel) {
45+ console.log('Adding release label');
46+ await github.rest.issues.addLabels({
47+ owner,
48+ repo,
49+ issue_number: issueNumber,
50+ labels: ['release']
51+ });
52+ } else {
53+ console.log('Release label already exists');
54+ }
55+
56+ return true;
57+ } else {
58+ console.log('Not a release branch');
59+ return false;
60+ }
61+
62+ - name : Fetch base branch
63+ if : contains(github.event.pull_request.labels.*.name, 'release') || steps.check_branch.outputs.result == 'true'
64+ run : |
65+ git fetch origin ${{ github.event.pull_request.base.ref }}
66+
67+ - name : Generate PR content
68+ if : contains(github.event.pull_request.labels.*.name, 'release') || steps.check_branch.outputs.result == 'true'
69+ id : generate_content
70+ run : |
71+ # Get the target branch of the PR
72+ TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
73+
74+ # Get commits between the target branch and the PR branch with simplified formatting
75+ # Format: "* feat: Feature description"
76+ COMMITS=$(git log --pretty=format:"* %s" origin/$TARGET_BRANCH..HEAD | grep -E '^\* (refactor|feat|fix)' || echo "No matching commits found")
77+
78+ # Create PR body content with just the commits
79+ PR_BODY="## Release Changes\n\n"
80+ PR_BODY="${PR_BODY}${COMMITS}"
81+
82+ # Save to file to maintain formatting
83+ echo -e "$PR_BODY" > pr_body.txt
84+
85+ # Use delimiter for multiline output
86+ echo "pr_body<<EOF" >> $GITHUB_OUTPUT
87+ cat pr_body.txt >> $GITHUB_OUTPUT
88+ echo "EOF" >> $GITHUB_OUTPUT
89+
90+ - name : Update Pull Request
91+ if : contains(github.event.pull_request.labels.*.name, 'release') || steps.check_branch.outputs.result == 'true'
92+ uses : actions/github-script@v7
93+ with :
94+ github-token : ${{ secrets.GITHUB_TOKEN }}
95+ script : |
96+ const { issue: { number: issueNumber }, repo: { owner, repo } } = context;
97+
98+ const prBody = `${{ steps.generate_content.outputs.pr_body }}`;
99+
100+ github.rest.issues.update({
101+ owner,
102+ repo,
103+ issue_number: issueNumber,
104+ body: prBody
105+ });
0 commit comments