|
16 | 16 | with: |
17 | 17 | fetch-depth: 0 |
18 | 18 |
|
| 19 | + # Generate commit history and calculate suggested merge date |
| 20 | + - name: Generate commit history and schedule |
| 21 | + id: generate-commits |
| 22 | + run: | |
| 23 | + # Get the commit history between master and dev |
| 24 | + COMMIT_LIST=$(git log --pretty=format:"* %s (%h) by %an" origin/master..origin/dev) |
| 25 | +
|
| 26 | + # Handle empty commit list (branches are identical) |
| 27 | + if [ -z "$COMMIT_LIST" ]; then |
| 28 | + COMMIT_LIST="No new commits - branches may be identical" |
| 29 | + fi |
| 30 | +
|
| 31 | + # Calculate suggested merge date based on release policy |
| 32 | + # By default, suggesting next Monday as merge date - adjust according to your policy |
| 33 | + MERGE_DATE=$(date -d "next Monday" +"%A, %B %d, %Y") |
| 34 | +
|
| 35 | + # Save commit list to a file (to handle multi-line output) |
| 36 | + echo "$COMMIT_LIST" > commit_list.txt |
| 37 | +
|
| 38 | + # Create a PR body with the commit list and suggested merge date |
| 39 | + echo "PR_BODY<<EOF" >> $GITHUB_ENV |
| 40 | + echo "This is an automated PR to promote changes from \`dev\` to \`master\`." >> $GITHUB_ENV |
| 41 | + echo "" >> $GITHUB_ENV |
| 42 | + echo "## Suggested Merge Schedule" >> $GITHUB_ENV |
| 43 | + echo "According to our release policy, this PR is expected to be merged on: **$MERGE_DATE**" >> $GITHUB_ENV |
| 44 | + echo "" >> $GITHUB_ENV |
| 45 | + echo "## Commits to be merged:" >> $GITHUB_ENV |
| 46 | + echo "\`\`\`" >> $GITHUB_ENV |
| 47 | + cat commit_list.txt >> $GITHUB_ENV |
| 48 | + echo "\`\`\`" >> $GITHUB_ENV |
| 49 | + echo "" >> $GITHUB_ENV |
| 50 | + echo "Please review the changes carefully before merging." >> $GITHUB_ENV |
| 51 | + echo "EOF" >> $GITHUB_ENV |
| 52 | +
|
19 | 53 | # Use a fixed branch name for the PR |
20 | 54 | - name: Update dev-to-master branch |
21 | 55 | run: | |
|
39 | 73 | const { repo, owner } = context.repo; |
40 | 74 | const prBranch = "automated-dev-to-master-branch"; |
41 | 75 | const prTitle = "Promote dev changes to master"; |
42 | | - const prBody = "This is an automated PR to promote changes from `dev` to `master`.\n\nPlease review the changes carefully before merging."; |
| 76 | + const prBody = process.env.PR_BODY; |
43 | 77 |
|
44 | 78 | // Retry helper function |
45 | 79 | async function retryOperation(operation, maxRetries = 3, delay = 5000) { |
|
99 | 133 | console.log(`PR created: ${result.data.html_url}`); |
100 | 134 | } catch (error) { |
101 | 135 | console.log(`All attempts to create PR failed: ${error.message}`); |
102 | | -
|
| 136 | + |
103 | 137 | // As a fallback, output command for manual PR creation |
104 | 138 | console.log(`To create the PR manually, visit: https://github.com/${owner}/${repo}/compare/master...${prBranch}`); |
105 | 139 | throw error; |
|
0 commit comments