-
Notifications
You must be signed in to change notification settings - Fork 1
234 lines (200 loc) · 6.97 KB
/
rust.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
name: safe-client-gateway
on: [ push, pull_request ]
env:
CARGO_TERM_COLOR: always
jobs:
rustfmt:
runs-on: ubuntu-20.04
steps:
- name: Checkout branch
uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2022-02-18
override: true
components: rustfmt
- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check
tests:
runs-on: ubuntu-20.04
services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
env:
RUSTC_BOOTSTRAP: 1 # grcov requires a nightly build. See https://github.com/mozilla/grcov#usage
REDIS_URI: redis://localhost:6379
REDIS_URI_MAINNET: redis://localhost:6379
WEBHOOK_TOKEN: test_webhook_token
CONFIG_SERVICE_URI: https://config.service.url
VPC_TRANSACTION_SERVICE_URI: 'false'
SCHEME: http
TRANSACTION_SERVICE_AUTH_TOKEN: some_other_random_token
steps:
- name: Checkout branch
uses: actions/checkout@v3
# This can be removed once https://github.com/actions-rs/toolchain/pull/209 is merged and released
- name: Set variables
run: |
echo "TOOLCHAIN=$(rustup show active-toolchain | cut -d " " -f1)" >> $GITHUB_ENV
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.TOOLCHAIN }}
override: true
- name: Cargo cache
uses: Swatinem/rust-cache@v2
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --all --locked -- --test-threads 1
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Awarnings'
- name: Cache grcov
id: grcov-cache
uses: actions/[email protected]
with:
path: /home/runner/.cargo/bin/
key: ${{ runner.os }}-grcov-v080
- name: Fetch grcov
if: steps.grcov-cache.outputs.cache-hit != 'true'
run: curl --location https://github.com/mozilla/grcov/releases/download/v0.8.0/grcov-linux-x86_64.tar.bz2 | tar jxf -
- name: Run grcov
id: coverage
uses: actions-rs/[email protected]
with:
config: ./.github/action-rs/grcov.yml
- name: Coveralls upload
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ steps.coverage.outputs.report }}
docs:
runs-on: ubuntu-20.04
needs: [ rustfmt, tests ]
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
fetch-depth: 0 # checks out all branches and tags, necessary for versioning /about endpoint
- name: Set variables
run: |
echo "TOOLCHAIN=$(rustup show active-toolchain | cut -d " " -f1)" >> $GITHUB_ENV
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.TOOLCHAIN }}
override: true
components: rustfmt
- name: Cargo cache
uses: Swatinem/rust-cache@v2
- name: Generate docs
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-deps --workspace --locked
- name: Move folder
run: |
rm -rf target/doc/docs
mv target/doc/safe_client_gateway target/doc/docs
cp .github/landing_page/* target/doc
- name: Fix internal links
run: find ./target/doc/docs/ -type f -exec sed -i "s/safe_client_gateway/docs/g" {} \;
- name: Update docs
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
docker-publish-staging:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main')
needs: [ rustfmt, tests ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# This is needed for the "Set Version" step as we need to fetch the available tags
fetch-depth: '0'
- name: Set up QEMU
uses: docker/[email protected]
with:
platforms: arm64
- name: Set Version
run: |
description="$(git describe --tags --always)"
echo "VERSION=${description:1}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: VERSION=${{ env.VERSION }}
tags: safeglobal/safe-client-gateway:staging
cache-from: type=registry,ref=safeglobal/safe-client-gateway:staging
cache-to: type=inline
deploy:
runs-on: ubuntu-20.04
env:
DOCKERHUB_ORG: safeglobal
DOCKERHUB_PROJECT: safe-client-gateway
needs: [ rustfmt, tests ]
if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
fetch-depth: 0 # checks out all branches and tags, necessary for versioning /about endpoint
- name: Dockerhub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Deploy main
if: github.ref == 'refs/heads/main'
run: bash scripts/deploy_docker.sh staging
- name: Deploy tag
if: startsWith(github.ref, 'refs/tags/')
run: bash scripts/deploy_docker.sh ${GITHUB_REF##*/}
- name: Deploy develop # unused
if: github.ref == 'refs/heads/develop'
run: bash scripts/deploy_docker.sh develop
autodeploy:
runs-on: ubuntu-20.04
needs: [ docker-publish-staging ]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Deploy staging
run: bash scripts/autodeploy.sh
env:
AUTODEPLOY_URL: ${{ secrets.AUTODEPLOY_URL }}
AUTODEPLOY_TOKEN: ${{ secrets.AUTODEPLOY_TOKEN }}
TARGET_ENV: "staging"