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,83 @@ 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+ if gh pr view upstream-sync 2>/dev/null; then
77+ echo "PR already exists, updating it"
78+ gh pr edit upstream-sync --title "Automated upstream merge" --body "Nightly sync of openjdk/jdk17u-dev:master into this fork"
79+ else
80+ echo "Creating new PR"
81+ gh pr create --head upstream-sync --base master --title "Automated upstream merge" --body "Nightly sync of openjdk/jdk17u-dev:master into this fork"
82+ fi
4283
4384 # 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 }}
85+ - name : Auto-approve PR
86+ env :
87+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
88+ run : |
89+ if gh pr view upstream-sync 2>/dev/null; then
90+ gh pr review upstream-sync --approve --body "Auto-approved upstream sync"
91+ echo "Approved PR for upstream-sync branch"
92+ fi
4893
4994 # 5. Enable auto-merge so GitHub merges as soon as
5095 # 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
96+ - name : Enable auto-merge
97+ env :
98+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
99+ run : |
100+ if gh pr view upstream-sync 2>/dev/null; then
101+ gh pr merge upstream-sync --auto --merge
102+ echo "Enabled auto-merge for upstream-sync branch"
103+ fi
0 commit comments