-
Notifications
You must be signed in to change notification settings - Fork 12
244 lines (221 loc) · 8.76 KB
/
kgw-test-reuse.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
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
name: kgw-test-reuse
on:
workflow_call:
inputs:
# for logging purpose, if kdb-ref is from PR.
kdb-repo:
type: string
# for workflow_run trigger, we need to check out to the SHA, bcz most of
# the pr come from forked repo, and we can't access the branch, but we can
# access the sha(i.e, pull/xxx/head)
# In that case, use SHA as the input.
kdb-ref: # can be branch/tag/SHA
required: true
type: string
kgw-ref: # can be branch/tag/SHA
required: true
type: string
kjs-ref: # can be branch/tag/SHA
required: true
type: string
secrets:
kgw-access-token:
required: true
jobs:
# JOB to run change detection
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
# Set job outputs to values from filter step
outputs:
run: ${{ steps.filter.outputs.code }}
steps:
- uses: actions/checkout@v4
with:
# This may save additional git fetch roundtrip if
# merge-base is found within latest 20 commits
fetch-depth: 20
- uses: dorny/[email protected]
id: filter
with:
filters: .github/filters.yaml
#predicate-quantifier: 'every'
kgw-test:
needs: changes
# only run only if there are changes, or manually triggered
if: ${{ needs.changes.outputs.run == 'true' || github.event_name == 'workflow_dispatch'}}
runs-on: ubuntu-latest
steps:
- name: Show references
run: |
echo "====== kgw test references ======"
test ${{ secrets.kgw-access-token }} = "" && echo "kgw access token empty" || echo "kgw access token available"
echo "kdb repo: ${{ inputs.kdb-repo }}"
echo "kdb reference: ${{ inputs.kdb-ref }}"
echo "kgw reference: ${{ inputs.kgw-ref }}"
echo "kjs reference: ${{ inputs.kjs-ref }}"
- name: checkout kwil-db using ref from input
if: ${{ inputs.kdb-ref != '' }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.kdb-ref }}
submodules: true
- name: checkout kwil-db using the reference or SHA for this event
if: ${{ inputs.kdb-ref == '' }}
uses: actions/checkout@v4
with:
submodules: true
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
check-latest: true
- name: Install Taskfile
uses: arduino/setup-task@v2
- name: Init workspace
run: |
task work
- name: Generate go vendor
run: |
go version
task vendor
- name: Build cli binaries
run: |
task build:cli
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers for kwild # both restore and save
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache-kwild
key: ${{ runner.os }}-buildx-kwild-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-kwild
- name: manual git tag
run: |
version=`echo ${{ github.sha }} | cut -c 1-7`
echo "GIT_TAG=$version" >> $GITHUB_ENV
- name: manual build time
run: |
build_time=`TZ=UTC date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ"`
echo "BUILD_TIME=$build_time" >> $GITHUB_ENV
- name: Build kwild image
id: docker_build_kwild
uses: docker/build-push-action@v6
with:
context: .
load: true
builder: ${{ steps.buildx.outputs.name }}
build-args: |
git_commit=${{ github.sha }}
version=${{ env.GIT_TAG }}
build_time=${{ env.BUILD_TIME }}
file: ./contrib/docker/kwild.dockerfile
push: false
tags: kwild:latest
cache-from: type=local,src=/tmp/.buildx-cache-kwild
cache-to: type=local,dest=/tmp/.buildx-cache-kwild-new
- name: Cache Docker layers for kgw # both restore and save
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache-kgw
key: ${{ runner.os }}-buildx-kgw-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-kgw
- name: Pull kgw repo & create vendor
shell: bash
env:
GH_ACCESS_TOKEN: ${{ secrets.kgw-access-token }}
# vendor is used to bypass private repo issues;
# if kgw on non-release branches, we want to use go workspace, so that kgw
# always uses the latest version of kwil-db/core
# when build in workspace, the dockerfile requires kgw and kwild in same folder.
run: |
kdbDir=$(pwd)
echo "KDB_DIR=$(pwd)" >> $GITHUB_ENV
echo "current dir: " $kdbDir
rm -rf go.work
cd ..
rm -rf ./kgw
git config --global url."https://${GH_ACCESS_TOKEN}:[email protected]/kwilteam/".insteadOf "https://github.com/kwilteam/"
git clone -b ${{ inputs.kgw-ref }} https://github.com/kwilteam/kgw.git ./kgw
rm -rf ~/.gitconfig
cd ./kgw
echo "KGW_DIR=$(pwd)" >> $GITHUB_ENV
if [[ ${{ inputs.kgw-ref }} == release-* ]]; then
go mod vendor
else
# non release branch, use go workspace to always use the latest version of kwil-db/core
test -f go.work || go work init . ../kwil-db/core
go work vendor
fi
cd -
cd $kdbDir
echo "current dir: " $pwd
- name: Build kgw image
id: docker_build_kgw
uses: docker/build-push-action@v6
with:
context: ${{ env.KGW_DIR }}/..
load: true
builder: ${{ steps.buildx.outputs.name }}
file: ${{ env.KGW_DIR }}/Dockerfile.workspace
push: false
tags: kgw:latest
cache-from: type=local,src=/tmp/.buildx-cache-kgw
cache-to: type=local,dest=/tmp/.buildx-cache-kgw-new
- name: Run kgw acceptance test
run: |
testUserID=$(id -u)
testGroupID=$(id -g)
KACT_LOG_LEVEL=warn task test:act:nb -- -kgw -ugid "$testUserID:$testGroupID"
- name: Run kwil-js test against kwild & kgw
run: |
cd contrib/docker/compose/kwil
echo "run kwild in docker"
# NOTE: we use the default hardhat signer address
KWIL_DB_OWNER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 docker compose up -d
# clone kwil-js
git clone https://github.com/kwilteam/kwil-js.git /tmp/kwil-js
cd /tmp/kwil-js
# kwil-js release branch is v0.x
kjs_ref=${{ inputs.kjs-ref }}
echo "====== checkout kwil-js ref: $kjs_ref"
git checkout $kjs_ref
# build kwil-js
npm install
npm run build
# run tests
chain_id=`curl -s -H "content-type: application/json" -d '{"jsonrpc":"2.0","method":"user.chain_info","params":null,"id":1}' http://localhost:8484/rpc/v1 | jq -r .result.chain_id`
echo "run kgw in docker"
docker run --name kgwcontainer -d --rm --network kwil_kwilnet0 -p 8090:8090 kgw:latest \
--devmode -d "http://localhost:8090" \
--cors-allow-origins "*" \
-b "http://kwild:8484" \
--chain-id $chain_id \
--allow-adhoc-query \
--log-level debug \
--ip-request-rate-authn 0
echo "run KWIL-JS TEST against kwild(http://localhost:8484), with $chain_id"
# NOTE: we use the default hardhat private key
PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 CHAIN_ID=$chain_id KWIL_PROVIDER=http://localhost:8484 npm run integration
echo "run KWIL-JS TEST against kgw(http://localhost:8090), with $chain_id"
# assume the test above will drop the database, so we can deploy again
PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 CHAIN_ID=$chain_id GATEWAY_ON=TRUE KWIL_PROVIDER=http://localhost:8090 npm run integration
echo "stop running kwild & kgw"
docker rm -f kgwcontainer
cd -
docker compose down
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache-kwild
mv /tmp/.buildx-cache-kwild-new /tmp/.buildx-cache-kwild
rm -rf /tmp/.buildx-cache-kgw
mv /tmp/.buildx-cache-kgw-new /tmp/.buildx-cache-kgw
- name: Prune Docker
if: ${{ always() }}
run: docker rm $(docker ps -a -q) -f ; docker network prune -f ; docker volume prune -f || true
- name: Show error log
if: ${{ failure() }}
run: grep -C 20 -s -i -r -e 'kwild version' -e 'error' -e 'warn' /tmp/TestKwil*/*.log /tmp/TestKwil*/*/*.log