PSRule-vscode/pipeline.build.ps1

118 строки
3.6 KiB
PowerShell
Исходник Обычный вид История

# Invoke-Build
# CI pipeline script for PSRule-vscode
2019-03-01 14:04:48 +03:00
[CmdletBinding()]
2019-03-01 14:04:48 +03:00
param (
[Parameter(Mandatory = $False)]
[String]$Build = '0.0.1',
2019-03-01 14:04:48 +03:00
[Parameter(Mandatory = $False)]
[String]$Configuration = 'Debug',
[Parameter(Mandatory = $False)]
2019-03-02 13:02:21 +03:00
[String]$ArtifactPath = (Join-Path -Path $PWD -ChildPath out/package),
[Parameter(Mandatory = $False)]
[String]$ApiKey
2019-03-01 14:04:48 +03:00
)
Write-Host -Object "[Pipeline] -- PWD: $PWD" -ForegroundColor Green;
Write-Host -Object "[Pipeline] -- ArtifactPath: $ArtifactPath" -ForegroundColor Green;
Write-Host -Object "[Pipeline] -- BuildNumber: $($Env:BUILD_BUILDNUMBER)" -ForegroundColor Green;
Write-Host -Object "[Pipeline] -- SourceBranch: $($Env:BUILD_SOURCEBRANCH)" -ForegroundColor Green;
Write-Host -Object "[Pipeline] -- SourceBranchName: $($Env:BUILD_SOURCEBRANCHNAME)" -ForegroundColor Green;
2019-03-01 14:04:48 +03:00
if ($Env:SYSTEM_DEBUG -eq 'true') {
$VerbosePreference = 'Continue';
}
2019-03-01 14:04:48 +03:00
if ($Env:BUILD_SOURCEBRANCH -like '*/tags/*' -and $Env:BUILD_SOURCEBRANCHNAME -like 'v0.*') {
$Build = $Env:BUILD_SOURCEBRANCHNAME.Substring(1);
}
2019-03-01 14:04:48 +03:00
$version = $Build;
$versionSuffix = [String]::Empty;
if ($version -like '*-*') {
[String[]]$versionParts = $version.Split('-', [System.StringSplitOptions]::RemoveEmptyEntries);
$version = $versionParts[0];
if ($versionParts.Length -eq 2) {
$versionSuffix = $versionParts[1];
}
2019-03-01 14:04:48 +03:00
}
Write-Host -Object "[Pipeline] -- Using version: $version" -ForegroundColor Green;
Write-Host -Object "[Pipeline] -- Using versionSuffix: $versionSuffix" -ForegroundColor Green;
2019-03-01 14:04:48 +03:00
task BuildExtension {
Write-Host "> Building extension" -ForegroundColor Green
2019-03-01 14:04:48 +03:00
exec { & npm run compile }
}
task PackageExtension {
Write-Host "> Packaging PSRule-vscode" -ForegroundColor Green
if (!(Test-Path -Path out/package)) {
$Null = New-Item -Path out/package -ItemType Directory -Force;
}
$workingPath = $PWD;
$packagePath = Join-Path -Path $workingPath -ChildPath 'out/package/psrule-vscode-preview.vsix';
exec { & npm run pack -- --out $packagePath }
2019-03-01 14:04:48 +03:00
}
# Synopsis: Install the extension in Visual Studio Code
2019-03-01 14:04:48 +03:00
task InstallExtension {
Write-Host "> Installing PSRule-vscode" -ForegroundColor Green
exec { & code --install-extension ./out/package/psrule-vscode-preview.vsix --force }
2019-03-01 14:04:48 +03:00
}
task VersionExtension {
if (![String]::IsNullOrEmpty($Build)) {
# Update extension version
if (![String]::IsNullOrEmpty($version)) {
Write-Verbose -Message "[VersionExtension] -- Updating extension version";
$package = Get-Content ./package.json -Raw | ConvertFrom-Json;
2019-03-01 14:04:48 +03:00
if ($package.version -ne $version) {
$package.version = $version;
$package | ConvertTo-Json -Depth 99 | Set-Content ./package.json;
}
2019-03-01 14:04:48 +03:00
}
}
}
# Synopsis: Remove temp files
2019-03-01 14:04:48 +03:00
task Clean {
Remove-Item -Path out,reports -Recurse -Force -ErrorAction Ignore;
}
# Synopsis: Restore NPM packages
task PackageRestore {
exec { & npm install --no-save }
2019-03-02 13:02:21 +03:00
}
task ReleaseExtension {
$packagePath = Join-Path -Path $ArtifactPath -ChildPath 'extension/psrule-vscode-preview.vsix';
exec { & npm install vsce --no-save }
exec { & npm run publish -- --packagePath $packagePath --pat $ApiKey }
}
2019-06-08 14:28:03 +03:00
# Synopsis: Add shipit build tag
task TagBuild {
if ($Null -ne $Env:BUILD_DEFINITIONNAME) {
Write-Host "`#`#vso[build.addbuildtag]shipit";
}
}
task Build Clean, PackageRestore, BuildExtension, VersionExtension, PackageExtension
2019-03-01 14:04:48 +03:00
task Install Build, InstallExtension
task . Build
2019-03-02 13:02:21 +03:00
2019-06-08 14:28:03 +03:00
task Release ReleaseExtension, TagBuild