Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@cassidydotdk cassidydotdk commented May 19, 2021

Get-VSSetupInstance -All

InstanceId          : 8631dbc0
DisplayName         : Visual Studio Professional 2019
InstallationVersion : 16.9.31205.134
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional
InstallDate         : 25/03/2021 14:16:54

InstanceId          : 8826a071
DisplayName         : Visual Studio Build Tools 2019
InstallationVersion : 16.9.31205.134
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
InstallDate         : 25/03/2021 14:11:03
@cassidydotdk

This comment has been minimized.

Copy link
Owner Author

@cassidydotdk cassidydotdk commented May 19, 2021

@cassidydotdk

This comment has been minimized.

@cassidydotdk

This comment has been minimized.

Copy link
Owner Author

@cassidydotdk cassidydotdk commented May 20, 2021

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