Skip to content

Commit

Permalink
Added job summary #724
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite committed Mar 5, 2023
1 parent 30b8aaf commit befdfdb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .azure-pipelines/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ stages:
displayName: 'Install GitVersion'

# Get extension version
- powershell: Invoke-Build GetVersionInfo -Rev '$(Build.BuildNumber)'
- pwsh: Invoke-Build GetVersionInfo -Rev '$(Build.BuildNumber)'
displayName: 'Get extension version'

# Build extension
- powershell: Invoke-Build -Configuration $(buildConfiguration) -Build $(Build.BuildNumber)
- pwsh: Invoke-Build -Configuration $(buildConfiguration) -Build $(Build.BuildNumber)
displayName: 'Build extension'

# PSRule results
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers

What's changed since v2.7.0:

- New features:
- Added job summaries to each run by @BernieWhite.
[#724](https://github.com/microsoft/PSRule-pipelines/issues/724)
- Set the `summary` input to `false` to skip generating a job summary.
- General improvements:
- **Important change**: Added warning to V1 tasks and update V0 tasks by @BernieWhite.
[#694](https://github.com/microsoft/PSRule-pipelines/issues/694)
Expand Down
4 changes: 4 additions & 0 deletions docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ steps:
path: string # Optional. The working directory PSRule is run from.
prerelease: boolean # Optional. Determine if a pre-release module version is installed.
repository: string # Optional. The name of the PowerShell repository where PSRule modules are installed from.
summary: boolean # Optional. Determines if a job summary is written.
version: string # Optional. The specific version of PSRule to use.
```

Expand Down Expand Up @@ -113,6 +114,9 @@ steps:
By default this is the PowerShell Gallery.
When configured, PowerShell modules are installed from this repository.
Before calling the `ps-rule-assert`, register and authenticate to the repository if required.
- **summary**: Determines if a job summary is written.
By default, a job summary is generated and attached to the timeline.
When set to `false` the job summary is skipped.
- **version**: The specific version of PSRule to use.
By default, the latest stable version of PSRule will be used. When set:
- The specific version of PSRule will be installed and imported for use.
Expand Down
20 changes: 20 additions & 0 deletions tasks/ps-rule-assertV2/powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ param (
[System.Boolean]$PreRelease = (Get-VstsInput -Name 'prerelease' -AsBool),

# The name of the PowerShell repository where PSRule modules are installed from.
[Parameter(Mandatory = $False)]
[String]$Repository = (Get-VstsInput -Name 'repository'),

# Determines if a job summary is written.
[Parameter(Mandatory = $False)]
[System.Boolean]$Summary = (Get-VstsInput -Name 'summary' -AsBool),

# The specific version of PSRule to use.
[Parameter(Mandatory = $False)]
[String]$Version = (Get-VstsInput -Name 'version')
Expand Down Expand Up @@ -275,6 +280,7 @@ Write-Host "[info] Using Option: $Option";
Write-Host "[info] Using Outcome: $Outcome";
Write-Host "[info] Using OutputFormat: $OutputFormat";
Write-Host "[info] Using OutputPath: $OutputPath";
Write-Host "[info] Using Summary: $Summary";

Write-Host "`#`#[endgroup]";

Expand Down Expand Up @@ -313,6 +319,9 @@ try {
$invokeParams['OutputPath'] = $OutputPath;
WriteDebug ([String]::Concat('-OutputFormat ', $OutputFormat, ' -OutputPath ''', $OutputPath, ''''));
}
if ($Summary) {
$Env:PSRULE_OUTPUT_JOBSUMMARYPATH = 'reports/ps_rule_summary.md';
}

# Repository
if ($InputType -eq 'repository') {
Expand All @@ -336,6 +345,7 @@ catch [PSRule.Pipeline.RuleException] {
}
catch [PSRule.Pipeline.FailPipelineException] {
Write-Host "`#`#vso[task.logissue type=error]$(Get-VstsLocString -Key 'AssertFailed')";
Write-Host "$($_.Exception.ScriptStackTrace)";
HostExit
}
catch {
Expand All @@ -344,6 +354,16 @@ catch {
HostExit
}
finally {
try {
if ($Summary -and (Test-Path -Path 'reports/ps_rule_summary.md')) {
Write-Host "`#`#vso[task.uploadsummary]reports/ps_rule_summary.md";
$Null = Remove-Item -Path 'reports/ps_rule_summary.md' -Force;
}
}
catch {
Write-Host "`#`#vso[task.logissue type=warning]Failed to write job summary: $($_.Exception.Message)";
Write-Host "$($_.Exception.ScriptStackTrace)";
}
Pop-Location;
}
Write-Host '---';
7 changes: 7 additions & 0 deletions tasks/ps-rule-assertV2/powershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function run() {
let input_outputPath: string = task.getPathInput('outputPath', /*required*/ false, /*check*/ false);
let input_prerelease: boolean = task.getBoolInput('prerelease', /*required*/ false);
let input_repository: string = task.getInput('repository', /*required*/ false);
let input_summary: boolean = task.getBoolInput('summary', /*required*/ false);
let input_version: string = task.getInput('version', /*required*/ false);

// Write bootstrap commands to a temporary script file
Expand Down Expand Up @@ -71,6 +72,12 @@ async function run() {
if (input_repository !== undefined) {
contents.push(`$scriptParams['Repository'] = '${input_repository}'`);
}
if (input_summary !== undefined && input_summary) {
contents.push(`$scriptParams['Summary'] = $True;`);
}
else {
contents.push(`$scriptParams['Summary'] = $False;`);
}
if (input_version !== undefined) {
contents.push(`$scriptParams['Version'] = '${input_version}'`);
}
Expand Down
8 changes: 8 additions & 0 deletions tasks/ps-rule-assertV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@
"defaultValue": "PSGallery",
"helpMarkDown": "The name of the PowerShell repository where PSRule modules are installed from."
},
{
"name": "summary",
"type": "boolean",
"label": "Summary",
"required": false,
"defaultValue": true,
"helpMarkDown": "Determines if a job summary is written."
},
{
"name": "version",
"type": "string",
Expand Down

0 comments on commit befdfdb

Please sign in to comment.