update ci kgw #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | | ||
go work init . ./test ./core | ||
- name: Generate go vendor | ||
run: | | ||
go version | ||
task vendor | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- 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 | ||
run: | | ||
# kdbDir=$(pwd) | ||
# echo "KDB_DIR=$(pwd)" >> $GITHUB_ENV | ||
# echo "current dir: " $kdbDir | ||
# 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 | ||
kdbDir=$(pwd) | ||
git config --global url."https://${GH_ACCESS_TOKEN}:[email protected]/kwilteam/".insteadOf "https://github.com/kwilteam/" | ||
rm -rf /tmp/kgw | ||
git clone -b ${{ inputs.kgw-ref }} https://github.com/kwilteam/kgw.git /tmp/kgw | ||
rm -rf ~/.gitconfig | ||
cd /tmp/kgw | ||
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 . $kdbDir/core | ||
go work vendor | ||
fi | ||
cd - | ||
- name: Build kgw image | ||
id: docker_build_kgw | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: /tmp/kgw | ||
load: true | ||
builder: ${{ steps.buildx.outputs.name }} | ||
file: /tmp/kgw/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: 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: Build cli binaries | ||
run: | | ||
task build:cli | ||
- 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" | ||
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 | ||
echo "run KWIL-JS TEST against kwild(http://localhost:8484), with $chain_id" | ||
PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000001 CHAIN_ID=$chain_id GATEWAY_ON=false GAS_ON=false 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=0000000000000000000000000000000000000000000000000000000000000001 CHAIN_ID=$chain_id GATEWAY_ON=true GAS_ON=false 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-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/TestKwilInt*/*.log /tmp/TestKwilInt*/*/*.log |