Skip to content

Commit

Permalink
chore(tests): split test scripts and seperate bff-sdk-generation from…
Browse files Browse the repository at this point in the history
… example-test

Signed-off-by: bjwswang <bjwswang@gmail.com>
  • Loading branch information
bjwswang committed Apr 1, 2024
1 parent ec979f3 commit 7a55e5f
Show file tree
Hide file tree
Showing 15 changed files with 1,286 additions and 858 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/bff-sdk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: KubeagiTests

on:
push:
branches:
- 'main'
pull_request:
branches: [main]
workflow_dispatch:
inputs:
OnlyTestGeneratedSdk:
description: 'only test bff-sdk-generator, but not push'
required: true
default: 'true'
type: boolean

env:
LOG_DIR: "/tmp/kubeagi-example-test/logs"
GOPROXY: https://proxy.golang.org/,direct

concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
build-bff-sdk:
env:
GRL_SDK_TEST_ONLY: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download operator image from cache
uses: actions/cache/restore@v3
with:
key: operator.image-${{ github.sha }}
path: /tmp/operator.image.tar
- name: Load component image to /tmp from cache
uses: actions/cache/restore@v3
with:
key: component-image-cache-${{ github.sha }}
restore-keys: component-image-cache-
path: |
/home/runner/work/kubeagi/kubeagi/tmp/images/
/home/runner/work/kubeagi/kubeagi/tmp/all.image.list
- name: Load kubeagi image to docker
run: |
docker load --input /tmp/operator.image.tar
- name: Copy the existing kustomize
# avoid kustomize installation to bypass the rate limit of GitHub.
run: |
mkdir -p ${GITHUB_WORKSPACE}/bin
cp /usr/local/bin/kustomize ${GITHUB_WORKSPACE}/bin/kustomize
- name: Install mc
run: |
command -v mc >/dev/null 2>&1 || (curl https://dl.min.io/client/mc/release/linux-amd64/mc \
--create-dirs -o /usr/local/bin/mc && chmod +x /usr/local/bin/mc )
- uses: dorny/paths-filter@v2
id: gql-changes
with:
filters: |
gql:
- 'apiserver/graph/schema/*.gql'
- name: setting token to npmrc
if: (( github.event_name == 'push' && steps.gql-changes.outputs.gql == 'true') || github.event_name == 'workflow_dispatch') && matrix.no == 1
run: |
echo '//registry.npmjs.org/:_authToken="${{ secrets.NPM_TOKEN }}"' >> ~/.npmrc
- name: Set variable on Merge pull request
if: github.event_name == 'push' && matrix.no == 1
run: |
echo "GRL_SDK_TEST_ONLY=false" >> $GITHUB_ENV
- name: Set variable on workflow_dispatch
if: github.event_name == 'workflow_dispatch'
run: |
echo "GRL_SDK_TEST_ONLY=$TEST_ONLY" >> $GITHUB_ENV
env:
TEST_ONLY: ${{ inputs.OnlyTestGeneratedSdk }}
- name: make sdk
if: (steps.gql-changes.outputs.gql == 'true' || github.event_name == 'workflow_dispatch') && matrix.no == 1
run: tests/build-bff-sdk.sh
env:
GRL_SDK_TEST_ONLY: ${{ env.GRL_SDK_TEST_ONLY }}
87 changes: 57 additions & 30 deletions .github/workflows/example_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,13 @@ jobs:
key: operator.image-${{ github.sha }}
path: /tmp/operator.image.tar

example-test:
build-bff-sdk:
env:
GRL_SDK_TEST_ONLY: true
needs:
- build-image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
no: [1]
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
overprovision-lvm: true
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
- uses: actions/checkout@v4
- name: Download operator image from cache
uses: actions/cache/restore@v3
Expand All @@ -104,18 +91,7 @@ jobs:
run: |
command -v mc >/dev/null 2>&1 || (curl https://dl.min.io/client/mc/release/linux-amd64/mc \
--create-dirs -o /usr/local/bin/mc && chmod +x /usr/local/bin/mc )
- name: Example test
run: tests/example-test.sh
env:
GITHUB_ACTION_NO: ${{ matrix.no }}
- name: Upload logs if test fail
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}-${{ matrix.no }}.logs
path: ${{ env.LOG_DIR }}
- uses: dorny/paths-filter@v2
if: matrix.no == 1
id: gql-changes
with:
filters: |
Expand All @@ -124,7 +100,6 @@ jobs:
- name: setting token to npmrc
if: (( github.event_name == 'push' && steps.gql-changes.outputs.gql == 'true') || github.event_name == 'workflow_dispatch') && matrix.no == 1
run: |
echo '//dev-npm.k8s.com.cn/:_authToken="${{ secrets.TENX_NPM_TOKEN }}"' >> ~/.npmrc
echo '//registry.npmjs.org/:_authToken="${{ secrets.NPM_TOKEN }}"' >> ~/.npmrc
- name: Set variable on Merge pull request
if: github.event_name == 'push' && matrix.no == 1
Expand All @@ -138,9 +113,61 @@ jobs:
TEST_ONLY: ${{ inputs.OnlyTestGeneratedSdk }}
- name: make sdk
if: (steps.gql-changes.outputs.gql == 'true' || github.event_name == 'workflow_dispatch') && matrix.no == 1
run: |
kubectl port-forward svc/arcadia-apiserver -n arcadia 8888:8081 --address 0.0.0.0 >/dev/null 2>&1 &
export GRAPH_API_ENDPOINT="http://0.0.0.0:8888/bff"
make bff-sdk-generator
run: tests/build-bff-sdk.sh
env:
GRL_SDK_TEST_ONLY: ${{ env.GRL_SDK_TEST_ONLY }}

# example-test:
# needs:
# - build-image
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# no: [1]
# steps:
# - name: Maximize build space
# uses: easimon/maximize-build-space@master
# with:
# overprovision-lvm: true
# remove-dotnet: 'true'
# remove-android: 'true'
# remove-haskell: 'true'
# remove-codeql: 'true'
# remove-docker-images: 'true'
# - uses: actions/checkout@v4
# - name: Download operator image from cache
# uses: actions/cache/restore@v3
# with:
# key: operator.image-${{ github.sha }}
# path: /tmp/operator.image.tar
# - name: Load component image to /tmp from cache
# uses: actions/cache/restore@v3
# with:
# key: component-image-cache-${{ github.sha }}
# restore-keys: component-image-cache-
# path: |
# /home/runner/work/kubeagi/kubeagi/tmp/images/
# /home/runner/work/kubeagi/kubeagi/tmp/all.image.list
# - name: Load kubeagi image to docker
# run: |
# docker load --input /tmp/operator.image.tar
# - name: Copy the existing kustomize
# # avoid kustomize installation to bypass the rate limit of GitHub.
# run: |
# mkdir -p ${GITHUB_WORKSPACE}/bin
# cp /usr/local/bin/kustomize ${GITHUB_WORKSPACE}/bin/kustomize
# - name: Install mc
# run: |
# command -v mc >/dev/null 2>&1 || (curl https://dl.min.io/client/mc/release/linux-amd64/mc \
# --create-dirs -o /usr/local/bin/mc && chmod +x /usr/local/bin/mc )
# - name: Example test
# run: tests/example-test.sh
# env:
# GITHUB_ACTION_NO: ${{ matrix.no }}
# - name: Upload logs if test fail
# if: failure()
# uses: actions/upload-artifact@v4
# with:
# name: ${{ github.sha }}-${{ matrix.no }}.logs
# path: ${{ env.LOG_DIR }}
51 changes: 51 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch GQL",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/apiserver/main.go",
"env": {
"POD_NAMESPACE": "kubeagi-system",
"KUBECONFIG": "/home/bjwswang/.kube/config",
},
"args": [
"-v",
"5",
"--host",
"172.22.96.167",
"--enable-playground",
"--client-id",
"bff-client",
"--client-secret",
"61324af0-1234-4f61-b110-ef57013267d6",
"--master-url",
"https://k8s.172.22.96.167.nip.io",
"--issuer-url",
"https://portal.172.22.96.167.nip.io/oidc",
]
},
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"POD_NAMESPACE": "kubeagi-system",
"KUBECONFIG": "/home/bjwswang/.kube/config",
},
"args": [
"-v",
"5",
"--health-probe-bind-address",
"localhost:8083"
]
},
]
}
24 changes: 17 additions & 7 deletions apiserver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,29 @@ import (
var s = &ServerConfig{}

type ServerConfig struct {
Scheme *runtime.Scheme

// Debug mode which only have graphql server running
Debug bool
// SystemNamespace which hosts system resources
SystemNamespace string

Host string
Port int
Host string
Port int

PlaygroundEndpointPrefix string

// EnablePlayground is true when graphql playground is going to be utilized
EnablePlayground bool
EnableSwagger bool
EnableOIDC bool
// EnableSwagger is true when swagger is going to be utilized
EnableSwagger bool

PlaygroundEndpointPrefix string
// OIDC configurations
EnableOIDC bool
IssuerURL, MasterURL, ClientID, ClientSecret string

// DataProcessURL is the URL of the data process service
DataProcessURL string

Scheme *runtime.Scheme
}

func NewServerFlags() ServerConfig {
Expand All @@ -62,6 +71,7 @@ func NewServerFlags() ServerConfig {
flag.StringVar(&s.ClientID, "client-id", "", "oidc client id(required when enable odic)")
flag.StringVar(&s.ClientSecret, "client-secret", "", "oidc client secret(required when enable odic)")
flag.StringVar(&s.DataProcessURL, "data-processing-url", "http://127.0.0.1:28888", "url to access data processing server")
flag.BoolVar(&s.Debug, "debug", false, "debug model for apiserver")

klog.InitFlags(nil)
flag.Parse()
Expand Down
1 change: 1 addition & 0 deletions apiserver/graph/schema/application.gql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# commoen for test
mutation createApplication($input:CreateApplicationMetadataInput!){
Application{
createApplication(input: $input) {
Expand Down
29 changes: 17 additions & 12 deletions apiserver/service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,29 @@ func NewServerAndRun(conf config.ServerConfig) {
}

bffGroup := r.Group("/bff")
// for file operations
registerMinIOAPI(bffGroup, conf)

// for ops apis with graphql
registerGraphQL(r, bffGroup, conf)

ragGroup := r.Group("/rags")
registerRAG(ragGroup, conf)
// when debug model is disabled
if !config.GetConfig().Debug {
// for file operations
registerMinIOAPI(bffGroup, conf)
ragGroup := r.Group("/rags")
registerRAG(ragGroup, conf)

// for admin chat server with Restful apis
chatGroup := r.Group("/chat")
registerChat(chatGroup, conf)

// for admin chat server with Restful apis
chatGroup := r.Group("/chat")
registerChat(chatGroup, conf)
// for gpts chat server with Restful apis
gptsGroup := r.Group("/gpts/chat")
registerGptsChat(gptsGroup, conf)

// for gpts chat server with Restful apis
gptsGroup := r.Group("/gpts/chat")
registerGptsChat(gptsGroup, conf)
fg := r.Group("/forward")
registerForward(fg, conf)

fg := r.Group("/forward")
registerForward(fg, conf)
}

Check failure on line 82 in apiserver/service/router.go

View workflow job for this annotation

GitHub Actions / Lint Go code

unnecessary trailing newline (whitespace)

// for swagger
if conf.EnableSwagger {
Expand Down
35 changes: 35 additions & 0 deletions tests/build-bff-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
#
# Copyright contributors to the KubeAGI project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

source ./tests/scripts/utils.sh
source ./tests/scripts/setup_testenv.sh

if [[ $RUNNER_DEBUG -eq 1 ]] || [[ $GITHUB_RUN_ATTEMPT -gt 1 ]]; then
# use [debug logging](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging)
# or run the same test multiple times.
set -x
fi
export TERM=xterm-color

info "1. setup test env"
setup_testenv

info "2. build bff sdk"
kubectl port-forward svc/arcadia-apiserver -n arcadia 8888:8081 --address 0.0.0.0 >/dev/null 2>&1 &
export GRAPH_API_ENDPOINT="http://0.0.0.0:8888/bff"
make bff-sdk-generator
Loading

0 comments on commit 7a55e5f

Please sign in to comment.