Skip to content

Commit

Permalink
chore(tests): seperate bff-sdk-generation from example-test
Browse files Browse the repository at this point in the history
Signed-off-by: bjwswang <[email protected]>
  • Loading branch information
bjwswang committed Apr 2, 2024
1 parent ec979f3 commit e6f6ad2
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 59 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build_bff_sdk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: BFF SDK Tests/Push

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:
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: Setup Golang
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- 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')
run: |
echo '//registry.npmjs.org/:_authToken="${{ secrets.NPM_TOKEN }}"' >> ~/.npmrc
- name: Set variable on Merge pull request
if: github.event_name == 'push'
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')
run: tests/build-bff-sdk.sh
env:
GRL_SDK_TEST_ONLY: ${{ env.GRL_SDK_TEST_ONLY }}
38 changes: 0 additions & 38 deletions .github/workflows/example_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ on:
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"
Expand Down Expand Up @@ -59,8 +53,6 @@ jobs:
path: /tmp/operator.image.tar

example-test:
env:
GRL_SDK_TEST_ONLY: true
needs:
- build-image
runs-on: ubuntu-latest
Expand Down Expand Up @@ -114,33 +106,3 @@ jobs:
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: |
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 '//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
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: |
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
env:
GRL_SDK_TEST_ONLY: ${{ env.GRL_SDK_TEST_ONLY }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ gql-gen:
@go run github.com/99designs/[email protected] generate
build-apiserver: gql-gen
@CGO_ENABLED=0 GOOS=linux go build -o bin/apiserver apiserver/main.go
run-apiserver:
POD_NAMESPACE=arcadia go run apiserver/main.go --enable-playground=true &
run-apiserver: gql-gen
nohup go run apiserver/main.go --enable-playground=true --debug > apiserver.log 2>&1 &

# sdk for apiserver api
GRL_SDK_GENERATOR_IMAGE ?= yuntijs/gql-sdk-generator:latest
Expand Down
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 @@
# commoe
mutation createApplication($input:CreateApplicationMetadataInput!){
Application{
createApplication(input: $input) {
Expand Down
28 changes: 16 additions & 12 deletions apiserver/service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,28 @@ 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)
}

// for swagger
if conf.EnableSwagger {
Expand Down
36 changes: 36 additions & 0 deletions tests/build-bff-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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

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 "Start kubeagi apiserver with debug mode"
make build-apiserver
nohup ./bin/apiserver --enable-playground=true --debug > apiserver.log 2>&1 &

sleep 5

info "2. build bff sdk"
export GRAPH_API_ENDPOINT="http://0.0.0.0:8081/bff"
make bff-sdk-generator
Loading

0 comments on commit e6f6ad2

Please sign in to comment.