Skip to content

Commit

Permalink
Shazwazza#361 - Features include:
Browse files Browse the repository at this point in the history
- Removal of createdPackages.config and packageManifest.xml in favor of package.xml (umbPack default package configuration file)
- Update of build.yml to use umbPack
- update of build.ps1 to use umbPack
  • Loading branch information
mbogunovic committed Jun 4, 2021
1 parent 70fe5c4 commit 5cf06a4
Show file tree
Hide file tree
Showing 8 changed files with 649 additions and 887 deletions.
85 changes: 13 additions & 72 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,80 +69,21 @@ jobs:
$ReleaseFolder = Get-Item $Env:RELEASE_FOLDER
$WebProjFolder = Get-Item $Env:WEB_PROJ_FOLDER
$TempFolder = Join-Path -Path $ReleaseFolder -ChildPath "Temp";
# Ensure umbPack is installed
$IsUmbPackInstalled = dotnet tool update -g Umbraco.Tools.Packages
# Set the version number in createdPackages.config
$CreatedPackagesConfig = Join-Path -Path $BuildFolder -ChildPath "createdPackages.config"
$CreatedPackagesConfigXML = [xml](Get-Content $CreatedPackagesConfig)
$CreatedPackagesConfigXML.packages.package.version = "$Env:GITVERSION_MAJORMINORPATCH"
$CreatedPackagesConfigXML.Save($CreatedPackagesConfig)
#copy the orig manifest to temp location to be updated to be used for the package
$PackageManifest = Join-Path -Path $BuildFolder -ChildPath "packageManifest.xml"
New-Item -ItemType Directory -Path $TempFolder
Copy-Item $PackageManifest "$TempFolder\package.xml"
$PackageManifest = (Join-Path -Path $TempFolder -ChildPath "package.xml")
# Set the data in packageManifest.config
$PackageManifestXML = [xml](Get-Content $PackageManifest)
$PackageManifestXML.umbPackage.info.package.version = "$Env:GITVERSION_MAJORMINORPATCH"
$PackageManifestXML.umbPackage.info.package.name = $CreatedPackagesConfigXML.packages.package.name
$PackageManifestXML.umbPackage.info.package.license.set_InnerXML($CreatedPackagesConfigXML.packages.package.license.get_InnerXML())
$PackageManifestXML.umbPackage.info.package.license.url = $CreatedPackagesConfigXML.packages.package.license.url
$PackageManifestXML.umbPackage.info.package.url = $CreatedPackagesConfigXML.packages.package.url
$PackageManifestXML.umbPackage.info.author.name = $CreatedPackagesConfigXML.packages.package.author.get_InnerXML()
$PackageManifestXML.umbPackage.info.author.website = $CreatedPackagesConfigXML.packages.package.author.url
#clear the files from the manifest
$NewFilesXML = $PackageManifestXML.CreateElement("files")
#package the files ... This will lookup all files in the file system that need to be there and update
# the package manifest XML with the correct data along with copying these files to the temp folder
# so they can be zipped with the package
Function WritePackageFile ($f)
{
Write-Host $f.FullName -foregroundcolor cyan
$NewFileXML = $PackageManifestXML.CreateElement("file")
$NewFileXML.set_InnerXML("<guid></guid><orgPath></orgPath><orgName></orgName>")
$GuidName = ([guid]::NewGuid()).ToString() + "_" + $f.Name
$NewFileXML.guid = $GuidName
$NewFileXML.orgPath = ReverseMapPath $f
$NewFileXML.orgName = $f.Name
$NewFilesXML.AppendChild($NewFileXML)
Copy-Item $f.FullName "$TempFolder\$GuidName"
if(-not $IsUmbPackInstalled){
dotnet tool install -g Umbraco.Tools.Packages
}
Function ReverseMapPath ($f)
{
$resultPath = "~"+ $f.Directory.FullName.Replace($WebProjFolder, "").Replace("\","/")
Return $resultPath
}
Function MapPath ($f)
{
$resultPath = Join-Path -Path $WebProjFolder -ChildPath ($f.Replace("~", "").Replace("/", "\"))
Return $resultPath
}
foreach($FileXML in $CreatedPackagesConfigXML.packages.package.files.file)
{
$File = Get-Item (MapPath $FileXML)
if ($File -is [System.IO.DirectoryInfo])
{
Get-ChildItem -path $File -Recurse `
| Where-Object { $_ -isnot [System.IO.DirectoryInfo]} `
| ForEach-Object { WritePackageFile($_) } `
| Out-Null
}
else {
WritePackageFile($File)| Out-Null
}
}
$PackageManifestXML.umbPackage.ReplaceChild($NewFilesXML, $PackageManifestXML.SelectSingleNode("/umbPackage/files")) | Out-Null
$PackageManifestXML.Save($PackageManifest)
#zip the package
$DestZIP = "$ReleaseFolder\Articulate_$Env:GITVERSION_SEMVER.zip"
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($TempFolder, $DestZIP)
# Set the version number in package.xml
$PackageConfig = Join-Path -Path $BuildFolder -ChildPath "package.xml"
$PackageConfigXML = [xml](Get-Content $PackageConfig)
$PackageConfigXML.umbPackage.info.package.version = "$Env:GITVERSION_MAJORMINORPATCH"
$PackageConfigXML.Save($PackageConfig)
$DestinationPath = "$ReleaseFolder\Articulate_$Env:GITVERSION_SEMVER.zip"
umbpack pack $PackageConfig -o $ReleaseFolder -v $Env:GITVERSION_MAJORMINORPATCH -n "Articulate_${Env:GITVERSION_SEMVER}.zip"
- uses: actions/upload-artifact@v2
with:
Expand Down
149 changes: 11 additions & 138 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,156 +12,29 @@ param (
$PSScriptFilePath = Get-Item $MyInvocation.MyCommand.Path
$RepoRoot = $PSScriptFilePath.Directory.Parent.FullName
$BuildFolder = Join-Path -Path $RepoRoot -ChildPath "build";
$WebProjFolder = Join-Path -Path $RepoRoot -ChildPath "src\Articulate.Web";
$ReleaseFolder = Join-Path -Path $BuildFolder -ChildPath "Release";
$TempFolder = Join-Path -Path $ReleaseFolder -ChildPath "Temp";
$PackageFilePath = Join-Path -Path $BuildFolder -ChildPath "package.xml"
$SolutionRoot = Join-Path -Path $RepoRoot "src";

# Go get nuget.exe if we don't hae it
$NuGet = "$BuildFolder\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
}

# ensure we have vswhere
New-Item "$BuildFolder\vswhere" -type directory -force
$vswhere = "$BuildFolder\vswhere.exe"
if (-not (test-path $vswhere))
{
Write-Host "Download VsWhere..."
$path = "$ToolsFolder\tmp"
&$nuget install vswhere -OutputDirectory $path
$dir = ls "$path\vswhere.*" | sort -property Name -descending | select -first 1
$file = ls -path "$dir" -name vswhere.exe -recurse
mv "$dir\$file" $vswhere
}
# Ensure umbPack is installed
$IsUmbPackInstalled = dotnet tool update -g Umbraco.Tools.Packages

$MSBuild = &$vswhere -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1
if (-not (test-path $MSBuild)) {
throw "MSBuild not found!"
if(-not $IsUmbPackInstalled){
dotnet tool install -g Umbraco.Tools.Packages
}


if ((Get-Item $ReleaseFolder -ErrorAction SilentlyContinue) -ne $null)
{
Write-Warning "$ReleaseFolder already exists on your local machine. It will now be deleted."
Remove-Item $ReleaseFolder -Recurse
}

####### DO THE SLN BUILD PART #############

# Set the version number in SolutionInfo.cs
$SolutionInfoPath = Join-Path -Path $SolutionRoot -ChildPath "SolutionInfo.cs"
(gc -Path $SolutionInfoPath) `
-replace "(?<=Version\(`")[.\d]*(?=`"\))", $ReleaseVersionNumber |
Set-Content -Path $SolutionInfoPath -Encoding UTF8
(gc -Path $SolutionInfoPath) `
-replace "(?<=AssemblyInformationalVersion\(`")[.\w-]*(?=`"\))", "$ReleaseVersionNumber$PreReleaseName" |
Set-Content -Path $SolutionInfoPath -Encoding UTF8
# Set the copyright
$Copyright = "Copyright " + [char]0x00A9 + " Shannon Deminick " + (Get-Date).year
(gc -Path $SolutionInfoPath) `
-replace "(?<=AssemblyCopyright\(`").*(?=`"\))", $Copyright |
Set-Content -Path $SolutionInfoPath -Encoding UTF8;

# Build the solution in release mode
$SolutionPath = Join-Path -Path $SolutionRoot -ChildPath "Articulate.sln";

#restore nuget packages
Write-Host "Restoring nuget packages..."
& $NuGet restore $SolutionPath

# clean sln for all deploys
& $MSBuild "$SolutionPath" /p:Configuration=Release /maxcpucount /t:Clean
if (-not $?)
{
throw "The MSBuild process returned an error code."
}

#build
& $MSBuild "$SolutionPath" /p:Configuration=Release /maxcpucount
if (-not $?)
{
throw "The MSBuild process returned an error code."
}

####### DO THE UMBRACO PACKAGE BUILD #############

# Set the version number in createdPackages.config
$CreatedPackagesConfig = Join-Path -Path $BuildFolder -ChildPath "createdPackages.config"
$CreatedPackagesConfigXML = [xml](Get-Content $CreatedPackagesConfig)
$CreatedPackagesConfigXML.packages.package.version = "$ReleaseVersionNumber"
$CreatedPackagesConfigXML.Save($CreatedPackagesConfig)

#copy the orig manifest to temp location to be updated to be used for the package
$PackageManifest = Join-Path -Path $BuildFolder -ChildPath "packageManifest.xml"
New-Item -ItemType Directory -Path $TempFolder
Copy-Item $PackageManifest "$TempFolder\package.xml"
$PackageManifest = (Join-Path -Path $TempFolder -ChildPath "package.xml")

# Set the data in packageManifest.config
$PackageManifestXML = [xml](Get-Content $PackageManifest)
$PackageManifestXML.umbPackage.info.package.version = "$ReleaseVersionNumber"
$PackageManifestXML.umbPackage.info.package.name = $CreatedPackagesConfigXML.packages.package.name
$PackageManifestXML.umbPackage.info.package.license.set_InnerXML($CreatedPackagesConfigXML.packages.package.license.get_InnerXML())
$PackageManifestXML.umbPackage.info.package.license.url = $CreatedPackagesConfigXML.packages.package.license.url
$PackageManifestXML.umbPackage.info.package.url = $CreatedPackagesConfigXML.packages.package.url
$PackageManifestXML.umbPackage.info.author.name = $CreatedPackagesConfigXML.packages.package.author.get_InnerXML()
$PackageManifestXML.umbPackage.info.author.website = $CreatedPackagesConfigXML.packages.package.author.url

#clear the files from the manifest
$NewFilesXML = $PackageManifestXML.CreateElement("files")

#package the files ... This will lookup all files in the file system that need to be there and update
# the package manifest XML with the correct data along with copying these files to the temp folder
# so they can be zipped with the package

Function WritePackageFile ($f)
{
Write-Host $f.FullName -foregroundcolor cyan
$NewFileXML = $PackageManifestXML.CreateElement("file")
$NewFileXML.set_InnerXML("<guid></guid><orgPath></orgPath><orgName></orgName>")
$GuidName = ([guid]::NewGuid()).ToString() + "_" + $f.Name
$NewFileXML.guid = $GuidName
$NewFileXML.orgPath = ReverseMapPath $f
$NewFileXML.orgName = $f.Name
$NewFilesXML.AppendChild($NewFileXML)
Copy-Item $f.FullName "$TempFolder\$GuidName"
}
Function ReverseMapPath ($f)
{
$resultPath = "~"+ $f.Directory.FullName.Replace($WebProjFolder, "").Replace("\","/")
Return $resultPath
}
Function MapPath ($f)
{
$resultPath = Join-Path -Path $WebProjFolder -ChildPath ($f.Replace("~", "").Replace("/", "\"))
Return $resultPath
}
foreach($FileXML in $CreatedPackagesConfigXML.packages.package.files.file)
{
$File = Get-Item (MapPath $FileXML)
if ($File -is [System.IO.DirectoryInfo])
{
Get-ChildItem -path $File -Recurse `
| Where-Object { $_ -isnot [System.IO.DirectoryInfo]} `
| ForEach-Object { WritePackageFile($_) } `
| Out-Null
}
else {
WritePackageFile($File)| Out-Null
}
}
$PackageManifestXML.umbPackage.ReplaceChild($NewFilesXML, $PackageManifestXML.SelectSingleNode("/umbPackage/files")) | Out-Null
$PackageManifestXML.Save($PackageManifest)

#zip the package
$DestZIP = "$ReleaseFolder\Articulate_$ReleaseVersionNumber$PreReleaseName.zip"
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($TempFolder, $DestZIP)
# Set the version number in package.xml
$PackageConfig = Join-Path -Path $BuildFolder -ChildPath "package.xml"
$PackageConfigXML = [xml](Get-Content $PackageConfig)
$PackageConfigXML.umbPackage.info.package.version = "$ReleaseVersionNumber"
$PackageConfigXML.Save($PackageConfig)

$nuSpec = Join-Path -Path $BuildFolder -ChildPath "Articulate.nuspec";
& $NuGet pack $nuSpec -BasePath $WebProjFolder -OutputDirectory $ReleaseFolder -Version "$ReleaseVersionNumber$PreReleaseName" -Properties "copyright=$Copyright;buildFolder=$BuildFolder"
umbpack pack $PackageFilePath -o $ReleaseFolder -v ($ReleaseVersionNumber + $PreReleaseName)
53 changes: 0 additions & 53 deletions build/createdPackages.config

This file was deleted.

Loading

0 comments on commit 5cf06a4

Please sign in to comment.