Build - fix build.ps1, build docs

This commit is contained in:
Stephan
2017-07-09 18:46:10 +02:00
parent 59f4fd9713
commit 35c979e33e
7 changed files with 237 additions and 187 deletions

View File

@@ -1,20 +0,0 @@
@ECHO OFF
SETLOCAL
SET release=%1
ECHO Installing Npm NuGet Package
SET nuGetFolder=%CD%\..\src\packages\
ECHO Configured packages folder: %nuGetFolder%
ECHO Current folder: %CD%
%CD%\..\src\.nuget\NuGet.exe install Npm.js -OutputDirectory %nuGetFolder% -Verbosity quiet
for /f "delims=" %%A in ('dir %nuGetFolder%node.js.* /b') do set "nodePath=%nuGetFolder%%%A\"
for /f "delims=" %%A in ('dir %nuGetFolder%npm.js.* /b') do set "npmPath=%nuGetFolder%%%A\tools\"
ECHO Adding Npm and Node to path
REM SETLOCAL is on, so changes to the path not persist to the actual user's path
PATH=%npmPath%;%nodePath%;%PATH%
Powershell.exe -ExecutionPolicy Unrestricted -File .\BuildDocs.ps1

View File

@@ -1,114 +0,0 @@
$PSScriptFilePath = (Get-Item $MyInvocation.MyCommand.Path);
$RepoRoot = (get-item $PSScriptFilePath).Directory.Parent.FullName;
$SolutionRoot = Join-Path -Path $RepoRoot "src";
$ToolsRoot = Join-Path -Path $RepoRoot "tools";
$DocFx = Join-Path -Path $ToolsRoot "docfx\docfx.exe"
$DocFxFolder = (Join-Path -Path $ToolsRoot "docfx")
$DocFxJson = Join-Path -Path $RepoRoot "apidocs\docfx.json"
$7Zip = Join-Path -Path $ToolsRoot "7zip\7za.exe"
$DocFxSiteOutput = Join-Path -Path $RepoRoot "apidocs\_site\*.*"
$NgDocsSiteOutput = Join-Path -Path $RepoRoot "src\Umbraco.Web.UI.Client\docs\api\*.*"
$ProgFiles86 = [Environment]::GetEnvironmentVariable("ProgramFiles(x86)");
$MSBuild = "$ProgFiles86\MSBuild\14.0\Bin\MSBuild.exe"
################ Do the UI docs
"Changing to Umbraco.Web.UI.Client folder"
cd ..
cd src\Umbraco.Web.UI.Client
Write-Host $(Get-Location)
"Creating build folder so MSBuild doesn't run the whole grunt build"
if (-Not (Test-Path "build")) {
md "build"
}
"Installing node"
# Check if Install-Product exists, should only exist on the build server
if (Get-Command Install-Product -errorAction SilentlyContinue)
{
Install-Product node ''
}
"Installing node modules"
& npm install
"Installing grunt"
& npm install -g grunt-cli
"Moving back to build folder"
cd ..
cd ..
cd build
Write-Host $(Get-Location)
& grunt --gruntfile ../src/umbraco.web.ui.client/gruntfile.js docs
# change baseUrl
$BaseUrl = "https://our.umbraco.org/apidocs/ui/"
$IndexPath = "../src/umbraco.web.ui.client/docs/api/index.html"
(Get-Content $IndexPath).replace('location.href.replace(rUrl, indexFile)', "`'" + $BaseUrl + "`'") | Set-Content $IndexPath
# zip it
& $7Zip a -tzip ui-docs.zip $NgDocsSiteOutput -r
################ Do the c# docs
# Build the solution in debug mode
$SolutionPath = Join-Path -Path $SolutionRoot -ChildPath "umbraco.sln"
# Go get nuget.exe if we don't hae it
$NuGet = "$ToolsRoot\nuget.exe"
$FileExists = Test-Path $NuGet
If ($FileExists -eq $False) {
Write-Host "Retrieving nuget.exe..."
$SourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
Invoke-WebRequest $SourceNugetExe -OutFile $NuGet
}
#restore nuget packages
Write-Host "Restoring nuget packages..."
& $NuGet restore $SolutionPath
& $MSBuild "$SolutionPath" /p:Configuration=Debug /maxcpucount /t:Clean
if (-not $?)
{
throw "The MSBuild process returned an error code."
}
& $MSBuild "$SolutionPath" /p:Configuration=Debug /maxcpucount
if (-not $?)
{
throw "The MSBuild process returned an error code."
}
# Go get docfx if we don't hae it
$FileExists = Test-Path $DocFx
If ($FileExists -eq $False) {
If(!(Test-Path $DocFxFolder))
{
New-Item $DocFxFolder -type directory
}
$DocFxZip = Join-Path -Path $ToolsRoot "docfx\docfx.zip"
$DocFxSource = "https://github.com/dotnet/docfx/releases/download/v1.9.4/docfx.zip"
Invoke-WebRequest $DocFxSource -OutFile $DocFxZip
#unzip it
& $7Zip e $DocFxZip "-o$DocFxFolder"
}
#clear site
If(Test-Path(Join-Path -Path $RepoRoot "apidocs\_site"))
{
Remove-Item $DocFxSiteOutput -recurse
}
# run it!
& $DocFx metadata $DocFxJson
& $DocFx build $DocFxJson
# zip it
& $7Zip a -tzip csharp-docs.zip $DocFxSiteOutput -r

View File

@@ -0,0 +1,110 @@
#
function Build-UmbracoDocs
{
$uenv = Get-UmbracoBuildEnv
$src = "$($uenv.SolutionRoot)\src"
$out = "$($uenv.SolutionRoot)\build.out"
$tmp = "$($uenv.SolutionRoot)\build.tmp"
$buildTemp = "$PSScriptRoot\temp"
$cache = 2
Prepare-Build -keep $uenv
################ Do the UI docs
# create Belle build folder, so that we don't cause a Belle rebuild
$belleBuildDir = "$src\Umbraco.Web.UI.Client\build"
if (-not (Test-Path $belleBuildDir))
{
mkdir $belleBuildDir > $null
}
Write-Host "Build UI documentation"
push-location "$src\Umbraco.Web.UI.Client"
$p = $env:path
$env:path = $uenv.NpmPath + ";" + $uenv.NodePath + ";" + $env:path
write "cache clean" > $tmp\belle-docs.log
&npm cache clean --quiet >> $tmp\belle-docs.log 2>&1
&npm install --quiet >> $tmp\belle-docs.log 2>&1
&npm install -g grunt-cli --quiet >> $tmp\belle-docs.log 2>&1
#&npm install -g bower --quiet >> $tmp\belle.log 2>&1
#&grunt build --buildversion=$version.Release >> $tmp\belle.log 2>&1
&grunt --gruntfile "$src/Umbraco.Web.UI.Client/gruntfile.js" docs >> $tmp\belle-docs.log 2>&1
# fixme - should we filter the log to find errors?
#get-content .\build.tmp\belle-docs.log | %{ if ($_ -match "build") { write $_}}
# change baseUrl
$baseUrl = "https://our.umbraco.org/apidocs/ui/"
$indexPath = "$src/Umbraco.Web.UI.Client/docs/api/index.html"
(Get-Content $indexPath).Replace("location.href.replace(rUrl, indexFile)", "'$baseUrl'") `
| Set-Content $indexPath
pop-location
$env:path = $p
# zip
&$uenv.Zip a -tzip -r "$out\ui-docs.zip" "$src\Umbraco.Web.UI.Client\docs\api\*.*" `
> $null
################ Do the c# docs
Write-Host "Build C# documentation"
# Build the solution in debug mode
# FIXME no only a simple compilation should be enough!
# FIXME we MUST handle msbuild & co error codes!
# FIXME deal with weird things in gitconfig?
#Build-Umbraco -Configuration Debug
Restore-NuGet $uenv
Compile-Umbraco $uenv "Debug" # FIXME different log file!
Restore-WebConfig "$src\Umbraco.Web.UI"
# ensure we have docfx
Get-DocFx $uenv $buildTemp
# clear
$docFxOutput = "$($uenv.SolutionRoot)\apidocs\_site"
if (test-path($docFxOutput))
{
Remove-Directory $docFxOutput
}
# run
$docFxJson = "$($uenv.SolutionRoot)\apidocs\docfx.json"
push-location "$($uenv.SolutionRoot)\build" # silly docfx.json wants this
Write-Host "Run DocFx metadata"
Write-Host "Logging to $tmp\docfx.metadata.log"
&$uenv.DocFx metadata $docFxJson > "$tmp\docfx.metadata.log"
Write-Host "Run DocFx build"
Write-Host "Logging to $tmp\docfx.build.log"
&$uenv.DocFx build $docFxJson > "$tmp\docfx.build.log"
pop-location
# zip
&$uenv.Zip a -tzip -r "$out\csharp-docs.zip" "$docFxOutput\*.*" `
> $null
}
function Get-DocFx($uenv, $buildTemp)
{
$docFx = "$buildTemp\docfx"
if (-not (test-path $docFx))
{
Write-Host "Download DocFx..."
$source = "https://github.com/dotnet/docfx/releases/download/v2.19.2/docfx.zip"
$client = new-object Net.WebClient
$client.DownloadFile($source, "$buildTemp\docfx.zip")
&$uenv.Zip x "$buildTemp\docfx.zip" -o"$buildTemp\docfx" -aos > $nul
Remove-File "$buildTemp\docfx.zip"
}
$uenv | add-member -memberType NoteProperty -name DocFx -value "$docFx\docfx.exe"
}

View File

@@ -21,13 +21,19 @@
. "$PSScriptRoot\Set-UmbracoVersion.ps1"
. "$PSScriptRoot\Get-UmbracoVersion.ps1"
. "$PSScriptRoot\Build-UmbracoDocs.ps1"
#
# Prepares the build
#
function Prepare-Build
{
param (
$uenv # an Umbraco build environment (see Get-UmbracoBuildEnv)
$uenv, # an Umbraco build environment (see Get-UmbracoBuildEnv)
[Alias("k")]
[switch]
$keep = $false
)
Write-Host ">> Prepare Build"
@@ -42,35 +48,18 @@ function Prepare-Build
Remove-Directory "$src\Umbraco.Web.UI.Client\build"
Remove-Directory "$src\Umbraco.Web.UI.Client\bower_components"
Remove-Directory "$tmp"
mkdir "$tmp" > $null
Remove-Directory "$out"
mkdir "$out" > $null
# prepare web.config
$webUi = "$src\Umbraco.Web.UI"
if (test-path "$webUi\web.config")
if (-not $keep)
{
if (test-path "$webUi\web.config.temp-build")
{
Write-Host "Found existing web.config.temp-build"
$i = 0
while (test-path "$webUi\web.config.temp-build.$i")
{
$i = $i + 1
}
Write-Host "Save existing web.config as web.config.temp-build.$i"
Write-Host "(WARN: the original web.config.temp-build will be restored during post-build)"
mv "$webUi\web.config" "$webUi\web.config.temp-build.$i"
}
else
{
Write-Host "Save existing web.config as web.config.temp-build"
Write-Host "(will be restored during post-build)"
mv "$webUi\web.config" "$webUi\web.config.temp-build"
}
Remove-Directory "$tmp"
mkdir "$tmp" > $null
Remove-Directory "$out"
mkdir "$out" > $null
}
# ensure proper web.config
$webUi = "$src\Umbraco.Web.UI"
Store-WebConfig $webUi
Write-Host "Create clean web.config"
Copy-File "$webUi\web.Template.config" "$webUi\web.config"
}
@@ -125,14 +114,13 @@ function Compile-Belle
function Compile-Umbraco
{
param (
$uenv # an Umbraco build environment (see Get-UmbracoBuildEnv)
$uenv, # an Umbraco build environment (see Get-UmbracoBuildEnv)
[string] $buildConfiguration = "Release"
)
$src = "$($uenv.SolutionRoot)\src"
$tmp = "$($uenv.SolutionRoot)\build.tmp"
$out = "$($uenv.SolutionRoot)\build.out"
$buildConfiguration = "Release"
if ($uenv.VisualStudio -eq $null)
{
@@ -179,7 +167,7 @@ function Compile-Umbraco
/p:UmbracoBuild=True `
> $tmp\msbuild.compat7.log
# /p:UmbracoBuild tells the csproj that we are building from PS
# /p:UmbracoBuild tells the csproj that we are building from PS
}
#
@@ -238,7 +226,8 @@ function Compile-Tests
$toolsVersion = "15.0"
}
Write-Host ">> Compile Tests (logging to $tmp\msbuild.tests.log)"
Write-Host ">> Compile Tests"
Write-Host "Logging to $tmp\msbuild.tests.log"
# beware of the weird double \\ at the end of paths
# see http://edgylogic.com/blog/powershell-and-external-commands-done-right/
@@ -277,13 +266,7 @@ function Prepare-Packages
$buildConfiguration = "Release"
# restore web.config
$webUi = "$src\Umbraco.Web.UI"
if (test-path "$webUi\web.config.temp-build")
{
Write-Host "Restoring existing web.config"
Remove-File "$webUi\web.config"
mv "$webUi\web.config.temp-build" "$webUi\web.config"
}
Restore-WebConfig "$src\Umbraco.Web.UI"
# cleanup build
Write-Host "Clean build"
@@ -417,11 +400,13 @@ function Restore-NuGet
$uenv # an Umbraco build environment (see Get-UmbracoBuildEnv)
)
Write-Host ">> Restore NuGet"
$src = "$($uenv.SolutionRoot)\src"
$tmp = "$($uenv.SolutionRoot)\build.tmp"
Write-Host ">> Restore NuGet"
Write-Host "Logging to $tmp\nuget.restore.log"
&$uenv.NuGet restore "$src\Umbraco.sln"
&$uenv.NuGet restore "$src\Umbraco.sln" > "$tmp\nuget.restore.log"
}
#
@@ -470,11 +455,13 @@ function Build-Umbraco
[CmdletBinding()]
param (
[string]
$target = "all"
$target = "all",
[string]
$buildConfiguration = "Release"
)
$target = $target.ToLowerInvariant()
Write-Host ">> Build-Umbraco <$target>"
Write-Host ">> Build-Umbraco <$target> <$configuration>"
Write-Host "Get Build Environment"
$uenv = Get-UmbracoBuildEnv
@@ -514,7 +501,7 @@ function Build-Umbraco
}
elseif ($target -eq "compile-umbraco")
{
Compile-Umbraco $uenv
Compile-Umbraco $uenv $buildConfiguration
}
elseif ($target -eq "pre-packages")
{
@@ -541,7 +528,7 @@ function Build-Umbraco
Prepare-Build $uenv
Restore-NuGet $uenv
Compile-Belle $uenv $version
Compile-Umbraco $uenv
Compile-Umbraco $uenv $buildConfiguration
Prepare-Tests $uenv
Compile-Tests $uenv
# not running tests...
@@ -563,5 +550,6 @@ Export-ModuleMember -function Get-UmbracoBuildEnv
Export-ModuleMember -function Set-UmbracoVersion
Export-ModuleMember -function Get-UmbracoVersion
Export-ModuleMember -function Build-Umbraco
Export-ModuleMember -function Build-UmbracoDocs
#eof

View File

@@ -81,3 +81,40 @@ function Replace-FileText($filename, $source, $replacement)
$utf8bom = New-Object System.Text.UTF8Encoding $true
[System.IO.File]::WriteAllText($filepath, $text, $utf8bom)
}
# store web.config
function Store-WebConfig($webUi)
{
if (test-path "$webUi\web.config")
{
if (test-path "$webUi\web.config.temp-build")
{
Write-Host "Found existing web.config.temp-build"
$i = 0
while (test-path "$webUi\web.config.temp-build.$i")
{
$i = $i + 1
}
Write-Host "Save existing web.config as web.config.temp-build.$i"
Write-Host "(WARN: the original web.config.temp-build will be restored during post-build)"
mv "$webUi\web.config" "$webUi\web.config.temp-build.$i"
}
else
{
Write-Host "Save existing web.config as web.config.temp-build"
Write-Host "(will be restored during post-build)"
mv "$webUi\web.config" "$webUi\web.config.temp-build"
}
}
}
# restore web.config
function Restore-WebConfig($webUi)
{
if (test-path "$webUi\web.config.temp-build")
{
Write-Host "Restoring existing web.config"
Remove-File "$webUi\web.config"
mv "$webUi\web.config.temp-build" "$webUi\web.config"
}
}

View File

@@ -2,14 +2,29 @@ Umbraco Cms Build
--
----
# Quick!
To build Umbraco, fire PowerShell and move to Umbraco's repository root (the directory that contains `src`, `build`, `README.md`...). There, trigger the build with the following command:
build\build.ps1
By default, this builds the current version. It is possible to specify a different version as a parameter to the build script:
build\build.ps1 7.6.44
Valid version strings are defined in the `Set-UmbracoVersion` documentation below.
# Build
The Umbraco Build solution relies on a PowerShell module. The module needs to be imported into PowerShell. From within the solution directory:
The Umbraco Build solution relies on a PowerShell module. The module needs to be imported into PowerShell. From within Umbraco's repository root:
$env:PSModulePath = "$pwd\build\Modules\;$env:PSModulePath"
Import-Module Umbraco.Build -Force -DisableNameChecking
build\build.ps1 -ModuleOnly
Once the module has been imported, a set of commands are added to PowerShell, and detailed below.
Or the abbreviated form:
build\build.ps1 -mo
Once the module has been imported, a set of commands are added to PowerShell.
## Get-UmbracoBuildEnv
@@ -79,6 +94,14 @@ Some log files, such as MsBuild logs, are produced in `build.tmp` too. The `buil
Building Umbraco requires a clean `web.config` file in the `Umbraco.Web.UI` project. If a `web.config` file already exists, the `pre-build` task (see below) will save it as `web.config.temp-build` and replace it with a clean copy of `web.Template.config`. The original file is replaced once it is safe to do so, by the `pre-packages` task.
## Build-UmbracoDocs
Builds umbraco documentation. Temporary files are generated in `build.tmp` while the actual artifacts (docs...) are produced in `build.out`. Example:
Build-UmbracoDocs
Some log files, such as MsBuild logs, are produced in `build.tmp` too. The `build` directory should remain clean during a build.
# VSTS
Continuous integration, nightly builds and release builds run on VSTS.

View File

@@ -1,7 +1,12 @@
param (
[Parameter(Mandatory=$false)]
[string]
$version
$version,
[Parameter(Mandatory=$false)]
[Alias("mo")]
[switch]
$moduleOnly = $false
)
# the script can run either from the solution root,
@@ -18,7 +23,7 @@ else
# look for the module and throw if not found
if (-not [System.IO.Directory]::Exists($mpath + "Umbraco.Build"))
{
Write-Error "Could not locate Umbraco.Build Powershell module."
Write-Error "Could not locate Umbraco build Powershell module."
break
}
@@ -29,13 +34,34 @@ if (-not $env:PSModulePath.Contains($mpath))
}
# force-import (or re-import) the module
Write-Host "Import Umbraco build Powershell module"
Import-Module Umbraco.Build -Force -DisableNameChecking
# module only?
if ($moduleOnly)
{
if (-not [string]::IsNullOrWhiteSpace($version))
{
Write-Host "(module only: ignoring version parameter)"
}
else
{
Write-Host "(module only)"
}
break
}
# get build environment
Write-Host "Setup Umbraco build Environment"
$uenv = Get-UmbracoBuildEnv
# set the version if any
if (-not [string]::IsNullOrWhiteSpace($version))
{
Write-Host "Set Umbraco version to $version"
Set-UmbracoVersion $version
}
# full umbraco build
Write-Host "Build Umbraco"
Build-Umbraco