Skip to content

Commit

Permalink
ci: run kwil-js test (#637)
Browse files Browse the repository at this point in the history
* ci: run kwiljs test
* ci: support kjs version
* ci: allow manual trigger Release workflow

---------

Co-authored-by: KwilLuke <105600466+KwilLuke@users.noreply.github.com>
  • Loading branch information
Yaiba and KwilLuke committed Apr 9, 2024
1 parent d6820ac commit 0df049b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
79 changes: 60 additions & 19 deletions .github/workflows/kgw-test-reuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ name: kgw-test-reuse
on:
workflow_call:
inputs:
# for logging purpose
# 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
# 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)
kdb-sha:
# In that case, use SHA as the input.
kdb-ref: # can be branch/tag/SHA
required: true
type: string
kdb-branch:
kgw-ref: # can be branch/tag/SHA
required: true
type: string
kgw-branch:
kjs-ref: # can be branch/tag/SHA
required: true
type: string
secrets:
Expand All @@ -25,27 +27,26 @@ jobs:
kgw-test:
runs-on: ubuntu-latest
steps:
- name: Show branch
- name: Show references
run: |
echo "====== kgw test branches ======"
echo "====== kgw test references ======"
test ${{ secrets.kgw-access-token }} = "" && echo "kgw access token empty" || echo "kgw access token available"
echo "kdb fork: ${{ inputs.kdb-repo }}"
echo "kdb sha: ${{ inputs.kdb-sha }}"
echo "kdb branch: ${{ inputs.kdb-branch }}"
echo "kgw branch: ${{ inputs.kgw-branch }}"
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 sha
if: ${{ inputs.kdb-sha != '' }}
- name: checkout kwil-db using ref from input
if: ${{ inputs.kdb-ref != '' }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.kdb-sha }}
ref: ${{ inputs.kdb-ref }}
submodules: true

- name: checkout kwil-db using branch
if: ${{ inputs.kdb-sha == '' }}
- name: checkout kwil-db using the reference or SHA for this event
if: ${{ inputs.kdb-ref == '' }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.kdb-branch }}
submodules: true

- name: Setup Go
Expand Down Expand Up @@ -88,10 +89,10 @@ jobs:
kdbDir=$(pwd)
git config --global url."https://${GH_ACCESS_TOKEN}:x-oauth-basic@github.com/kwilteam/".insteadOf "https://github.com/kwilteam/"
rm -rf /tmp/kgw
git clone -b ${{ inputs.kgw-branch }} https://github.com/kwilteam/kgw.git /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-branch }} == release-* ]]; then
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
Expand Down Expand Up @@ -165,6 +166,46 @@ jobs:
sed -i "s/\${UID}:\${GID}/${testUserID}:${testGroupID}/g" test/integration/docker-compose.override.yml
KIT_LOG_LEVEL=warn go test -count=1 -timeout 0 ./test/integration -run ^TestKGW$ -v
- name: Run kwil-js test against kwild & kgw
run: |
cd deployments/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
# find the latest tag if kjs-ref is a tag
if [[ ${{ inputs.kjs-ref }} == v0.* ]]; then
kjs_ref=`git tag -l | grep ${{ inputs.kjs-ref }} | sort | tail -n 1`
else
kjs_ref=${{ inputs.kjs-ref }}
fi
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 http://localhost:8080/api/v1/chain_info | jq -r .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:8080" \
--chain-id $chain_id \
--allow-adhoc-query \
--allow-deploy-db \
--log-level debug
echo "run KWIL-JS TEST against kwild(http:localhost:8080), with $chain_id"
PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000001 CHAIN_ID=$chain_id GATEWAY_ON=false GAS_ON=false KWIL_PROVIDER=http://localhost:8080 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
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
release:
types:
- published
workflow_dispatch:

jobs:
parse-release-version:
Expand All @@ -13,24 +14,29 @@ jobs:
outputs:
vkdb: ${{ steps.versions.outputs.kdb_version }}
vkgw: ${{ steps.versions.outputs.kgw_version }}
vkjs: ${{ steps.versions.outputs.kjs_version }}
steps:
- name: Get kdb n kgw version # minor version
id: versions
shell: bash
run: |
version=`echo ${{ github.event.release.tag_name }} | sed 's/^v//' | cut -d '.' -f 2`
kgw_version=$(v7="2"; v6="1"; eval echo \${v$version})
kjs_version=$(v7="6"; v6="5"; eval echo \${v$version})
echo "kdb_version=v0.$version" >> $GITHUB_OUTPUT
echo "kgw_version=v0.$kgw_version" >> $GITHUB_OUTPUT
echo "kdb_version=v0.$version <> kgw_version=v0.$kgw_version"
echo "kjs_version=v0.$kjs_version" >> $GITHUB_OUTPUT
echo "kdb_version=v0.$version <> kgw_version=v0.$kgw_version <> kjs_version=v0.$kjs_version"
kgw-test-release:
name: Run kgw test on release branches
needs: parse-release-version
uses: ./.github/workflows/kgw-test-reuse.yaml
with:
kdb-branch: release-${{ needs.parse-release-version.outputs.vkdb }}
kgw-branch: release-${{ needs.parse-release-version.outputs.vkgw }}
kdb-ref: release-${{ needs.parse-release-version.outputs.vkdb }}
kgw-ref: release-${{ needs.parse-release-version.outputs.vkgw }}
# kwil-js has no release branch, we'll use the latest tag of this minor version
kjs-ref: ${{ needs.parse-release-version.outputs.vkjs }}
secrets:
kgw-access-token: ${{ secrets.KGW_MACH_SECRET_FOR_KWILDB }}

Expand Down
8 changes: 4 additions & 4 deletions deployments/compose/kwil/docker-compose.override.yml.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: '3'
services:
app:
version: '3'

services:
app:
user: 1000

0 comments on commit 0df049b

Please sign in to comment.