77permissions :           #  minimum perms the job needs
88  contents : write       #  push the sync branch
99  pull-requests : write  #  open, approve & merge the PR
10-   actions : write        #  update workflow files
1110
1211concurrency :           #  never let two syncs race
1312  group : ${{ github.workflow }}-${{ github.ref }} 
@@ -22,34 +21,90 @@ jobs:
2221      - uses : actions/checkout@v4 
2322        with :
2423          fetch-depth : 0 
24+           token : ${{ secrets.GITHUB_TOKEN }} 
2525
2626      #  2. fetch upstream & copy it to a side branch
2727      - name : Update upstream-sync branch 
28+         env :
29+           GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
2830        run : | 
31+           # Configure git identity 
32+           git config --global user.email "[email protected] " 33+           git config --global user.name "GitHub Action" 
34+            
2935          git remote add upstream https://github.com/openjdk/jdk17u-dev.git 
3036          git fetch upstream master 
31-           git checkout -B upstream-sync upstream/master 
37+            
38+           echo "=== Current branch status ===" 
39+           git log --oneline -5 
40+           echo "=== Upstream status ===" 
41+           git log --oneline -5 upstream/master 
42+            
43+           # Create sync branch from current master to preserve workflows 
44+           git checkout -B upstream-sync origin/master 
45+            
46+           echo "=== About to merge upstream changes ===" 
47+           git log --oneline -1 HEAD 
48+           git log --oneline -1 upstream/master 
49+            
50+           # Simple merge approach - let's see what happens 
51+           if git merge upstream/master --no-edit --allow-unrelated-histories; then 
52+             echo "=== Merge successful ===" 
53+             git log --oneline -5 
54+           else 
55+             echo "=== Merge failed, trying alternative approach ===" 
56+             git merge --abort || true  
57+             git reset --hard upstream/master 
58+             # Restore our workflow files after taking upstream 
59+             git checkout origin/master -- .github/workflows/ 
60+             git add .github/workflows/ 
61+             git commit -m "Preserve local workflow files during upstream sync" 
62+             echo "=== Alternative approach completed ===" 
63+             git log --oneline -5 
64+           fi 
65+            
66+           echo "=== Final branch status before push ===" 
67+           git log --oneline -10 
3268          git push -f origin upstream-sync 
3369
3470#  3. Open or update the PR `upstream-sync -> master`
35-       - uses : peter-evans/create-pull-request@v7 
36-         id : cpr 
37-         with :
38-           branch : upstream-sync 
39-           base :   master 
40-           title :  " Automated upstream merge" 
41-           body :   " Nightly sync of openjdk/jdk:master into this fork" 
71+       - name : Create or update pull request 
72+         env :
73+           GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
74+         run : | 
75+           # Check if PR already exists 
76+           PR_NUMBER=$(gh pr list --head upstream-sync --base master --json number --jq '.[0].number' || echo "") 
77+            
78+           if [ -n "$PR_NUMBER" ]; then 
79+             echo "PR #$PR_NUMBER already exists, updating it" 
80+             gh pr edit $PR_NUMBER --title "Automated upstream merge" --body "Nightly sync of openjdk/jdk17u-dev:master into this fork" 
81+           else 
82+             echo "Creating new PR" 
83+             PR_NUMBER=$(gh pr create --head upstream-sync --base master --title "Automated upstream merge" --body "Nightly sync of openjdk/jdk17u-dev:master into this fork" --json number --jq '.number') 
84+             echo "Created PR #$PR_NUMBER" 
85+           fi 
86+            
87+           echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT 
4288
4389#  4. Auto-approve that PR
44-       - if : steps.cpr.outputs.pull-request-operation != 'none' 
45-         uses : hmarr/auto-approve-action@v4 
46-         with :
47-           pull-request-number : ${{ steps.cpr.outputs.pull-request-number }} 
90+       - name : Auto-approve PR 
91+         env :
92+           GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
93+         run : | 
94+           PR_NUMBER=$(gh pr list --head upstream-sync --base master --json number --jq '.[0].number') 
95+           if [ -n "$PR_NUMBER" ]; then 
96+             gh pr review $PR_NUMBER --approve --body "Auto-approved upstream sync" 
97+             echo "Approved PR #$PR_NUMBER" 
98+           fi 
4899
49100#  5. Enable auto-merge so GitHub merges as soon as
50101      #     branch protection requirements are satisfied
51-       - if : steps.cpr.outputs.pull-request-operation == 'created' 
52-         uses : peter-evans/enable-pull-request-automerge@v3 
53-         with :
54-           pull-request-number : ${{ steps.cpr.outputs.pull-request-number }} 
55-           merge-method : merge 
102+       - name : Enable auto-merge 
103+         env :
104+           GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
105+         run : | 
106+           PR_NUMBER=$(gh pr list --head upstream-sync --base master --json number --jq '.[0].number') 
107+           if [ -n "$PR_NUMBER" ]; then 
108+             gh pr merge $PR_NUMBER --auto --merge 
109+             echo "Enabled auto-merge for PR #$PR_NUMBER" 
110+           fi 
0 commit comments