Last active
May 23, 2021 06:01
-
-
Save cassidydotdk/c6b94513ee5d94f5a332a8d09519f0f7 to your computer and use it in GitHub Desktop.
Complete Build and Publish Script. Will deploy all projects to publishing target, no HPP required.
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
param( | |
[Parameter()] | |
[switch]$NoBuild, | |
[Parameter()] | |
[switch]$NoSync, | |
[Parameter()] | |
[string]$CmHost="https://habitatstarterkit.local", | |
[Parameter()] | |
[string]$SolutionName="HabitatStarterKit.sln", | |
[Parameter()] | |
[ValidateSet("Debug", "Release")] | |
[string]$BuildConfiguration="Debug" | |
) | |
$ErrorActionPreference = "Stop" | |
if(!$NoBuild) | |
{ | |
$vssetup = Get-Module -ListAvailable -Name VSSetup | |
if(-Not $vssetup) | |
{ | |
Write-Host "`nInstalling Visual Studio Locator..`n" -ForegroundColor DarkGray | |
Install-Module VSSetup | |
} | |
$vsversion = Get-VSSetupInstance -All | Select-VSSetupInstance -Latest | |
if(-Not $vsversion) | |
{ | |
Write-Host "Could not locate MSBuild. Did you follow all the prerequisite installation steps?" -ForegroundColor Red | |
Exit | |
} | |
$msbuild = $vsversion.InstallationPath + "\MSBuild\Current\Bin\MSBuild.exe" | |
Write-Host "`nBuilding with MSBuild..`n" -ForegroundColor DarkGray | |
& $msbuild $SolutionName -t:restore,build -p:RestorePackagesConfig=true ` | |
/p:Configuration=$BuildConfiguration /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish ` | |
/p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=false ` | |
/p:publishUrl=$PSScriptRoot\data\cm\website | |
} | |
if(!$NoSync) | |
{ | |
Import-Module $PSScriptRoot\tools\config.psm1 | |
$SharedSecret = Get-EnvVar "UNICORN_SHARED_SECRET" | |
if (-Not $SharedSecret) | |
{ | |
Write-Host "UNICORN_SHARED_SECRET not defined in .env file" -ForegroundColor Red | |
Exit | |
} | |
Write-Host "`nWarming up Sitecore..." -ForegroundColor DarkGray | |
Invoke-WebRequest $CmHost -UseBasicParsing | out-null | |
Write-Host "Warmed up!`n" | |
Write-Host "`nSyncing with Unicorn..." -ForegroundColor DarkGray | |
Import-Module $PSScriptRoot\packages\Unicorn.4.1.4\tools\PSAPI\Unicorn.psm1 | |
$controlPanelUrl = $CmHost + "/unicorn.aspx" | |
Sync-Unicorn -ControlPanelUrl $controlPanelUrl -SharedSecret $SharedSecret | |
} |
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
function Get-EnvVar { | |
param( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$Key | |
) | |
select-string -Path ".env" -Pattern "^$Key=(.+)$" | % { $_.Matches.Groups[1].Value } | |
} | |
function Read-UserEnvFile { | |
param( | |
[Parameter()] | |
[string] $EnvFile = ".env.user" | |
) | |
if (Test-Path $EnvFile) { | |
Write-Host "User specific .env file found. Starting Docker with custom user settings." -ForegroundColor Green | |
Write-Host "Variable overrides:-" -ForegroundColor Yellow | |
Get-Content $EnvFile | Where-Object { $_ -notmatch '^#.*' -and $_ -notmatch '^\s*$' } | ForEach-Object { | |
$var, $val = $_.trim().Split('=') | |
Write-Host " $var=$val" -ForegroundColor Yellow | |
Set-Item -Path "env:$($var)" -Value $val | |
} | |
} | |
} | |
Export-ModuleMember -Function * |
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
(just snippets) | |
environment: | |
UNICORN_SHARED_SECRET: ${UNICORN_SHARED_SECRET} | |
volumes: | |
- .\unicorn:C:\inetpub\wwwroot\App_Data\unicorn |
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
$vssetup = Get-Module -ListAvailable -Name VSSetup | |
if(-Not $vssetup) | |
{ | |
Write-Host "`nInstalling Visual Studio Locator..`n" -ForegroundColor DarkGray | |
Install-Module VSSetup | |
} | |
$vsversion = Get-VSSetupInstance -All | Select-VSSetupInstance -Latest | |
if(-Not $vsversion) | |
{ | |
Write-Host "Could not locate MSBuild. Did you follow all the prerequisite installation steps?" -ForegroundColor Red | |
Exit | |
} | |
$msbuild = $vsversion.InstallationPath + "\MSBuild\Current\Bin\MSBuild.exe" |
Nuget package restore and build reference: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restoring-and-building-with-one-msbuild-command
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Config.psm1 sourced from here https://github.com/konabos/konabos-docker-examples/blob/master/sitecore-xp0-sxa-jss/docker/tools/util.psm1