1- # .github/workflows/sync-upstream.yml
2- name : Sync Upstream
3-
1+ # .github/workflows/auto-upstream-sync.yml
2+ name : Upstream-sync → protected master
43on :
5- schedule :
6- - cron : ' 22 14 * * *' # Runs every day at 14:15 UTC
7- workflow_dispatch :
4+ schedule : # run every night
5+ - cron : ' 7 2 * * *'
6+ workflow_dispatch : # (optional) manual trigger
7+
8+ permissions : # minimum perms the job needs
9+ contents : write # push the sync branch
10+ pull-requests : write # open, approve & merge the PR
811
9- permissions :
10- contents : write
11- actions : read
12+ concurrency : # never let two syncs race
13+ group : ${{ github.workflow }}-${{ github.ref }}
14+ cancel-in-progress : true
1215
1316jobs :
1417 sync :
1518 runs-on : ubuntu-latest
1619
1720 steps :
18- - name : Checkout code
19- uses : actions/checkout@v2
20- with :
21- persist-credentials : false
22- fetch-depth : 0
23-
24- - name : Pull latest changes from upstream
25- run : |
26- git config --global user.email "[email protected] " 27- git config --global user.name "Datadog Syncup Service"
28- git remote add upstream https://github.com/openjdk/jdk.git
29- git fetch upstream
30- git checkout -b upstream-master upstream/master
31- git checkout master
32- git merge upstream-master
33-
34- - name : Push changes to downstream
35- uses : ad-m/github-push-action@master
36- with :
37- github_token : ${{ secrets.GH_PAT }}
38- branch : master
21+ # 1. full clone so we always have the latest tip
22+ - uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0
25+
26+ # 2. fetch upstream & copy it to a side branch
27+ - name : Update upstream-sync branch
28+ run : |
29+ git remote add upstream https://github.com/openjdk/jdk.git
30+ git fetch upstream master
31+ git checkout -B upstream-sync upstream/master
32+ git push -f origin upstream-sync
33+
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 }}
48+
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
0 commit comments