forked from networkservicemesh/.github
-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (69 loc) · 2.67 KB
/
resolve-conflicts.yaml
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
---
name: Check mergeability
on:
workflow_call:
inputs:
pr_branch_ref:
type: string
required: true
secrets:
token:
required: true
jobs:
resolve_conflicts:
runs-on: ubuntu-latest
steps:
- name: Checkout default branch
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.token }}
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.pr_branch_ref }}
fetch-depth: 0
token: ${{ secrets.token }}
- name: Verify conflicts only in go.mod/go.sum
run: |
CONFLICTING_FILES=$(git merge-tree $(git merge-base origin/main HEAD) origin/main HEAD | \
awk 'BEGIN {is_conflict = 0} /changed in both/{is_conflict = 1; next} /base/{if (is_conflict) {print $4; is_conflict = 0} next }' | \
{ grep -vF "go.mod" || true; } | \
{ grep -vF "go.sum" || true; })
if [[ -n $CONFLICTING_FILES ]]; then
echo "Conflicts can be resolved only in go.mod and go.sum files, but conflicts were found in other files: $CONFLICTING_FILES"
exit 1
fi
- name: Check number of retries
run: |
if [ $(git log --oneline | head -n 10 | grep -Fc "Automatically resolving conflicts in go.mod") -ge 3 ]; then
echo "Couldn't automatically resolve conflicts (number of re-tries is >= 3). Please, resolve them manually."
exit 1
fi
- name: Merge default branch
run: |
git config --global user.email "[email protected]"
git config --global user.name "NSMBot"
git config pull.rebase false
git pull -q origin main -s ort -X theirs
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.23.3
- name: Update version manually
run: |
branch=${{ inputs.pr_branch_ref }}
repository=${branch#update/networkservicemesh/}
echo Update ${repository} version in go.mod manually
go get -u github.com/networkservicemesh/${repository}@main
- name: Re-generate go.sum
run: go mod tidy
- name: Push changes
run: |
echo "Automatically resolving conflicts in go.mod and updating dependency versions to the latest" >> /tmp/commit-message
git config --global user.email "[email protected]"
git config --global user.name "NSMBot"
git add -- go.sum go.mod
git commit -s -F /tmp/commit-message
echo "Force-pushing changes to ${{ inputs.pr_branch_ref }}"
git push -f origin ${{ inputs.pr_branch_ref }}