Skip to content

Commit

Permalink
Workflow adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
rrg92 committed Sep 17, 2024
1 parent f733eb7 commit 1699a72
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 79 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: TestPowershai
on:
workflow_call:
secrets:
HuggingFaceToken:
OpenaiToken:
GoogleApiToken:
inputs:
TestModels:
required: true
type: string

jobs:
PsGallery:
name: PsGallery
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch tags
run: git fetch --prune --unshallow --tags
- name: Test
shell: pwsh
env:
HF_API_TOKEN: ${{ secrets.HuggingFaceToken }}
OPENAI_API_KEY: ${{ secrets.OpenaiToken }}
GOOGLE_API_KEY: ${{ secrets.GoogleApiToken }}
POWERSHAI_TEST_MODELS: ${{ inputs.TestModels }}
run: ./util/publish-prepare.ps1 -BasicTest
16 changes: 16 additions & 0 deletions .github/workflows/testonly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: TestOnly
on:
push:
branches:
- test-*

jobs:
Test:
uses: ./.github/workflows/test.yml
with:
TestModel: ${{ env.POWERSHAI_TEST_MODELS }}
secrets:
HuggingFaceToken: ${{ secrets.HF_API_TOKEN }}
OpenaiToken: ${{ secrets.OPENAI_API_KEY }}
GoogleApiToken: ${{ secrets.GOOGLE_API_KEY }}

105 changes: 49 additions & 56 deletions util/TestPowershai.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
param(
[switch]$Basic
,$TestModels = $ENV:POWERSHAI_TEST_MODELS # provider/modelname,provider/modelname
,$TestModels = $Env:POWERSHAI_TEST_MODELS # provider/modelname,provider/modelname
,[switch]$Verbose
)

Expand Down Expand Up @@ -35,63 +35,56 @@ try {
$Provider = $Parts[0];
$Model = $Parts[1];

try {
write-host "Testing provider: $provider";
Set-AiProvider $provider;

write-host "Testing model: $model";
Set-AiDefaultModel $model;
write-host "Testing provider: $provider";
Set-AiProvider $provider;

write-host "Testing model: $model";
Set-AiDefaultModel $model;

write-host "Test: Simple temporary default chat";
iat "Hi, this is a test from powershell ai module called Powershai";

1..5 | iat "write names of that numbers"

ia "gere 5 palavras em pt-BR"
ia -Lines "traduza os nomes para o inglês" | %{ "English: $_" }

# chat creation test!
write-host "Test: Creating new chat"
$Chat = New-PowershaiChat "Test-$ChatNum";

$SecretGuid = [Guid]::NewGuid().Guid;
write-host "Test: New chat sending data! SecretGuid: $SecretGuid"
ia (@(
"This is a secret data: $SecretGuid"
"I will ask about it later"
) -Join "`n")

write-host "Test: Getting data from current chat history"
$ReturnedSecret = @(ia -Lines "What is secret data? Return just secret data in first line");
if($ReturnedSecret){
$ReturnedSecret = @($ReturnedSecret)[0].trim();
}

write-host " SecretGuidReturned: ~$ReturnedSecret~"

if($ReturnedSecret -ne $SecretGuid){
throw "HISTORYTEST_POSITIVE_FAIL"
}

write-host " HISTORY TEST PASSED"

$ReturnedSecret2 = @(ia -Lines "What is secret data? If you dont know about scret, just answer that text: DONT_KNOW");

if($ReturnedSecret2){
$ReturnedSecret2 = $ReturnedSecret2 -Join "`n"
}

if($ReturnedSecret2 -like "*$SecretGuid*" -or $ReturnedSecret2 -NotLike "*DONT_KNOW*"){
throw "HISTORYTEST_NEGATIVE_FAIL"
}

write-host " TEMPORARY TEST PASSED";



} catch {
write-host "failed: $_";
write-host "Test: Simple temporary default chat";
iat "Hi, this is a test from powershell ai module called Powershai";

1..5 | iat "write names of that numbers"

ia "gere 5 palavras em pt-BR"
ia -Lines "traduza os nomes para o inglês" | %{ "English: $_" }

# chat creation test!
write-host "Test: Creating new chat"
$Chat = New-PowershaiChat "Test-$ChatNum";

$SecretGuid = [Guid]::NewGuid().Guid;
write-host "Test: New chat sending data! SecretGuid: $SecretGuid"
ia (@(
"This is a secret data: $SecretGuid"
"I will ask about it later"
) -Join "`n")

write-host "Test: Getting data from current chat history"
$ReturnedSecret = @(ia -Lines "What is secret data? Return just secret data in first line");
if($ReturnedSecret){
$ReturnedSecret = @($ReturnedSecret)[0].trim();
}

write-host " SecretGuidReturned: ~$ReturnedSecret~"

if($ReturnedSecret -ne $SecretGuid){
throw "HISTORYTEST_POSITIVE_FAIL"
}

write-host " HISTORY TEST PASSED"

$ReturnedSecret2 = @(ia -Lines "What is secret data? If you dont know about scret, just answer that text: DONT_KNOW");

if($ReturnedSecret2){
$ReturnedSecret2 = $ReturnedSecret2 -Join "`n"
}

if($ReturnedSecret2 -like "*$SecretGuid*" -or $ReturnedSecret2 -NotLike "*DONT_KNOW*"){
throw "HISTORYTEST_NEGATIVE_FAIL"
}

write-host " TEMPORARY TEST PASSED";
}

} catch {
Expand Down
43 changes: 20 additions & 23 deletions util/publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
param(
$ApiKey = $Env:PSGALERY_KEY
,[switch]$CompileDoc
,[switch]$Simulate
,[switch]$BasicTest
,[switch]$Publish
,[switch]$CheckVersion
)

$ErrorActionPreference = "Stop";
. (Join-Path "$PsScriptRoot" UtilLib.ps1)
CheckPowershaiRoot
$ModuleRoot = Resolve-Path powershai

if(!$Global:POWERSHAI_PUBLISH_DATA){
$Global:POWERSHAI_PUBLISH_DATA = @{}
Expand All @@ -26,28 +27,29 @@ if(!$POWERSHAI_PUBLISH_DATA.TempDir){

$TempDir = $POWERSHAI_PUBLISH_DATA.TempDir;

$PlatyDir = Join-Path $TempDir "platy"
$null = New-Item -Force -ItemType Directory -Path $PlatyDir

if($CompileDoc){
$PlatyDir = Join-Path $TempDir "platy"
$null = New-Item -Force -ItemType Directory -Path $PlatyDir
write-host "DocCompileWorkDir: $PlatyDir";
$DocsScript = Join-Path $PsScriptRoot doc.ps1
& $DocsScript $PlatyDir -SupportedLangs * -MaxAboutWidth 150
}

$ModuleRoot = Resolve-Path powershai


# Current version!
$LastTaggedVersion = git describe --tags --match "v*" --abbrev=0;
# Module version!
if($$CheckVersion){
# Current version!
$LastTaggedVersion = git describe --tags --match "v*" --abbrev=0;

$TaggedVersion = [Version]($LastTaggedVersion.replace("v",""))
$TaggedVersion = [Version]($LastTaggedVersion.replace("v",""))

# Module version!
$Mod = import-module $ModuleRoot -force -PassThru;

if($TaggedVersion -ne $Mod.Version){
throw "POWERSHAI_PUBLISH_INCORRECT_VERSION: Module = $($Mod.Version) Git = $TaggedVersion";
$Mod = import-module $ModuleRoot -force -PassThru;

if($TaggedVersion -ne $Mod.Version){
throw "POWERSHAI_PUBLISH_INCORRECT_VERSION: Module = $($Mod.Version) Git = $TaggedVersion";
}
}

if($BasicTest){
Expand All @@ -56,17 +58,12 @@ if($BasicTest){
write-host " Test run!";
}

$PublishParams = @{
Path = $ModuleRoot
NuGetApiKey = $ApiKey
Force = $true
Verbose = $true;
}

if($Simulate){
$PublishParams.WhatIf = $true;
}

if($Publish){
$PublishParams = @{
Path = $ModuleRoot
NuGetApiKey = $ApiKey
Force = $true
Verbose = $true;
}
Publish-Module -Path $ModuleRoot -NuGetApiKey $ApiKey -Force -Verbose
}

0 comments on commit 1699a72

Please sign in to comment.