forked from graphprotocol/graph-node
-
Notifications
You must be signed in to change notification settings - Fork 2
133 lines (110 loc) · 4.01 KB
/
sync.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
on:
schedule:
# 1:05 past midnight UTC
- cron: "5 1 * * *"
env:
DEFAULT_BRANCH: "master"
name: "Sync with upstream"
jobs:
sync-check:
name: "Sync Necessity Check"
runs-on: "ubuntu-latest"
outputs:
should_sync: ${{ steps.out.outputs.should_sync }}
steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"
with:
fetch-depth: 0
submodules: true
- id: "out"
name: "Check if sync is needed"
run: |
git fetch origin
git remote add upstream https://github.com/graphprotocol/graph-node
git fetch upstream --no-tags
MERGE_BASE=$(git merge-base origin/$DEFAULT_BRANCH upstream/$DEFAULT_BRANCH)
# Don't force push unnecessarily unless changes are detected
if [[ $(git rev-list $MERGE_BASE..upstream/$DEFAULT_BRANCH | wc -l) -ne 0 ]]; then
echo "should_sync=true" >> $GITHUB_OUTPUT
else
echo "No changes detected on upstream $DEFAULT_BRANCH"
echo "should_sync=false" >> $GITHUB_OUTPUT
fi
sync:
name: "Sync"
runs-on: "ubuntu-latest"
needs: "sync-check"
if: "needs.sync-check.outputs.should_sync == 'true'"
steps:
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
- name: "Free up disk space"
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: "Checkout source code"
uses: "actions/checkout@v3"
with:
# Subsequent actions are not triggered unless using PAT
token: "${{ secrets.GH_PAT }}"
fetch-depth: 0
submodules: true
- name: "Setup toolchain"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
profile: "minimal"
override: false
- uses: "Swatinem/rust-cache@v1"
with:
cache-on-failure: true
- name: "Install libpq-dev"
run: |
sudo apt-get install -y libpq-dev
- name: "Install protoc"
run: |
# The version from apt-get is too old and won't work
curl -L -o /tmp/protoc.zip "https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip"
mkdir ${HOME}/protoc
cd ${HOME}/protoc
unzip /tmp/protoc.zip && rm /tmp/protoc.zip
echo "${HOME}/protoc/bin" >> $GITHUB_PATH
- name: "Config Git"
run: |
git config user.name "Jonathan LEI"
git config user.email "[email protected]"
- name: "Update branch"
run: |
git fetch origin
git remote add upstream https://github.com/graphprotocol/graph-node
git fetch upstream --no-tags
MERGE_BASE=$(git merge-base origin/$DEFAULT_BRANCH upstream/$DEFAULT_BRANCH)
# Brings files from `home` to default branch
git checkout $DEFAULT_BRANCH
git reset --hard upstream/$DEFAULT_BRANCH
git checkout origin/home .
git add .
git commit -m "chore: README and CI changes"
# Here, we pick commits on the default branch except the first one. We do this instead
# of a naive rebase because the `home` branch might have changed, causing merge
# conflicts.
COMMIT_COUNT=$(git rev-list $MERGE_BASE..origin/$DEFAULT_BRANCH | wc -l)
if [ "$COMMIT_COUNT" -ne "1" ]; then
git cherry-pick origin/$DEFAULT_BRANCH~$(($COMMIT_COUNT-1))..origin/$DEFAULT_BRANCH
fi
- name: "Check code format"
run: |
cargo fmt --all --check
- name: "Build"
run: |
cargo build --all --all-targets
- name: "Push updated branch"
run: |
git push --force-with-lease
- name: "Move nightly tag"
run: |
git tag -f nightly
git push --delete origin nightly
git push origin nightly