Skip to content

Instantly share code, notes, and snippets.

@cassidydotdk
Last active May 23, 2021 06:01
Show Gist options
  • Save cassidydotdk/c6b94513ee5d94f5a332a8d09519f0f7 to your computer and use it in GitHub Desktop.
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.
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
}
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 *
(just snippets)
environment:
UNICORN_SHARED_SECRET: ${UNICORN_SHARED_SECRET}
volumes:
- .\unicorn:C:\inetpub\wwwroot\App_Data\unicorn
$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"
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<unicorn>
<authenticationProvider>
<SharedSecret>$(env:UNICORN_SHARED_SECRET)</SharedSecret>
<!--
Writes the reason why failed automated tool authentications failed to the Sitecore logs.
Will result in writing your shared secret to the logs as part of the signature base,
so disable it unless you're debugging failed authentications.
-->
<WriteAuthFailuresToLog>false</WriteAuthFailuresToLog>
</authenticationProvider>
</unicorn>
</sitecore>
</configuration>
@cassidydotdk
Copy link
Author

cassidydotdk commented May 19, 2021

@cassidydotdk
Copy link
Author

@cassidydotdk
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment