Skip to content

Commit

Permalink
CI process update (#2)
Browse files Browse the repository at this point in the history
* Added CI scripts and pipeline metadata
* Added appveyor.yml
* Update module and CI process
  • Loading branch information
BernieWhite authored Nov 24, 2018
1 parent de74683 commit 354f099
Show file tree
Hide file tree
Showing 13 changed files with 451 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/artifacts/
/build/
/reports/
/out/
/**/*.user
/src/**/*-help.xml
/src/**/*.help.txt
6 changes: 6 additions & 0 deletions .platyps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

markdown:
# Should a line break be added after headers
sectionFormat: LineBreakAfterHeader
# Set the default infostring for fenced sections
infoString: text
45 changes: 45 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"files.exclude": {
".vs/": true,
"out/": true,
"reports/": true,
"**/bin/": true,
"**/obj/": true
}
}
51 changes: 51 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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": []
}
]
}
209 changes: 209 additions & 0 deletions PSRule.build.ps1
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions PSRule.sln
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit 354f099

Please sign in to comment.