|
1 | | -name: Prepare Release PR |
| 1 | +name: Create PR from master to main |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: |
5 | 4 | push: |
6 | 5 | branches: |
7 | 6 | - master |
8 | 7 |
|
9 | | -# Add this permissions block |
10 | | -permissions: |
11 | | - contents: write |
12 | | - pull-requests: write |
13 | | - |
14 | 8 | jobs: |
15 | | - create_release_pr: |
| 9 | + create-pull-request: |
16 | 10 | runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
17 | 14 | steps: |
18 | | - - uses: actions/checkout@v4 |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v3 |
19 | 17 | with: |
20 | 18 | fetch-depth: 0 |
21 | | - # Add this line to use the token for authentication |
22 | | - token: ${{ secrets.GITHUB_TOKEN }} |
23 | | - - run: | |
24 | | - git config user.name "GitHub Actions" |
25 | | - git config user.email "actions@github.com" |
26 | | - git checkout -b release-main |
27 | | - git push origin release-main --force |
28 | | - - uses: peter-evans/create-pull-request@v5 |
29 | | - with: |
30 | | - base: main |
31 | | - title: "Automated Release PR: release-main -> main" |
32 | | - body: "Automated release changes." |
33 | | - branch: release-main |
34 | | - token: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + ref: master |
| 20 | + |
| 21 | + - name: Set Git Identity |
| 22 | + run: | |
| 23 | + git config --global user.name 'GitHub Actions' |
| 24 | + git config --global user.email 'github-actions@github.com' |
| 25 | +
|
| 26 | + - name: Create Pull Request with gh cli |
| 27 | + env: |
| 28 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + run: | |
| 30 | + # We're already on master, just need to fetch main |
| 31 | + git fetch origin main:refs/remotes/origin/main |
| 32 | +
|
| 33 | + # Check if there are differences between main and master |
| 34 | + DIFF_COUNT=$(git rev-list --count origin/main..HEAD) |
| 35 | +
|
| 36 | + if [ "$DIFF_COUNT" -gt 0 ]; then |
| 37 | + echo "Differences found between main and master. Creating PR..." |
| 38 | + |
| 39 | + # Use GitHub CLI to create the PR |
| 40 | + gh pr create \ |
| 41 | + --base main \ |
| 42 | + --head master \ |
| 43 | + --title "Merge master into main" \ |
| 44 | + --body "This is an automated PR to merge changes from master into main branch." || true |
| 45 | + |
| 46 | + echo "Pull request created or already exists." |
| 47 | + else |
| 48 | + echo "No differences found between main and master. Skipping PR creation." |
| 49 | + fi |
0 commit comments