Skip to content

Commit

Permalink
Moved the testing logic to github action for re-use (#45)
Browse files Browse the repository at this point in the history
* Moved the testing logic to github action

* Fixed the typo

* Added the missing shell name
  • Loading branch information
miazamrai authored Nov 15, 2022
1 parent 7343508 commit d388926
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 16 deletions.
51 changes: 51 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: 'rai-sdk-go test'
description: 'rai-sdk-go test action'

inputs:
client_id:
required: true
description: 'Client ID for oAuth'

client_secret:
required: true
description: 'Client secret for oAuth'

client_credentials_url:
required: true
description: 'Client credentials url for fetching the oAuth token'

rai_host:
required: false
description: 'RAI host'
default: 'azure.relationalai.com'

custom_headers:
required: false
description: 'Optional http headers'
default: '{}'

runs:
using: 'composite'
steps:
- uses: actions/checkout@v3
with:
repository: RelationalAI/rai-sdk-go

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Build
run: go build -v ./rai
shell: bash

- name: Test
env:
CLIENT_ID: ${{ inputs.client_id }}
CLIENT_SECRET: ${{ inputs.client_secret }}
CLIENT_CREDENTIALS_URL: ${{ inputs.client_credentials_url }}
HOST: ${{ inputs.rai_host }}
CUSTOM_HEADERS: ${{ inputs.custom_headers }}
run: go test -v -timeout 30m ./rai
shell: bash
20 changes: 6 additions & 14 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Build
run: go build -v ./rai
- uses: actions/checkout@v3

- name: Test
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
CLIENT_CREDENTIALS_URL: ${{ secrets.CLIENT_CREDENTIALS_URL }}
run: go test -v -timeout 30m ./rai
uses: ./.github/actions/test
with:
client_id: ${{ secrets.CLIENT_ID }}
client_secret: ${{ secrets.CLIENT_SECRET }}
client_credentials_url: ${{ secrets.CLIENT_CREDENTIALS_URL }}
8 changes: 6 additions & 2 deletions rai/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,22 @@ func newTestClient() (*Client, error) {
clientId := os.Getenv("CLIENT_ID")
clientSecret := os.Getenv("CLIENT_SECRET")
clientCredentialsUrl := os.Getenv("CLIENT_CREDENTIALS_URL")
raiHost := os.Getenv("HOST")
if raiHost == "" {
raiHost = "azure.relationalai.com"
}

placeHolderConfig := `
[default]
host=azure.relationalai.com
host=%s
region=us-east
port=443
scheme=https
client_id=%s
client_secret=%s
client_credentials_url=%s
`
configSrc := fmt.Sprintf(placeHolderConfig, clientId, clientSecret, clientCredentialsUrl)
configSrc := fmt.Sprintf(placeHolderConfig, raiHost, clientId, clientSecret, clientCredentialsUrl)
LoadConfigString(configSrc, "default", &cfg)
opts := ClientOptions{Config: cfg}
testClient := NewClient(context.Background(), &opts)
Expand Down

0 comments on commit d388926

Please sign in to comment.