Skip to content

Commit 1944a07

Browse files
Paul Johnsonrasmusjp
authored andcommitted
Setup ci/cd pipeline (#2)
1 parent f409cbc commit 1944a07

File tree

7 files changed

+408
-2
lines changed

7 files changed

+408
-2
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
.vscode/
1111
[Bb]in/
1212
[Oo]bj/
13+
14+
15+
Build/temp
16+
build.out/
17+
build.tmp/

Build/build-bootstrap.ps1

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
# this script should be dot-sourced into the build.ps1 scripts
3+
# right after the parameters declaration
4+
# ie
5+
# . "$PSScriptRoot\build-bootstrap.ps1"
6+
7+
# THIS FILE IS DISTRIBUTED AS PART OF UMBRACO.BUILD
8+
# DO NOT MODIFY IT - ALWAYS USED THE COMMON VERSION
9+
10+
# ################################################################
11+
# BOOTSTRAP
12+
# ################################################################
13+
14+
# reset errors
15+
$error.Clear()
16+
17+
# ensure we have temp folder for downloads
18+
$scriptRoot = "$PSScriptRoot"
19+
$scriptTemp = "$scriptRoot\temp"
20+
if (-not (test-path $scriptTemp)) { mkdir $scriptTemp > $null }
21+
22+
# get NuGet
23+
$cache = 4
24+
$nuget = "$scriptTemp\nuget.exe"
25+
# ensure the correct NuGet-source is used. This one is used by Umbraco
26+
$nugetsourceUmbraco = "https://www.myget.org/F/umbracoprereleases/api/v3/index.json"
27+
if (-not $local)
28+
{
29+
$source = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
30+
if ((test-path $nuget) -and ((ls $nuget).CreationTime -lt [DateTime]::Now.AddDays(-$cache)))
31+
{
32+
Remove-Item $nuget -force -errorAction SilentlyContinue > $null
33+
}
34+
if (-not (test-path $nuget))
35+
{
36+
Write-Host "Download NuGet..."
37+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
38+
Invoke-WebRequest $source -OutFile $nuget
39+
if (-not $?) { throw "Failed to download NuGet." }
40+
}
41+
}
42+
elseif (-not (test-path $nuget))
43+
{
44+
throw "Failed to locate NuGet.exe."
45+
}
46+
47+
# NuGet notes
48+
# As soon as we use -ConfigFile, NuGet uses that file, and only that file, and does not
49+
# merge configuration from system level. See comments in NuGet.Client solution, class
50+
# NuGet.Configuration.Settings, method LoadDefaultSettings.
51+
# For NuGet to merge configurations, it needs to "find" the file in the current directory,
52+
# or above. Which means we cannot really use -ConfigFile but instead have to have Umbraco's
53+
# NuGet.config file at root, and always run NuGet.exe while at root or in a directory below
54+
# root.
55+
56+
$solutionRoot = "$scriptRoot\.."
57+
$testPwd = [System.IO.Path]::GetFullPath($pwd.Path) + "\"
58+
$testRoot = [System.IO.Path]::GetFullPath($solutionRoot) + "\"
59+
if (-not $testPwd.ToLower().StartsWith($testRoot.ToLower()))
60+
{
61+
throw "Cannot run outside of the solution's root."
62+
}
63+
64+
# get the build system
65+
if (-not $local)
66+
{
67+
$params = "-OutputDirectory", $scriptTemp, "-Verbosity", "quiet", "-PreRelease", "-Source", $nugetsourceUmbraco
68+
69+
Write-Host "Executing: $params"
70+
&$nuget install Umbraco.Build @params
71+
if (-not $?) { throw "Failed to download Umbraco.Build." }
72+
}
73+
74+
# ensure we have the build system
75+
$ubuildPath = ls "$scriptTemp\Umbraco.Build.*" | sort -property CreationTime -descending | select -first 1
76+
if (-not $ubuildPath)
77+
{
78+
throw "Failed to locate the build system."
79+
}
80+
81+
# boot the build system
82+
# this creates $global:ubuild
83+
return &"$ubuildPath\ps\Boot.ps1"
84+
85+
# at that point the build.ps1 script must boot the build system
86+
# eg
87+
# $ubuild.Boot($ubuildPath.FullName, [System.IO.Path]::GetFullPath("$scriptRoot\.."),
88+
# @{ Local = $local; With7Zip = $false; WithNode = $false },
89+
# @{ continue = $continue })
90+
# if (-not $?) { throw "Failed to boot the build system." }
91+
#
92+
# and it's good practice to report
93+
# eg
94+
# Write-Host "Umbraco.Whatever Build"
95+
# Write-Host "Umbraco.Build v$($ubuild.BuildVersion)"
96+
97+
# eof

Build/build.ps1

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
2+
param (
3+
# get, don't execute
4+
[Parameter(Mandatory=$false)]
5+
[Alias("g")]
6+
[switch] $get = $false,
7+
8+
# run local, don't download, assume everything is ready
9+
[Parameter(Mandatory=$false)]
10+
[Alias("l")]
11+
[Alias("loc")]
12+
[switch] $local = $false,
13+
14+
# keep the build directories, don't clear them
15+
[Parameter(Mandatory=$false)]
16+
[Alias("c")]
17+
[Alias("cont")]
18+
[switch] $continue = $false
19+
)
20+
21+
# ################################################################
22+
# BOOTSTRAP
23+
# ################################################################
24+
25+
# create and boot the buildsystem
26+
$ubuild = &"$PSScriptRoot\build-bootstrap.ps1"
27+
if (-not $?) { return }
28+
$ubuild.Boot($PSScriptRoot,
29+
@{ Local = $local; },
30+
@{ Continue = $continue })
31+
if ($ubuild.OnError()) { return }
32+
33+
Write-Host "Umbraco.Cloud.StorageProviders.AzureBlob Build"
34+
Write-Host "Umbraco.Build v$($ubuild.BuildVersion)"
35+
36+
# ################################################################
37+
# TASKS
38+
# ################################################################
39+
40+
$ubuild.DefineMethod("CompileUmbracoCloudStorageProvidersAzureBlob",
41+
{
42+
$buildConfiguration = "Release"
43+
44+
$src = "$($this.SolutionRoot)\src"
45+
$log = "$($this.BuildTemp)\dotnet.build.umbraco.log"
46+
47+
if ($this.BuildEnv.VisualStudio -eq $null)
48+
{
49+
throw "Build environment does not provide VisualStudio."
50+
}
51+
52+
Write-Host "Compile Umbraco.Cloud.StorageProviders.AzureBlob"
53+
Write-Host "Logging to $log"
54+
55+
&dotnet build "$src\Umbraco.Cloud.StorageProviders.AzureBlob\Umbraco.Cloud.StorageProviders.AzureBlob.csproj" `
56+
--configuration $buildConfiguration `
57+
--output "$($this.BuildTemp)\bin\\" `
58+
> $log
59+
60+
# get files into WebApp\bin
61+
&dotnet publish "$src\Umbraco.Cloud.StorageProviders.AzureBlob\Umbraco.Cloud.StorageProviders.AzureBlob.csproj" `
62+
--configuration Release --output "$($this.BuildTemp)\WebApp\bin\\" `
63+
> $log
64+
65+
# remove extra files
66+
$webAppBin = "$($this.BuildTemp)\WebApp\bin"
67+
$excludeDirs = @("$($webAppBin)\refs","$($webAppBin)\runtimes","$($webAppBin)\Umbraco","$($webAppBin)\wwwroot")
68+
$excludeFiles = @("$($webAppBin)\appsettings.*","$($webAppBin)\*.deps.json","$($webAppBin)\*.exe","$($webAppBin)\*.config","$($webAppBin)\*.runtimeconfig.json")
69+
$this.RemoveDirectory($excludeDirs)
70+
$this.RemoveFile($excludeFiles)
71+
72+
if (-not $?) { throw "Failed to compile Umbraco.StorageProviders." }
73+
74+
# /p:UmbracoBuild tells the csproj that we are building from PS, not VS
75+
})
76+
77+
78+
$ubuild.DefineMethod("PreparePackages",
79+
{
80+
Write-Host "Prepare Packages"
81+
82+
$src = "$($this.SolutionRoot)\src"
83+
$tmp = "$($this.BuildTemp)"
84+
$out = "$($this.BuildOutput)"
85+
86+
$buildConfiguration = "Release"
87+
88+
# cleanup build
89+
Write-Host "Clean build"
90+
$this.RemoveFile("$tmp\bin\*.dll.config")
91+
92+
# cleanup WebApp
93+
Write-Host "Cleanup WebApp"
94+
$this.RemoveDirectory("$tmp\WebApp")
95+
96+
# offset the modified timestamps on all umbraco dlls, as WebResources
97+
# break if date is in the future, which, due to timezone offsets can happen.
98+
Write-Host "Offset dlls timestamps"
99+
Get-ChildItem -r "$tmp\*.dll" | ForEach-Object {
100+
$_.CreationTime = $_.CreationTime.AddHours(-11)
101+
$_.LastWriteTime = $_.LastWriteTime.AddHours(-11)
102+
}
103+
})
104+
105+
$ubuild.DefineMethod("PrepareBuild",
106+
{
107+
Write-Host "============ PrepareBuild ============"
108+
109+
Write-host "Set environment"
110+
$env:UMBRACO_VERSION=$this.Version.Semver.ToString()
111+
$env:UMBRACO_RELEASE=$this.Version.Release
112+
$env:UMBRACO_COMMENT=$this.Version.Comment
113+
$env:UMBRACO_BUILD=$this.Version.Build
114+
115+
if ($args -and $args[0] -eq "vso")
116+
{
117+
Write-host "Set VSO environment"
118+
# set environment variable for VSO
119+
# https://github.com/Microsoft/vsts-tasks/issues/375
120+
# https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md
121+
Write-Host ("##vso[task.setvariable variable=UMBRACO_VERSION;]$($this.Version.Semver.ToString())")
122+
Write-Host ("##vso[task.setvariable variable=UMBRACO_RELEASE;]$($this.Version.Release)")
123+
Write-Host ("##vso[task.setvariable variable=UMBRACO_COMMENT;]$($this.Version.Comment)")
124+
Write-Host ("##vso[task.setvariable variable=UMBRACO_BUILD;]$($this.Version.Build)")
125+
126+
Write-Host ("##vso[task.setvariable variable=UMBRACO_TMP;]$($this.SolutionRoot)\build.tmp")
127+
}
128+
})
129+
130+
$ubuild.DefineMethod("RestoreNuGet",
131+
{
132+
Write-Host "Restore NuGet"
133+
Write-Host "Logging to $($this.BuildTemp)\nuget.restore.log"
134+
&$this.BuildEnv.NuGet restore "$($this.SolutionRoot)\Umbraco.Cloud.StorageProviders.AzureBlob.sln" > "$($this.BuildTemp)\nuget.restore.log"
135+
if (-not $?) { throw "Failed to restore NuGet packages." }
136+
})
137+
138+
$ubuild.DefineMethod("PackageNuGet",
139+
{
140+
Write-Host "Create NuGet packages"
141+
142+
$log = "$($this.BuildTemp)\dotnet.pack.umbraco.log"
143+
Write-Host "Logging to $log"
144+
145+
&dotnet pack "Umbraco.Cloud.StorageProviders.AzureBlob.sln" `
146+
--output "$($this.BuildOutput)" `
147+
--verbosity detailed `
148+
-c Release `
149+
-p:PackageVersion="$($this.Version.Semver.ToString())" > $log
150+
151+
# run hook
152+
if ($this.HasMethod("PostPackageNuGet"))
153+
{
154+
Write-Host "Run PostPackageNuGet hook"
155+
$this.PostPackageNuGet();
156+
if (-not $?) { throw "Failed to run hook." }
157+
}
158+
})
159+
160+
$ubuild.DefineMethod("Build",
161+
{
162+
$error.Clear()
163+
164+
# $this.PrepareBuild()
165+
# if ($this.OnError()) { return }
166+
$this.RestoreNuGet()
167+
if ($this.OnError()) { return }
168+
$this.CompileUmbracoCloudStorageProvidersAzureBlob()
169+
if ($this.OnError()) { return }
170+
$this.PreparePackages()
171+
if ($this.OnError()) { return }
172+
$this.PackageNuGet()
173+
if ($this.OnError()) { return }
174+
Write-Host "Done"
175+
})
176+
177+
# ################################################################
178+
# RUN
179+
# ################################################################
180+
181+
# configure
182+
$ubuild.ReleaseBranches = @( "master" )
183+
184+
# run
185+
if (-not $get)
186+
{
187+
$ubuild.Build()
188+
if ($ubuild.OnError()) { return }
189+
}
190+
if ($get) { return $ubuild }

NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<packageSources>
44
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
55
<add key="Umbraco Prereleases" value="https://www.myget.org/F/umbracoprereleases/api/v3/index.json" />
6+
<add key="UmbracoStorageProviders@Local" value="https://pkgs.dev.azure.com/umbraco/Umbraco.StorageProviders/_packaging/UmbracoStorageProviders%40Local/nuget/v3/index.json" />
67
</packageSources>
78
</configuration>

0 commit comments

Comments
 (0)