7
7
permissions : # minimum perms the job needs
8
8
contents : write # push the sync branch
9
9
pull-requests : write # open, approve & merge the PR
10
- actions : write # update workflow files
11
10
12
11
concurrency : # never let two syncs race
13
12
group : ${{ github.workflow }}-${{ github.ref }}
@@ -22,34 +21,113 @@ jobs:
22
21
- uses : actions/checkout@v4
23
22
with :
24
23
fetch-depth : 0
24
+ token : ${{ secrets.GITHUB_TOKEN }}
25
25
26
26
# 2. fetch upstream & copy it to a side branch
27
27
- name : Update upstream-sync branch
28
+ env :
29
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
28
30
run : |
31
+ # Configure git identity
32
+ git config --global user.email "[email protected] "
33
+ git config --global user.name "GitHub Action"
34
+
29
35
git remote add upstream https://github.com/openjdk/jdk17u-dev.git
30
36
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
32
68
git push -f origin upstream-sync
33
69
34
- # 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"
42
-
43
- # 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 }}
70
+ # 3. Create or update the PR automatically
71
+ - name : Create or update pull request
72
+ env :
73
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
74
+ run : |
75
+ # Check if PR already exists using REST API
76
+ PR_EXISTS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
77
+ "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:upstream-sync&base=master" \
78
+ | jq -r '.[0].number // empty')
79
+
80
+ if [ -n "$PR_EXISTS" ]; then
81
+ echo "PR #$PR_EXISTS already exists, updating it"
82
+ curl -s -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
83
+ -H "Accept: application/vnd.github.v3+json" \
84
+ "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_EXISTS" \
85
+ -d '{
86
+ "title": "Automated upstream merge",
87
+ "body": "Nightly sync of openjdk/jdk17u-dev:master into this fork"
88
+ }'
89
+ echo "Updated existing PR #$PR_EXISTS"
90
+ else
91
+ echo "Creating new PR"
92
+ PR_RESPONSE=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
93
+ -H "Accept: application/vnd.github.v3+json" \
94
+ "https://api.github.com/repos/${{ github.repository }}/pulls" \
95
+ -d '{
96
+ "title": "Automated upstream merge",
97
+ "body": "Nightly sync of openjdk/jdk17u-dev:master into this fork",
98
+ "head": "upstream-sync",
99
+ "base": "master"
100
+ }')
101
+ PR_NUMBER=$(echo "$PR_RESPONSE" | jq -r '.number')
102
+ if [ "$PR_NUMBER" != "null" ] && [ -n "$PR_NUMBER" ]; then
103
+ echo "Created PR #$PR_NUMBER"
104
+ else
105
+ echo "Failed to create PR. Response: $PR_RESPONSE"
106
+ exit 1
107
+ fi
108
+ fi
48
109
49
- # 5. Enable auto-merge so GitHub merges as soon as
50
- # 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
110
+ # 4. Enable auto-merge (skip approval since you can't approve your own PR)
111
+ - name : Enable auto-merge
112
+ env :
113
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
114
+ run : |
115
+ PR_NUMBER=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
116
+ "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:upstream-sync&base=master" \
117
+ | jq -r '.[0].number')
118
+
119
+ if [ "$PR_NUMBER" != "null" ] && [ -n "$PR_NUMBER" ]; then
120
+ echo "Enabling auto-merge for PR #$PR_NUMBER"
121
+ echo "Note: Auto-approval skipped - GitHub doesn't allow approving your own PRs"
122
+ echo "The PR will need manual approval or branch protection bypass to auto-merge"
123
+
124
+ # Try to enable auto-merge (may not work without approval depending on branch protection)
125
+ curl -s -X PUT -H "Authorization: token $GITHUB_TOKEN" \
126
+ -H "Accept: application/vnd.github+json" \
127
+ "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/merge" \
128
+ -d '{
129
+ "merge_method": "merge"
130
+ }' && echo "Auto-merge enabled" || echo "Auto-merge requires approval or branch protection settings"
131
+ else
132
+ echo "Could not find PR to enable auto-merge"
133
+ fi
0 commit comments