-
Notifications
You must be signed in to change notification settings - Fork 113
111 lines (98 loc) · 3.99 KB
/
sync-branches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: 'Sync branches'
on:
schedule:
- cron: '0 0 * * 1' # Run at the start of every monday
workflow_dispatch: # Allow manually invoking this workflow
permissions: {}
env:
base_branch: 'origin/main'
jobs:
sync-non-code:
if: github.repository == 'dotnet/dotnet-monitor'
strategy:
matrix:
branch: ["release/6.x", "release/8.0"]
name: 'Sync non-code to ${{ matrix.branch }}'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: true # We need to persist credentials to push the resulting changes upstream.
fetch-depth: 0 # Fetch the entire repo for the below git operations
ref: ${{ matrix.branch }}
- name: Sync branch
run: |
git checkout --no-overlay "$base_branch" -- \
".github" \
".devcontainer" \
".vscode" \
"eng/actions" \
"cspell.json" \
"documentation/**.md"
- name: Open PR
uses: ./.github/actions/open-pr
with:
files_to_commit: "*"
title: '[${{ matrix.branch }}] Sync non-code with ${{ env.base_branch }}'
commit_message: sync non-code with ${{ env.base_branch }}
body: Sync non-code with ${{ env.base_branch }}. This PR was auto generated and will not be automatically merged in.
branch_name: sync/${{ matrix.branch }}
fail_if_files_unchanged: false
labels: 'automatic-pr'
auth_token: ${{ secrets.GITHUB_TOKEN }}
sync-code:
if: github.repository == 'dotnet/dotnet-monitor'
strategy:
matrix:
branch: ["feature/9.x"]
name: 'Sync branch with ${{ matrix.branch }}'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: true # We need to persist credentials to push the resulting changes upstream.
fetch-depth: 0 # Fetch the entire repo for the below git operations
ref: ${{ matrix.branch }}
- name: Sync branch
run: |
ourFiles=$(perl -ne '/^([^\s]+)\s+merge=ours/gm && print "$1 "' .gitattributes)
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Activate the ours merge driver to respect any branch specific files
git config merge.ours.driver true
MERGE_RESULT=0
# Don't fail if the automatic merge fails, we'll try to handle it later
git merge "$base_branch" --strategy=ort --strategy-option=theirs || MERGE_RESULT=$?
# If the merge failed it's likely due to a (modify/delete) conflict. Try to auto-resolve it by accepting the results.
# If we've deviated more than that the below commands will fail and it requires manual intervention.
if [ $MERGE_RESULT -ne 0 ]; then
for match in $ourFiles; do
git add -- "$match"
done
git commit --no-edit
fi
for match in $ourFiles; do
git checkout --no-overlay "$target_branch" -- "$match"
done
env:
target_branch: origin/${{ matrix.branch }}
- name: Open PR
uses: ./.github/actions/open-pr
with:
files_to_commit: "*"
title: '[${{ matrix.branch }}] Sync branch with ${{ env.base_branch }}'
commit_message: Restore branch-specific files
body: Sync branch with ${{ env.base_branch }}. This PR was auto generated and will not be automatically merged in.
branch_name: sync/${{ matrix.branch }}
fail_if_files_unchanged: false
always_create_pr: true
labels: 'automatic-pr'
auth_token: ${{ secrets.GITHUB_TOKEN }}