зеркало из https://github.com/microsoft/PSRule.git
CI process update (#2)
* Added CI scripts and pipeline metadata * Added appveyor.yml * Update module and CI process
This commit is contained in:
Родитель
de746831b5
Коммит
354f099058
|
@ -5,6 +5,7 @@
|
|||
/artifacts/
|
||||
/build/
|
||||
/reports/
|
||||
/out/
|
||||
/**/*.user
|
||||
/src/**/*-help.xml
|
||||
/src/**/*.help.txt
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
markdown:
|
||||
# Should a line break be added after headers
|
||||
sectionFormat: LineBreakAfterHeader
|
||||
# Set the default infostring for fenced sections
|
||||
infoString: text
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Launch Current File",
|
||||
"script": "${file}",
|
||||
"args": [],
|
||||
"cwd": "${file}"
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Launch Current File in Temporary Console",
|
||||
"script": "${file}",
|
||||
"args": [],
|
||||
"cwd": "${file}",
|
||||
"createTemporaryIntegratedConsole": true
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Launch Current File w/Args Prompt",
|
||||
"script": "${file}",
|
||||
"args": [
|
||||
"${command:SpecifyScriptArgs}"
|
||||
],
|
||||
"cwd": "${file}"
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "attach",
|
||||
"name": "PowerShell Attach to Host Process",
|
||||
"processId": "${command:PickPSHostProcess}",
|
||||
"runspaceId": 1
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Interactive Session",
|
||||
"cwd": "${workspaceRoot}"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"files.exclude": {
|
||||
".vs/": true,
|
||||
"out/": true,
|
||||
"reports/": true,
|
||||
"**/bin/": true,
|
||||
"**/obj/": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "test",
|
||||
"type": "shell",
|
||||
"command": "Invoke-Build Test",
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": [ "$pester" ]
|
||||
},
|
||||
{
|
||||
"label": "coverage",
|
||||
"type": "shell",
|
||||
"command": "Invoke-Build Test -CodeCoverage",
|
||||
"problemMatcher": [ "$pester" ]
|
||||
},
|
||||
{
|
||||
"label": "build",
|
||||
"type": "shell",
|
||||
"command": "Invoke-Build Build",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "build-docs",
|
||||
"type": "shell",
|
||||
"command": "Invoke-Build BuildHelp",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "scaffold-docs",
|
||||
"type": "shell",
|
||||
"command": "Invoke-Build ScaffoldHelp",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "clean",
|
||||
"type": "shell",
|
||||
"command": "Invoke-Build Clean",
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
|
||||
param (
|
||||
[Parameter(Mandatory = $False)]
|
||||
[String]$ModuleVersion,
|
||||
|
||||
[Parameter(Mandatory = $False)]
|
||||
[String]$Configuration = 'Debug',
|
||||
|
||||
[Parameter(Mandatory = $False)]
|
||||
[String]$NuGetApiKey,
|
||||
|
||||
[Parameter(Mandatory = $False)]
|
||||
[Switch]$CodeCoverage = $False
|
||||
)
|
||||
|
||||
# Copy the PowerShell modules files to the destination path
|
||||
function CopyModuleFiles {
|
||||
|
||||
param (
|
||||
[Parameter(Mandatory = $True)]
|
||||
[String]$Path,
|
||||
|
||||
[Parameter(Mandatory = $True)]
|
||||
[String]$DestinationPath
|
||||
)
|
||||
|
||||
process {
|
||||
$sourcePath = Resolve-Path -Path $Path;
|
||||
|
||||
Get-ChildItem -Path $sourcePath -Recurse -File -Include *.ps1,*.psm1,*.psd1,*.docx,*.dotx | Where-Object -FilterScript {
|
||||
($_.FullName -notmatch '(\.(cs|csproj)|(\\|\/)(obj|bin))')
|
||||
} | ForEach-Object -Process {
|
||||
$filePath = $_.FullName.Replace($sourcePath, $destinationPath);
|
||||
|
||||
$parentPath = Split-Path -Path $filePath -Parent;
|
||||
|
||||
if (!(Test-Path -Path $parentPath)) {
|
||||
$Null = New-Item -Path $parentPath -ItemType Directory -Force;
|
||||
}
|
||||
|
||||
Copy-Item -Path $_.FullName -Destination $filePath -Force;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function SendAppveyorTestResult {
|
||||
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory = $True)]
|
||||
[String]$Uri,
|
||||
|
||||
[Parameter(Mandatory = $True)]
|
||||
[String]$Path,
|
||||
|
||||
[Parameter(Mandatory = $False)]
|
||||
[String]$Include = '*'
|
||||
)
|
||||
|
||||
begin {
|
||||
Write-Verbose -Message "[SendAppveyorTestResult] BEGIN::";
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
try {
|
||||
$webClient = New-Object -TypeName 'System.Net.WebClient';
|
||||
|
||||
foreach ($resultFile in (Get-ChildItem -Path $Path -Filter $Include -File -Recurse)) {
|
||||
|
||||
Write-Verbose -Message "[SendAppveyorTestResult] -- Uploading file: $($resultFile.FullName)";
|
||||
|
||||
$webClient.UploadFile($Uri, "$($resultFile.FullName)");
|
||||
}
|
||||
}
|
||||
catch {
|
||||
throw $_.Exception;
|
||||
}
|
||||
finally {
|
||||
$webClient = $Null;
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose -Message "[SendAppveyorTestResult] END::";
|
||||
}
|
||||
}
|
||||
|
||||
task BuildDotNet {
|
||||
exec {
|
||||
# Build library
|
||||
# dotnet publish src/PSRule -c $Configuration -f net452 -o $(Join-Path -Path $PWD -ChildPath out/modules/PSRule/desktop)
|
||||
dotnet publish src/PSRule -c $Configuration -f netstandard2.0 -o $(Join-Path -Path $PWD -ChildPath out/modules/PSRule/core)
|
||||
}
|
||||
}
|
||||
|
||||
task CopyModule {
|
||||
CopyModuleFiles -Path src/PSRule -DestinationPath out/modules/PSRule;
|
||||
|
||||
# Copy third party notices
|
||||
Copy-Item -Path ThirdPartyNotices.txt -Destination out/modules/PSRule;
|
||||
}
|
||||
|
||||
# Synopsis: Build modules only
|
||||
task BuildModule BuildDotNet, CopyModule
|
||||
|
||||
# Synopsis: Build help
|
||||
task BuildHelp BuildModule, PlatyPS, {
|
||||
|
||||
# Generate MAML and about topics
|
||||
$Null = New-ExternalHelp -OutputPath out/docs/PSRule -Path '.\docs\commands\PSRule\en-US','.\docs\keywords\PSRule\en-US' -Force;
|
||||
|
||||
# Copy generated help into module out path
|
||||
$Null = Copy-Item -Path out/docs/PSRule/* -Destination out/modules/PSRule/en-US;
|
||||
$Null = Copy-Item -Path out/docs/PSRule/* -Destination out/modules/PSRule/en-AU;
|
||||
}
|
||||
|
||||
task ScaffoldHelp BuildModule, {
|
||||
|
||||
Import-Module (Join-Path -Path $PWD -ChildPath out/modules/PSRule) -Force;
|
||||
|
||||
Update-MarkdownHelp -Path '.\docs\commands\PSRule\en-US';
|
||||
}
|
||||
|
||||
# Synopsis: Remove temp files.
|
||||
task Clean {
|
||||
Remove-Item -Path out,reports -Recurse -Force -ErrorAction SilentlyContinue;
|
||||
}
|
||||
|
||||
task PublishModule Build, {
|
||||
|
||||
# Update module version
|
||||
if ($Null -ne 'ModuleVersion') {
|
||||
Update-ModuleManifest -Path out/modules/PSRule/PSRule.psd1 -ModuleVersion $ModuleVersion;
|
||||
}
|
||||
}
|
||||
|
||||
task ReleaseModule {
|
||||
|
||||
if ($Null -ne 'NuGetApiKey') {
|
||||
|
||||
Publish-Module -Path out/modules/PSRule -NuGetApiKey $NuGetApiKey -Verbose
|
||||
}
|
||||
}
|
||||
|
||||
task NuGet {
|
||||
$Null = Install-PackageProvider -Name NuGet -Force -Scope CurrentUser;
|
||||
}
|
||||
|
||||
task Pester {
|
||||
|
||||
# Install pester if v4+ is not currently installed
|
||||
if ($Null -eq (Get-Module -Name Pester -ListAvailable | Where-Object -FilterScript { $_.Version -like '4.*' })) {
|
||||
Install-Module -Name Pester -MinimumVersion '4.0.0' -Force -Scope CurrentUser -SkipPublisherCheck;
|
||||
}
|
||||
|
||||
Import-Module -Name Pester -Verbose:$False;
|
||||
}
|
||||
|
||||
task platyPS {
|
||||
|
||||
# Install pester if v4+ is not currently installed
|
||||
if ($Null -eq (Get-Module -Name PlatyPS -ListAvailable)) {
|
||||
Install-Module -Name PlatyPS -Force -Scope CurrentUser;
|
||||
}
|
||||
|
||||
Import-Module -Name PlatyPS -Verbose:$False;
|
||||
}
|
||||
|
||||
task TestModule Pester, {
|
||||
|
||||
# Run Pester tests
|
||||
$pesterParams = @{ Path = $PWD; OutputFile = 'reports/Pester.xml'; OutputFormat = 'NUnitXml'; PesterOption = @{ IncludeVSCodeMarker = $True }; PassThru = $True; };
|
||||
|
||||
if ($CodeCoverage) {
|
||||
$pesterParams.Add('CodeCoverage', (Join-Path -Path $PWD -ChildPath 'out/modules/**/*.psm1'));
|
||||
}
|
||||
|
||||
if (!(Test-Path -Path reports)) {
|
||||
$Null = New-Item -Path reports -ItemType Directory -Force;
|
||||
}
|
||||
|
||||
$results = Invoke-Pester @pesterParams;
|
||||
|
||||
if (![String]::IsNullOrEmpty($Env:APPVEYOR_JOB_ID)) {
|
||||
SendAppveyorTestResult -Uri "https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)" -Path '.\reports' -Include '*.xml';
|
||||
}
|
||||
|
||||
# Throw an error if pester tests failed
|
||||
|
||||
if ($Null -eq $results) {
|
||||
throw 'Failed to get Pester test results.';
|
||||
}
|
||||
elseif ($results.FailedCount -gt 0) {
|
||||
throw "$($results.FailedCount) tests failed.";
|
||||
}
|
||||
}
|
||||
|
||||
# Synopsis: Build and clean.
|
||||
task . Build, Test
|
||||
|
||||
# Synopsis: Build the project
|
||||
task Build Clean, BuildModule, BuildHelp
|
||||
|
||||
task Test Build, TestModule
|
||||
|
||||
task Publish PublishModule
|
||||
|
||||
task Release ReleaseModule
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.106
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSRule", "src\PSRule\PSRule.csproj", "{ACAFD790-980B-4B64-912F-9BAD91DFF749}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ACAFD790-980B-4B64-912F-9BAD91DFF749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ACAFD790-980B-4B64-912F-9BAD91DFF749}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ACAFD790-980B-4B64-912F-9BAD91DFF749}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ACAFD790-980B-4B64-912F-9BAD91DFF749}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {533491EB-BAE9-472E-B57F-A675ECD335B5}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,29 @@
|
|||
Do Not Translate or Localize
|
||||
|
||||
This file is based on or incorporates material from the projects listed below (Third Party IP). The original copyright notice and the license under which Microsoft received such Third Party IP, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft licenses the Third Party IP to you under the licensing terms for the Microsoft product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.
|
||||
|
||||
---------------------------------------------
|
||||
File: YamlDotNet
|
||||
---------------------------------------------
|
||||
|
||||
https://github.com/aaubry/YamlDotNet
|
||||
|
||||
Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Antoine Aubry and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,19 @@
|
|||
version: 0.0.0.{build}
|
||||
image: Visual Studio 2017
|
||||
|
||||
# Only build master branch
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
environment:
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Don't download unneeded packages
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: true # Don't send telemetry
|
||||
|
||||
install:
|
||||
- ps: |
|
||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null
|
||||
Install-Module InvokeBuild -MinimumVersion 5.4.0 -Scope CurrentUser -Force | Out-Null
|
||||
|
||||
build_script:
|
||||
- ps: Invoke-Build
|
|
@ -0,0 +1,39 @@
|
|||
# Azure DevOps
|
||||
# Build pipeline for PSRule
|
||||
|
||||
trigger:
|
||||
- master
|
||||
|
||||
pool:
|
||||
vmImage: VS2017-Win2016
|
||||
|
||||
variables:
|
||||
buildConfiguration: 'Release'
|
||||
|
||||
steps:
|
||||
|
||||
# Install pipeline dependencies
|
||||
- powershell: ./scripts/vstsbuild.ps1
|
||||
displayName: 'Install Invoke-Build'
|
||||
|
||||
# Invoke build
|
||||
- powershell: Invoke-Build -Configuration $(buildConfiguration)
|
||||
displayName: 'Build module'
|
||||
|
||||
# Publish test results
|
||||
- task: PublishTestResults@2
|
||||
displayName: 'Publish test results'
|
||||
inputs:
|
||||
testRunTitle: 'Pester unit tests'
|
||||
testResultsFormat: NUnit
|
||||
testResultsFiles: 'reports/*.xml'
|
||||
mergeTestResults: true
|
||||
buildConfiguration: $(buildConfiguration)
|
||||
condition: succeededOrFailed()
|
||||
|
||||
# Generate artifacts
|
||||
- task: PublishBuildArtifacts@1
|
||||
displayName: 'Publish PSRule module'
|
||||
inputs:
|
||||
PathtoPublish: out/modules/PSRule
|
||||
ArtifactName: PSRule
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
if ($Null -eq (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
|
||||
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser;
|
||||
}
|
||||
|
||||
if ($Null -eq (Get-Module -Name InvokeBuild -ListAvailable -ErrorAction SilentlyContinue | Where-Object -FilterScript { $_.Version -like '5.*' })) {
|
||||
Install-Module InvokeBuild -MinimumVersion 5.4.0 -Scope CurrentUser -Force;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -15,7 +15,7 @@ RootModule = 'PSRule.psm1'
|
|||
ModuleVersion = '0.0.1'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
CompatiblePSEditions = 'Core', 'Desktop'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '0130215d-58eb-4887-b6fa-31ed02500569'
|
||||
|
@ -33,7 +33,7 @@ Copyright = '(c) Microsoft Corporation. All rights reserved.'
|
|||
Description = 'A PowerShell rules engine.'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
# PowerShellVersion = ''
|
||||
PowerShellVersion = '5.1'
|
||||
|
||||
# Name of the Windows PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
|
@ -42,7 +42,7 @@ Description = 'A PowerShell rules engine.'
|
|||
# PowerShellHostVersion = ''
|
||||
|
||||
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# DotNetFrameworkVersion = ''
|
||||
DotNetFrameworkVersion = '4.7.2'
|
||||
|
||||
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# CLRVersion = ''
|
||||
|
|
Загрузка…
Ссылка в новой задаче