forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (140 loc) · 6.47 KB
/
auto-merge.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# This workflow is triggered by a cron job and merges the upstream 'devel' branch into 'devel+classic'.
# If there are merge conflicts, it creates an issue and does not push any changes.
# Incidentally, it also pushes 'upstream/devel:devel' to the repo, keeping our diff up-to-date.
#
# Changelog:
#
# In January 2023, ledgerwatch extracted a Go library from erigon called 'github.com/ledgerwatch/erigon-lib' as an external dependency.
# See github.com/etccooperative/erigon-lib for changes enabling Ethereum Classic support.
#
# This workflow attempts to manage the upstream merges of both github.com/etccooperative/erigon and github.com/etccooperative/erigon-lib.
# It will first fetch and merge github.com/ledgerwatch/erigon-lib into github.com/etccooperative/erigon-lib (branches: 'main' vs. 'main+classic').
# If this merge (and push to remote) is successful, it will then fetch, merge, and push github.com/ledgerwatch/erigon into github.com/etccooperative/erigon (branches: 'devel' vs. 'devel+classic').
name: AutoMerge - Nightly
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
erigon-lib:
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
ERIGON_LIB_HEAD: ${{ steps.merge.outputs.ERIGON_LIB_HEAD }}
steps:
- uses: actions/checkout@v3
with:
repository: etccooperative/erigon-lib
ref: main+classic
submodules: false
fetch-depth: 0
- name: Set up git config
run: |
git config --global user.email "b5c6@protonmail.com"
git config --global user.name "meowsbits"
# Keep forked remote default branch ('main') up-to-date with upstream.
- name: Push erigon-lib 'upstream/main:main' (with --force)
env:
MY_PAT: ${{ secrets.MEOWSBITS_REPOWORKFLOW_TOKEN }}
run: |
git remote add upstream https://github.com/ledgerwatch/erigon-lib.git
git fetch upstream
git remote set-url origin https://meowsbits:${MY_PAT}@github.com/etccooperative/erigon-lib.git
# 'Github Actions workflow push to another repo' @ https://stackoverflow.com/a/69979203
git config --unset-all http.https://github.com/.extraheader
git push origin upstream/main:main --force
# Keep forked remote ETC branch ('main+classic') merged with upstream's "main" branch.
- name: Merge erigon-lib branch 'main' into 'main+classic'
id: merge # Necessary for setting an OUTPUT value.
run: |
merge_status=$(git merge -X theirs upstream/main --no-edit)
if [[ $merge_status == 1 ]]; then
echo "Merge conflict detected"
exit 1
fi
# The merge was successful.
# Before exiting, save the newly-minted commit hash to an environment variable,
# which we'll reference later in an erigon update step upgrading (bumping) this dependency.
ERIGON_LIB_HEAD="$(git rev-parse HEAD)"
echo "ERIGON_LIB_HEAD=${ERIGON_LIB_HEAD}" # Debug print.
echo "ERIGON_LIB_HEAD=${ERIGON_LIB_HEAD}" >> $GITHUB_OUTPUT # Write the result to the special OUTPUT value.
exit 0
- name: Push erigon-lib changes if successful
if: success()
env:
MY_PAT: ${{ secrets.MEOWSBITS_REPOWORKFLOW_TOKEN }}
run: |
git remote set-url origin https://meowsbits:${MY_PAT}@github.com/etccooperative/erigon-lib.git
git push origin main+classic
- name: Create issue if failed
if: failure()
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: .github/automerge-issue-on-failure.md
erigon:
needs: erigon-lib
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: devel+classic
submodules: false
fetch-depth: 0
token: ${{ secrets.MEOWSBITS_REPOWORKFLOW_TOKEN }}
- name: Set up git config
run: |
git config --global user.email "b5c6@protonmail.com"
git config --global user.name "meowsbits"
# Keep forked remote default branch ('devel') up-to-date with upstream.
- name: Push erigon 'upstream/devel:devel' (with --force)
env:
MY_PAT: ${{ secrets.MEOWSBITS_REPOWORKFLOW_TOKEN }}
run: |
git remote add upstream https://github.com/ledgerwatch/erigon.git
git fetch upstream
git remote set-url origin https://meowsbits:${MY_PAT}@github.com/${GITHUB_REPOSITORY}.git
git push origin upstream/devel:devel --force
# Update the erigon-lib dependency in go.mod.
# We use the environment variable ERIGON_LIB_HEAD, which was set in the previous step.
- uses: actions/setup-go@v3
with:
go-version: '1.20.0' # The Go version to download (if necessary) and use.
- name: Update erigon-lib dependency
run: |
echo "ERIGON_LIB_HEAD=${{ needs.erigon-lib.outputs.ERIGON_LIB_HEAD }}" # Debug print.
[[ -z "${{ needs.erigon-lib.outputs.ERIGON_LIB_HEAD }}" ]] && {
echo "ERIGON_LIB_HEAD is empty"
exit 0
}
go mod edit -replace "github.com/ledgerwatch/erigon-lib=github.com/etccooperative/erigon-lib@${{ needs.erigon-lib.outputs.ERIGON_LIB_HEAD }}"
go mod tidy
git diff --quiet || {
echo "Work tree has modified files."
git add go.mod go.sum
git commit -m "Update erigon-lib dependency"
}
# Keep forked remote ETC branch ('devel+classic') merged with upstream's "devel" branch.
- name: Merge erigon branch 'devel' into 'devel+classic'
run: |
merge_status=$(git merge -X theirs upstream/devel --no-edit)
if [[ $merge_status == 1 ]]; then
echo "Merge conflict detected"
exit 1
fi
exit 0
- name: Push erigon changes if successful
if: success()
env:
MY_PAT: ${{ secrets.MEOWSBITS_REPOWORKFLOW_TOKEN }}
run: |
git remote set-url origin https://meowsbits:${MY_PAT}@github.com/${GITHUB_REPOSITORY}.git
git push origin devel+classic
- name: Create issue if failed
if: failure()
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: .github/automerge-issue-on-failure.md