Skip to content

Commit

Permalink
Merge pull request #3 from kurokobo/deploy_main
Browse files Browse the repository at this point in the history
feat: allow running tests against main branch
  • Loading branch information
kurokobo authored Jan 1, 2025
2 parents 30d2167 + d4629eb commit 44b6ae5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ For a full list of available cmdlets, refer to the [📚Documentation](./Docs/RE

| Version | Dify<br>(Community) | Dify<br>(Cloud) |
| :---: | :---: | :---: |
| 0.14.2 | ✅ PSDify 0.2.0 | ✅ PSDify 0.2.0 |
| 0.12.1 | ✅ PSDify 0.1.0 | ✅ PSDify 0.1.0 |
| 0.11.2 | ✅ PSDify 0.0.1 | ✅ PSDify 0.0.1 |

Expand Down
12 changes: 9 additions & 3 deletions Tests/01_Initialize-Dify.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Describe "Initialize-Dify" -Skip:$IsCloud {
$Result = Initialize-Dify -Server $DefaultServer -Email $DefaultEmail -Name $DefaultName -Password $DefaultPassword

$Result.Server | Should -Be $DefaultServer
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
if ($InvokeVersionTests) {
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
}
$Result.Name | Should -Be $DefaultName
$Result.Email | Should -Be $DefaultEmail
}
Expand All @@ -56,12 +58,16 @@ Describe "Initialize-Dify" -Skip:$IsCloud {
$Result = Initialize-Dify -Server $DefaultServer -Email $DefaultEmail -Name $DefaultName -InitPassword $DefaultInitPassword -Password $DefaultPassword

$Result.Server | Should -Be $DefaultServer
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
if ($InvokeVersionTests) {
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
}
$Result.Name | Should -Be $DefaultName
$Result.Email | Should -Be $DefaultEmail

$env:PSDIFY_URL | Should -Be $DefaultServer
$env:PSDIFY_VERSION | Should -Be $env:PSDIFY_TEST_VERSION
if ($InvokeVersionTests) {
$env:PSDIFY_VERSION | Should -Be $env:PSDIFY_TEST_VERSION
}
$env:PSDIFY_CONSOLE_TOKEN | Should -Not -BeNullOrEmpty
$env:PSDIFY_CONSOLE_REFRESH_TOKEN | Should -Not -BeNullOrEmpty
}
Expand Down
12 changes: 9 additions & 3 deletions Tests/02_Connect-Dify.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Describe "Connect-Dify" {
$Result = Connect-Dify -Server $DefaultServer -Email $DefaultEmail -Password $DefaultPassword

$Result.Server | Should -Be $DefaultServer
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
if ($InvokeVersionTests) {
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
}
$Result.Name | Should -Be $DefaultName
$Result.Email | Should -Be $DefaultEmail
}
Expand All @@ -41,7 +43,9 @@ Describe "Connect-Dify" {
$Result = Connect-Dify

$Result.Server | Should -Be $DefaultServer
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
if ($InvokeVersionTests) {
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
}
$Result.Name | Should -Be $DefaultName
$Result.Email | Should -Be $DefaultEmail
}
Expand All @@ -61,7 +65,9 @@ Describe "Connect-Dify" {
$Result = Connect-Dify -Server $DefaultServer -Email $DefaultEmail -AuthMethod "Code"

$Result.Server | Should -Be $DefaultServer
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
if ($InvokeVersionTests) {
$Result.Version | Should -Be $env:PSDIFY_TEST_VERSION
}
$Result.Email | Should -Be $DefaultEmail
}
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/Assets/compose_main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
api:
image: langgenius/dify-api:main

worker:
image: langgenius/dify-api:main

web:
image: langgenius/dify-web:main
8 changes: 6 additions & 2 deletions Tests/Helper/New-DifyInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ function New-DifyInstance {
[String] $Path,

[String] $Version,
[String] $EnvFile,
[String] $OverrideFile
[String] $EnvFile
)

if ($env:PSDIFY_TEST_MODE -eq "cloud") {
Expand All @@ -22,11 +21,16 @@ function New-DifyInstance {

git clone --depth=1 -b $Version https://github.com/langgenius/dify.git $Path

if ($Version -eq "main") {
Copy-Item (Join-Path -Path $AssetsRoot -ChildPath "compose_main.yaml") -Destination (Join-Path -Path $DockerPath -ChildPath "docker-compose.override.yaml") -Force
}

Set-Location -Path $DockerPath
Copy-Item -Path ".env.example" -Destination ".env" -Force
if ($EnvFile) {
Get-Content $EnvFile | Add-Content -Path ".env"
}
docker compose pull
docker compose up -d
Set-Location -Path $CurrentLocation

Expand Down
40 changes: 26 additions & 14 deletions Tests/Helper/Start-DifyInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,43 @@ function Start-DifyInstance {
[String] $Path,

[String] $Version,
[String] $EnvFile,
[String] $OverrideFile
[String] $EnvFile
)

if ($env:PSDIFY_TEST_MODE -eq "cloud") {
return
}

# check if the instance is already running
try {
$CurrentDifyVersion = (Get-DifyVersion -Server "http://host.docker.internal/").Version
$IsRunning = (Get-DifyVersion -Server "http://host.docker.internal/").Version
}
catch {
$CurrentDifyVersion = ""
$IsRunning = $null
}

if ($CurrentDifyVersion -ne $Version) {
Remove-DifyInstance -Path $Path
New-DifyInstance -Path $Path -Version $Version -EnvFile $EnvFile -OverrideFile $OverrideFile

$Server = "http://host.docker.internal/"
$Email = "[email protected]"
$Name = "Dify"
$InitPassword = "difyai123456" | ConvertTo-SecureString -AsPlainText -Force
$Password = "difyai123456" | ConvertTo-SecureString -AsPlainText -Force
# gather the current version by reading the docker image label
if ($IsRunning) {
try {
$CurrentVersion = (docker inspect docker-api-1 | ConvertFrom-Json).Config.Labels."org.opencontainers.image.version"
}
catch {
$CurrentVersion = $null
}
}

$null = Initialize-Dify -Server $Server -Email $Email -Name $Name -InitPassword $InitPassword -Password $Password
if ($IsRunning -and ($CurrentVersion -eq $Version)) {
return
}

Remove-DifyInstance -Path $Path
New-DifyInstance -Path $Path -Version $Version -EnvFile $EnvFile

$Server = "http://host.docker.internal/"
$Email = "[email protected]"
$Name = "Dify"
$InitPassword = "difyai123456" | ConvertTo-SecureString -AsPlainText -Force
$Password = "difyai123456" | ConvertTo-SecureString -AsPlainText -Force

$null = Initialize-Dify -Server $Server -Email $Email -Name $Name -InitPassword $InitPassword -Password $Password
}
6 changes: 6 additions & 0 deletions Tests/Initialize-PSDifyPester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ else {
$DefaultAuthMethod = "Code"
$DefaultEmail = $env:PSDIFY_TEST_EMAIL
}
if (@("main") -contains $env:PSDIFY_TEST_VERSION) {
$InvokeVersionTests = $true
}
else {
$InvokeVersionTests = $false
}

# import modules and helper scripts
Get-Module -Name PSDify -ListAvailable | Uninstall-Module -Force -Confirm:$false
Expand Down

0 comments on commit 44b6ae5

Please sign in to comment.