Add more to build script for gitlabci

This commit is contained in:
Stephen Maunder 2017-12-31 21:16:55 +00:00
parent 783c6b0a6a
commit d421040192

View file

@ -2,6 +2,8 @@ param(
[string[]]$Tasks
)
function Install-Dependency([string] $Name)
{
$policy = Get-PSRepository -Name "PSGallery" | Select-Object -ExpandProperty "InstallationPolicy"
@ -31,6 +33,57 @@ function Run-Tests
}
}
function Release
{
Write-Output "Setting Variables"
$BuildRoot = $env:CI_PROJECT_DIR
$releasePath = "$BuildRoot\Release"
Write-Output "Build Root : $BuildRoot"
Write-Output "Release Root : $releasePath"
if (-not (Test-Path "$releasePath\SnipeitPS")) {
$null = New-Item -Path "$releasePath\SnipeitPS" -ItemType Directory
}
# Copy module
Copy-Item -Path "$BuildRoot\SnipeitPS\*" -Destination "$releasePath\SnipeitPS" -Recurse -Force
# Copy additional files
$additionalFiles = @(
"$BuildRoot\CHANGELOG.md"
"$BuildRoot\LICENSE"
"$BuildRoot\README.md"
)
Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force
$manifestContent = Get-Content -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -Raw
if ($manifestContent -notmatch '(?<=ModuleVersion\s+=\s+'')(?<ModuleVersion>.*)(?='')') {
throw "Module version was not found in manifest file,"
}
$currentVersion = [Version] $Matches.ModuleVersion
if ($env:CI_JOB_ID) {
$newRevision = $env:CI_JOB_ID
}
else {
$newRevision = 0
}
$version = New-Object -TypeName System.Version -ArgumentList $currentVersion.Major,
$currentVersion.Minor,
$newRevision
Write-Output "New version : $version"
Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName ModuleVersion -Value $version
$functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\SnipeitPS\Public" | ForEach-Object {$_.BaseName}
Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport
Remove-Module SnipeitPS
Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop
Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789
}
foreach($task in $Tasks){
switch($task)
{
@ -41,16 +94,8 @@ foreach($task in $Tasks){
Run-Tests
}
"release" {
Register-PSRepository -Name InternalPowerShellModules `
-SourceLocation http://192.168.1.155:81/nuget/DIPowerShell `
-PackageManagementProvider NuGet `
-PublishLocation http://192.168.1.155:81/nuget/DIPowerShell `
-InstallationPolicy Trusted
Write-Output "Registerting Module"
Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop
Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789
Write-Output "Releasing..."
Release
}
}
}