-
Notifications
You must be signed in to change notification settings - Fork 75
326 lines (295 loc) · 10.6 KB
/
client.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
name: Client
on:
schedule:
- cron: "0 0 * * *"
push:
branches:
- main
paths-ignore:
- "docs-v1/**"
- "docs/**"
- "infrastructure/**"
- "scripts/**"
- "solidity-v1/**"
- "token-stakedrop/**"
pull_request:
workflow_dispatch:
inputs:
environment:
description: "Environment for workflow execution"
required: false
default: "dev"
upstream_builds:
description: "Upstream builds"
required: false
upstream_ref:
description: "Git reference to checkout (e.g. branch name)"
required: false
default: "main"
# TODO: Implement automatic releases creation on tags push with https://github.com/softprops/action-gh-release
jobs:
client-detect-changes:
runs-on: ubuntu-latest
outputs:
path-filter: ${{ steps.filter.outputs.path-filter }}
steps:
- uses: actions/checkout@v3
if: github.event_name == 'pull_request'
- uses: dorny/paths-filter@v2
if: github.event_name == 'pull_request'
id: filter
with:
filters: |
path-filter:
- './!((docs-v1|docs|infrastructure|scripts|solidity-v1|token-stakedrop)/**)'
electrum-integration-detect-changes:
runs-on: ubuntu-latest
outputs:
path-filter: ${{ steps.filter.outputs.path-filter }}
steps:
- uses: actions/checkout@v3
if: github.event_name == 'pull_request'
- uses: dorny/paths-filter@v2
if: github.event_name == 'pull_request'
id: filter
with:
filters: |
path-filter:
- './config/_electrum_urls/**'
- './pkg/bitcoin/electrum/**'
client-build-test-publish:
needs: client-detect-changes
if: |
github.event_name != 'pull_request'
|| needs.client-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# Fetch the whole history for the `git describe` command to work.
fetch-depth: 0
- name: Resolve versions
run: |
echo "version=$(git describe --tags --match "v[0-9]*" HEAD)" >> $GITHUB_ENV
echo "revision=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Load environment variables
uses: keep-network/ci/actions/load-env-variables@v2
if: github.event_name == 'workflow_dispatch'
with:
environment: ${{ github.event.inputs.environment }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker Build Image
uses: docker/build-push-action@v3
with:
target: build-docker
tags: go-build-env
build-args: |
VERSION=${{ env.version }}
REVISION=${{ env.revision }}
load: true # load image to local registry to use it in next steps
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
context: .
# Since build-push-action doesn't support outputing an image to multiple outputs
# we need to save it in a separate step. See: https://github.com/moby/buildkit/issues/1555
# Once multiple outputs are supported we can replace this step with
# `outputs` property configured in `Build Docker Build Image`:
# outputs: |
# type=image
# type=docker,dest=/tmp/go-build-env-image.tar
- name: Save Docker Build Image
run: |
docker save --output /tmp/go-build-env-image.tar go-build-env
- name: Upload Docker Build Image
uses: actions/upload-artifact@v3
with:
name: go-build-env-image
path: /tmp/go-build-env-image.tar
- name: Run Go tests
run: |
docker run \
--workdir /go/src/github.com/keep-network/keep-core \
go-build-env \
gotestsum
- name: Build Docker Runtime Image
if: github.event_name != 'workflow_dispatch'
uses: docker/build-push-action@v3
with:
target: runtime-docker
labels: |
version=${{ env.version }}
revision=${{ env.revision }}
push: false
context: .
- name: Login to Google Container Registry
if: github.event_name == 'workflow_dispatch'
uses: docker/login-action@v2
with:
registry: ${{ env.GCR_REGISTRY_URL }}
username: _json_key
password: ${{ secrets.KEEP_TEST_GCR_JSON_KEY }}
- name: Build and publish Docker Runtime Image
if: github.event_name == 'workflow_dispatch'
uses: docker/build-push-action@v3
env:
IMAGE_NAME: "keep-client"
with:
target: runtime-docker
tags: |
${{ env.GCR_REGISTRY_URL }}/${{ env.GOOGLE_PROJECT_ID }}/${{ env.IMAGE_NAME }}
${{ env.GCR_REGISTRY_URL }}/${{ env.GOOGLE_PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.version }}
${{ env.GCR_REGISTRY_URL }}/${{ env.GOOGLE_PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.environment }}
${{ env.GCR_REGISTRY_URL }}/${{ env.GOOGLE_PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.version }}-${{ github.event.inputs.environment }}
labels: |
version=${{ env.version }}
revision=${{ env.revision }}
build-args: |
ENVIRONMENT=${{ github.event.inputs.environment }}
VERSION=${{ env.version }}
REVISION=${{ env.revision }}
push: true
context: .
- name: Build Client Binaries
uses: docker/build-push-action@v3
with:
target: output-bins
outputs: type=local,dest=./out/bin/
build-args: |
ENVIRONMENT=${{ github.event.inputs.environment }}
VERSION=${{ env.version }}
REVISION=${{ env.revision }}
push: false
context: .
- name: Archive Client Binaries
uses: actions/upload-artifact@v3
with:
name: binaries
path: |
out/bin/*.tar.gz
out/bin/*.md5
out/bin/*.sha256
- name: Publish Client Binaries
if: github.event_name == 'workflow_dispatch'
uses: thesis/[email protected]
with:
service-key: ${{ secrets.KEEP_TEST_CLIENT_BINARIES_UPLOADER_SERVICE_KEY_JSON_BASE64 }}
# TODO: Change to keep-prd-210b once mainnet setup is done and we are sure we want to publish mainnet builds automatically.
project: keep-test-f3e0
bucket-name: keep-test-client-binaries
bucket-path: ${{ github.event.inputs.environment }}/${{ env.version }}
build-folder: out/bin
- name: Notify CI about completion of the workflow
if: github.event_name == 'workflow_dispatch'
uses: keep-network/ci/actions/notify-workflow-completed@v2
env:
GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
with:
module: "github.com/keep-network/keep-core/client"
url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
environment: ${{ github.event.inputs.environment }}
upstream_builds: ${{ github.event.inputs.upstream_builds }}
upstream_ref: ${{ github.event.inputs.upstream_ref }}
version: ${{ env.version }}
- # Temp fix - move cache instead of copying (added below step and
# modified value of `cache-to`).
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
# Without the change some jobs were failing with `no space left on device`
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
client-scan:
needs: client-detect-changes
if: |
github.event_name == 'push'
|| needs.client-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- uses: actions/checkout@v3
- uses: securego/gosec@master
with:
args: |
-exclude-dir=pkg/chain/ethereum/beacon/gen
-exclude-dir=pkg/chain/ethereum/ecdsa/gen
-exclude-dir=pkg/chain/ethereum/threshold/gen
-exclude-dir=pkg/chain/ethereum/tbtc/gen
./...
client-format:
needs: client-detect-changes
if: |
github.event_name == 'push'
|| needs.client-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
- name: gofmt
run: |
if [ $(gofmt -l . | wc -l) -gt 0 ]; then
gofmt -d -e .
exit 1
fi
client-vet:
needs: client-detect-changes
if: |
github.event_name == 'push'
|| needs.client-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
- run: go vet
client-lint:
needs: client-detect-changes
if: |
github.event_name == 'push'
|| needs.client-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
- name: Staticcheck
uses: dominikh/[email protected]
with:
version: "2022.1.3"
install-go: false
client-integration-test:
needs: [electrum-integration-detect-changes, client-build-test-publish]
if: |
github.event_name != 'pull_request'
|| needs.electrum-integration-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download Docker Build Image
uses: actions/download-artifact@v3
with:
name: go-build-env-image
path: /tmp
- name: Load Docker Build Image
run: |
docker load --input /tmp/go-build-env-image.tar
- name: Run Go Integration Tests
run: |
docker run \
--workdir /go/src/github.com/keep-network/keep-core \
go-build-env \
gotestsum -- -timeout 20m -tags=integration ./...