2020-10-20 16:10:47 +03:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
# Invoke-Build
|
|
|
|
# CI pipeline script for PSRule-vscode
|
2019-03-01 14:04:48 +03:00
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
[CmdletBinding()]
|
2019-03-01 14:04:48 +03:00
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $False)]
|
2019-12-05 03:37:33 +03:00
|
|
|
[String]$Build,
|
2019-03-01 14:04:48 +03:00
|
|
|
|
2021-05-03 20:35:23 +03:00
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[ValidateSet('preview', 'stable', 'canary')]
|
|
|
|
[String]$Channel,
|
|
|
|
|
2019-03-01 14:04:48 +03:00
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[String]$Configuration = 'Debug',
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
2019-08-04 15:06:00 +03:00
|
|
|
[String]$OutputPath = (Join-Path -Path $PWD -ChildPath out),
|
2019-03-02 13:02:21 +03:00
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
2020-10-20 16:10:47 +03:00
|
|
|
[String]$ApiKey,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $False)]
|
|
|
|
[String]$AssertStyle = 'AzurePipelines'
|
2019-03-01 14:04:48 +03:00
|
|
|
)
|
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- PWD: $PWD" -ForegroundColor Green;
|
2019-08-04 15:06:00 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- OutputPath: $OutputPath" -ForegroundColor Green;
|
2019-06-08 12:05:53 +03:00
|
|
|
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
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
if ($Env:SYSTEM_DEBUG -eq 'true') {
|
|
|
|
$VerbosePreference = 'Continue';
|
|
|
|
}
|
2019-03-01 14:04:48 +03:00
|
|
|
|
2019-06-08 12:05:53 +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
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
$version = $Build;
|
|
|
|
$versionSuffix = [String]::Empty;
|
2019-03-03 13:06:33 +03:00
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
if ($version -like '*-*') {
|
|
|
|
[String[]]$versionParts = $version.Split('-', [System.StringSplitOptions]::RemoveEmptyEntries);
|
|
|
|
$version = $versionParts[0];
|
2019-03-03 13:06:33 +03:00
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
if ($versionParts.Length -eq 2) {
|
|
|
|
$versionSuffix = $versionParts[1];
|
2021-05-03 20:35:23 +03:00
|
|
|
$Channel = 'preview';
|
2019-06-08 12:05:53 +03:00
|
|
|
}
|
2021-05-03 20:35:23 +03:00
|
|
|
else {
|
|
|
|
$Channel = 'stable';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Handle channel
|
|
|
|
if ([String]::IsNullOrEmpty('Channel')) {
|
|
|
|
$Channel = 'preview';
|
|
|
|
}
|
|
|
|
$channelSuffix = '-preview';
|
|
|
|
switch ($Channel) {
|
|
|
|
'canary' { $channelSuffix = '-canary' }
|
|
|
|
'stable' { $channelSuffix = '' }
|
|
|
|
default { $channelSuffix = '-preview' }
|
2019-03-01 14:04:48 +03:00
|
|
|
}
|
|
|
|
|
2021-05-03 20:35:23 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- Using channel: $Channel" -ForegroundColor Green;
|
|
|
|
Write-Host -Object "[Pipeline] -- Using channelSuffix: $channelSuffix" -ForegroundColor Green;
|
2019-06-08 12:05:53 +03:00
|
|
|
Write-Host -Object "[Pipeline] -- Using version: $version" -ForegroundColor Green;
|
|
|
|
Write-Host -Object "[Pipeline] -- Using versionSuffix: $versionSuffix" -ForegroundColor Green;
|
|
|
|
|
2019-08-04 15:06:00 +03:00
|
|
|
$packageRoot = Join-Path -Path $OutputPath -ChildPath 'package';
|
2021-05-03 20:35:23 +03:00
|
|
|
$packageName = "psrule-vscode$channelSuffix";
|
|
|
|
$packagePath = Join-Path -Path $packageRoot -ChildPath "$packageName.vsix";
|
2019-08-04 15:06:00 +03:00
|
|
|
|
2020-10-20 16:10:47 +03:00
|
|
|
function Get-RepoRuleData {
|
|
|
|
[CmdletBinding()]
|
|
|
|
param (
|
|
|
|
[Parameter(Position = 0, Mandatory = $False)]
|
|
|
|
[String]$Path = $PWD
|
|
|
|
)
|
|
|
|
process {
|
|
|
|
GetPathInfo -Path $Path -Verbose:$VerbosePreference;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetPathInfo {
|
|
|
|
[CmdletBinding()]
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $True)]
|
|
|
|
[String]$Path
|
|
|
|
)
|
|
|
|
begin {
|
|
|
|
$items = New-Object -TypeName System.Collections.ArrayList;
|
|
|
|
}
|
|
|
|
process {
|
|
|
|
$Null = $items.Add((Get-Item -Path $Path));
|
|
|
|
$files = @(Get-ChildItem -Path $Path -File -Recurse -Include *.ps1,*.psm1,*.psd1,*.cs | Where-Object {
|
|
|
|
!($_.FullName -like "*.Designer.cs") -and
|
|
|
|
!($_.FullName -like "*/bin/*") -and
|
|
|
|
!($_.FullName -like "*/obj/*") -and
|
|
|
|
!($_.FullName -like "*\obj\*") -and
|
|
|
|
!($_.FullName -like "*\bin\*") -and
|
|
|
|
!($_.FullName -like "*\out\*") -and
|
|
|
|
!($_.FullName -like "*/out/*")
|
|
|
|
});
|
|
|
|
$Null = $items.AddRange($files);
|
|
|
|
}
|
|
|
|
end {
|
|
|
|
$items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 14:04:48 +03:00
|
|
|
task BuildExtension {
|
2019-08-04 15:06:00 +03:00
|
|
|
Write-Host '> Building extension' -ForegroundColor Green;
|
2019-03-01 14:04:48 +03:00
|
|
|
exec { & npm run compile }
|
|
|
|
}
|
|
|
|
|
|
|
|
task PackageExtension {
|
2019-08-04 15:06:00 +03:00
|
|
|
Write-Host '> Packaging PSRule-vscode' -ForegroundColor Green;
|
|
|
|
if (!(Test-Path -Path $packageRoot)) {
|
|
|
|
$Null = New-Item -Path $packageRoot -ItemType Directory -Force;
|
2019-03-01 14:04:48 +03:00
|
|
|
}
|
2019-06-08 12:05:53 +03:00
|
|
|
exec { & npm run pack -- --out $packagePath }
|
2019-03-01 14:04:48 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 12:11:42 +03:00
|
|
|
# Synopsis: Install the extension in Visual Studio Code
|
2019-03-01 14:04:48 +03:00
|
|
|
task InstallExtension {
|
2019-08-04 15:06:00 +03:00
|
|
|
Write-Host '> Installing PSRule-vscode' -ForegroundColor Green;
|
|
|
|
exec { & code --install-extension $packagePath --force }
|
2019-03-01 14:04:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
task VersionExtension {
|
2021-05-03 20:35:23 +03:00
|
|
|
# Update channel
|
|
|
|
$package = Get-Content ./package.json -Raw | ConvertFrom-Json;
|
|
|
|
if ($package.name -ne $packageName) {
|
|
|
|
$package.name = $packageName;
|
|
|
|
$package | ConvertTo-Json -Depth 99 | Set-Content ./package.json;
|
|
|
|
}
|
|
|
|
|
2019-03-01 14:04:48 +03:00
|
|
|
if (![String]::IsNullOrEmpty($Build)) {
|
|
|
|
# Update extension version
|
|
|
|
if (![String]::IsNullOrEmpty($version)) {
|
|
|
|
Write-Verbose -Message "[VersionExtension] -- Updating extension version";
|
2019-06-08 12:05:53 +03:00
|
|
|
$package = Get-Content ./package.json -Raw | ConvertFrom-Json;
|
2019-03-01 14:04:48 +03:00
|
|
|
|
2019-06-08 12:05:53 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:10:47 +03:00
|
|
|
# Synopsis: Install NuGet provider
|
|
|
|
task NuGet {
|
|
|
|
if ($Null -eq (Get-PackageProvider -Name NuGet -ErrorAction Ignore)) {
|
|
|
|
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Synopsis: Install PSRule
|
|
|
|
task PSRule NuGet, {
|
2021-05-03 20:35:23 +03:00
|
|
|
if ($Null -eq (Get-InstalledModule -Name PSRule -MinimumVersion 1.3.0 -ErrorAction Ignore)) {
|
|
|
|
Install-Module -Name PSRule -Repository PSGallery -MinimumVersion 1.3.0 -Scope CurrentUser -Force;
|
2020-10-20 16:10:47 +03:00
|
|
|
}
|
|
|
|
Import-Module -Name PSRule -Verbose:$False;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Synopsis: Run validation
|
|
|
|
task Rules PSRule, {
|
|
|
|
$assertParams = @{
|
|
|
|
Path = './.ps-rule/'
|
|
|
|
Style = $AssertStyle
|
|
|
|
OutputFormat = 'NUnit3'
|
|
|
|
ErrorAction = 'Stop'
|
2021-05-03 20:35:23 +03:00
|
|
|
As = 'Summary'
|
2020-10-20 16:10:47 +03:00
|
|
|
}
|
|
|
|
Assert-PSRule @assertParams -InputPath $PWD -Format File -OutputPath reports/ps-rule-file.xml;
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:05:53 +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;
|
|
|
|
}
|
|
|
|
|
2019-03-02 12:11:42 +03:00
|
|
|
# Synopsis: Restore NPM packages
|
|
|
|
task PackageRestore {
|
2019-06-08 12:05:53 +03:00
|
|
|
exec { & npm install --no-save }
|
2019-03-02 13:02:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
task ReleaseExtension {
|
2019-06-08 12:05:53 +03:00
|
|
|
exec { & npm install vsce --no-save }
|
|
|
|
exec { & npm run publish -- --packagePath $packagePath --pat $ApiKey }
|
2019-03-02 12:11:42 +03:00
|
|
|
}
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:05:53 +03:00
|
|
|
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
|