generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db0c0fb
commit 93891af
Showing
3 changed files
with
206 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Import-Module (Resolve-Path Utilities) ` | ||
-Function ` | ||
Get-WebProjectPath, ` | ||
Invoke-ExpressionWithException, ` | ||
Write-Status ` | ||
-Force | ||
|
||
$projectPath = Get-WebProjectPath | ||
$repositoryPath = Join-Path $projectPath "App_Data/CIRepository" | ||
$launchProfile = $Env:ASPNETCORE_ENVIRONMENT -eq "CI" ? "Zapier.WebCI" : "DancingGoat" | ||
$configuration = $Env:ASPNETCORE_ENVIRONMENT -eq "CI" ? "Release" : "Debug" | ||
$dbName = $Env:DATABASE_NAME | ||
$dbUser = $Env:DATABASE_USER | ||
$dbPassword = $Env:DATABASE_PASSWORD | ||
|
||
$turnOffCI = "sqlcmd " + ` | ||
"-S localhost " + ` | ||
"-d $dbName " + ` | ||
"-U $dbUser " + ` | ||
"-P $dbPassword " + ` | ||
"-Q `"UPDATE CMS_SettingsKey SET KeyValue = N'False' WHERE KeyName = N'CMSEnableCI'`"" | ||
|
||
$turnOnCI = "sqlcmd " + ` | ||
"-S localhost " + ` | ||
"-d $dbName " + ` | ||
"-U $dbUser " + ` | ||
"-P $dbPassword " + ` | ||
"-Q `"UPDATE CMS_SettingsKey SET KeyValue = N'True' WHERE KeyName = N'CMSEnableCI'`"" | ||
|
||
$updateCommand = "dotnet run " + ` | ||
"--launch-profile $launchProfile " + ` | ||
"-c $configuration " + ` | ||
"--no-build " + ` | ||
"--project $projectPath " + ` | ||
"--kxp-update " + ` | ||
"--skip-confirmation" | ||
|
||
$restoreCommand = "dotnet run " + ` | ||
"--launch-profile $launchProfile " + ` | ||
"-c $configuration " + ` | ||
"--no-build " + ` | ||
"--no-restore " + ` | ||
"--project $projectPath " + ` | ||
"--kxp-ci-restore" | ||
Invoke-ExpressionWithException $restoreCommand | ||
Invoke-ExpressionWithException $turnOffCI | ||
Invoke-ExpressionWithException $updateCommand | ||
Invoke-ExpressionWithException $turnOnCI | ||
# Invoke-ExpressionWithException $storeCommand | ||
|
||
|
||
|
||
Write-Host "`n" | ||
Write-Status 'CI files processed' | ||
Write-Host "`n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# Utilities | ||
|
||
$scriptConfig = @{} | ||
$scriptConfig.WorkspaceFolder = ".." | ||
$scriptConfig.SolutionFileName = "Kentico.Xperience.Zapier.sln" | ||
$scriptConfig.AssemblyName = "DancingGoat" | ||
|
||
<# | ||
.DESCRIPTION | ||
Returns shared configuration for PowerShell scripts | ||
#> | ||
function Get-ScriptConfig { | ||
return $scriptConfig | ||
} | ||
|
||
<# | ||
.DESCRIPTION | ||
Returns the main solution file path | ||
#> | ||
function Get-SolutionPath { | ||
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) $($scriptConfig.SolutionFileName)) | ||
} | ||
|
||
<# | ||
.DESCRIPTION | ||
Returns the web application folder path from the workspace root | ||
#> | ||
function Get-WebProjectPath { | ||
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "examples/DancingGoat") | ||
} | ||
|
||
<# | ||
.DESCRIPTION | ||
Returns the admin application folder path from the workspace root | ||
#> | ||
<#function Get-AdminProjectPath { | ||
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "src/Kentico.Community.Portal.Admin") | ||
}#> | ||
|
||
<# | ||
.DESCRIPTION | ||
Returns the admin client application folder path from the workspace root | ||
#> | ||
<#function Get-AdminClientProjectPath { | ||
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "src/Kentico.Community.Portal.Admin/Client") | ||
}#> | ||
|
||
<# | ||
.DESCRIPTION | ||
Returns the Core project folder path from the workspace root | ||
#> | ||
<#function Get-CoreProjectPath { | ||
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "src/Kentico.Community.Portal.Core") | ||
}#> | ||
|
||
|
||
<# | ||
.DESCRIPTION | ||
Gets the database connection string from the user secrets or appsettings.json file | ||
#> | ||
<#function Get-ConnectionString { | ||
$projectPath = Get-WebProjectPath | ||
# Try to get the connection string from user secrets first | ||
Write-Host "Checking for a connection string user secrets for project: $projectPath" | ||
$connectionString = dotnet user-secrets list --project $projectPath ` | ||
| Select-String -Pattern "ConnectionStrings:" ` | ||
| ForEach-Object { $_.Line -replace '^ConnectionStrings:CMSConnectionString \= ', '' } | ||
if (-not [string]::IsNullOrEmpty($connectionString)) { | ||
Write-Host 'Using ConnectionString from user-secrets' | ||
return $connectionString | ||
} | ||
$appSettingFileName = $Env:ASPNETCORE_ENVIRONMENT -eq "CI" ? 'appsettings.CI.json' : 'appsettings.json' | ||
$jsonFilePath = Join-Path $projectPath $appSettingFileName | ||
Write-Host "Using settings from $jsonFilePath" | ||
if (!(Test-Path $jsonFilePath)) { | ||
throw "Could not find file $jsonFilePath" | ||
} | ||
$appSettingsJson = Get-Content $jsonFilePath | Out-String | ConvertFrom-Json | ||
$connectionString = $appSettingsJson.ConnectionStrings.CMSConnectionString; | ||
if (!$connectionString) { | ||
throw "Connection string not found in $jsonFilePath" | ||
} | ||
return $connectionString; | ||
}#> | ||
|
||
<# | ||
.DESCRIPTION | ||
Ensures the expression successfully exits and throws an exception | ||
with the failed expression if it does not. | ||
#> | ||
function Invoke-ExpressionWithException { | ||
param( | ||
[string]$expression | ||
) | ||
|
||
Write-Host "$expression" | ||
|
||
Invoke-Expression -Command $expression | ||
|
||
if ($LASTEXITCODE -ne 0) { | ||
$errorMessage = "[ $expression ] failed`n`n" | ||
|
||
throw $errorMessage | ||
} | ||
} | ||
function Write-Status { | ||
param( | ||
[string]$message | ||
) | ||
|
||
Write-Host $message -ForegroundColor Blue | ||
} | ||
|
||
function Write-Notification { | ||
param( | ||
[string]$message | ||
) | ||
|
||
Write-Host $message -ForegroundColor Magenta | ||
} | ||
|
||
function Write-Error { | ||
param( | ||
[string]$message | ||
) | ||
|
||
Write-Host $message -ForegroundColor Red | ||
} |