Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"microsoft.psrule.tool": {
"version": "3.0.0-b0453",
"commands": [
"ps-rule"
],
"rollForward": false
}
}
}
12 changes: 1 addition & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,9 @@ jobs:
Save-Module -Name PSRule.Rules.MSFT.OSS -Repository PSGallery -Path out/repo/;
Register-PSRepository -SourceLocation out/repo -Name Local -InstallationPolicy Trusted;

- name: Run PSRule v1
- name: Run PSRule
uses: ./
with:
inputType: repository
modules: PSRule.Rules.MSFT.OSS
repository: Local
version: "1.11.1"

- name: Run PSRule v2
uses: ./
with:
inputType: repository
modules: PSRule.Rules.MSFT.OSS
outcome: Problem

Expand All @@ -74,7 +65,6 @@ jobs:
- name: Run PSRule self analysis
uses: ./
with:
inputType: repository
outputFormat: Markdown
outputPath: reports/report.md
modules: PSRule.Rules.MSFT.OSS
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ See [upgrade notes][upgrade-notes] for helpful information when upgrading from p

[upgrade-notes]: docs/upgrade-notes.md

## Next release

We are currently working towards the next release of PSRule.
PSRule v3 is currently in development and not suitable for production use.

- [v3](docs/CHANGELOG-v3.md)

## Current release

- [v2](docs/CHANGELOG-v2.md)
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ For a list of changes please see the [change log][2].
- name: Run PSRule analysis
uses: microsoft/ps-rule@main
with:
inputType: repository, inputPath # Optional. Determines the type of input to use for PSRule.
inputPath: string # Optional. The path PSRule will look for files to validate.
modules: string # Optional. A comma separated list of modules to use for analysis.
source: string # Optional. A path containing rules to use for analysis.
includePath: string # Optional. A path containing rules to use for analysis.
baseline: string # Optional. The name of a PSRule baseline to use.
conventions: string # Optional. A comma separated list of conventions to use.
option: string # Optional. The path to an options file.
Expand All @@ -96,18 +95,9 @@ For a list of changes please see the [change log][2].
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.
restore: boolean
```

### `inputType`

Determines the type of input to use for PSRule either `repository` or `inputPath`.
Defaults to `repository`.

When set to:

- `repository` - The structure of the repository within `inputPath` will be analyzed.
- `inputPath` - Supported file formats within `inputPath` will be read as objects.

### `inputPath`

The path PSRule will look for input files.
Expand Down
33 changes: 21 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@ branding:
icon: 'check-circle'
color: 'green'
inputs:
inputType:
description: 'Determines the type of input to use for PSRule.'
default: 'repository'
includePath:
description: 'An path containing rules to use for analysis.'
default: '.ps-rule/'
required: false

inputPath:
description: 'The path PSRule will look for files to validate.'
default: ''
default: '.'
required: false

modules:
description: 'A comma separated list of modules to use for analysis.'
default: ''
required: false

source:
description: 'An path containing rules to use for analysis.'
default: '.ps-rule/'
required: false

baseline:
description: 'The name of a PSRule baseline to use.'
default: ''
Expand All @@ -45,7 +40,7 @@ inputs:

outcome:
description: 'Filters output to include results with the specified outcome.'
default: ''
default: 'Processed'
required: false

outputFormat:
Expand Down Expand Up @@ -83,11 +78,25 @@ inputs:
default: ''
required: false

restore:
description: 'Restore PSRule modules.'
default: 'true'
required: false

runs:
using: 'composite'
steps:
- name: 'Analysis'
- name: Check .NET version
shell: pwsh
run: dotnet --version

- name: Install PSRule
shell: pwsh
run: dotnet tool restore --tool-manifest $Env:GITHUB_ACTION_PATH/.config/dotnet-tools.json

- name: Run PSRule
shell: pwsh
working-directory: ${{ github.workspace }}
run: |-
${{ github.action_path }}/powershell.ps1 -InputType '${{ inputs.inputType }}' -InputPath '${{ inputs.inputPath }}' -Modules '${{ inputs.modules }}' -Source '${{ inputs.source }}' -Baseline '${{ inputs.baseline }}' -Conventions '${{ inputs.conventions }}' -Option '${{ inputs.option }}' -Outcome '${{ inputs.outcome }}' -OutputFormat '${{ inputs.outputFormat }}' -OutputPath '${{ inputs.outputPath }}' -Path '${{ inputs.path }}' -PreRelease '${{ inputs.prerelease }}' -Repository '${{ inputs.repository }}' -Summary '${{ inputs.summary }}' -Version '${{ inputs.version }}'
#${{ github.action_path }}/bootstrap.ps1 -InputType '${{ inputs.inputType }}' -InputPath '${{ inputs.inputPath }}' -Modules '${{ inputs.modules }}' -Source '${{ inputs.source }}' -Baseline '${{ inputs.baseline }}' -Conventions '${{ inputs.conventions }}' -Option '${{ inputs.option }}' -Outcome '${{ inputs.outcome }}' -OutputFormat '${{ inputs.outputFormat }}' -OutputPath '${{ inputs.outputPath }}' -Path '${{ inputs.path }}' -PreRelease '${{ inputs.prerelease }}' -Repository '${{ inputs.repository }}' -Summary '${{ inputs.summary }}' -Version '${{ inputs.version }}'
dotnet tool run ps-rule run --in-github-actions
122 changes: 63 additions & 59 deletions powershell.ps1 → bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,115 @@
# Licensed under the MIT License.

#
# PSRule
# PSRule bootstrap script.
#

# See details at: https://github.com/microsoft/ps-rule
# See details at: https://github.com/microsoft/PSRule/blob/main/src/bootstrap/README.md

[CmdletBinding()]
param (
# The root path for analysis
[Parameter(Mandatory = $False)]
[String]$Path = $Env:INPUT_PATH,
[String]$WorkspacePath = $PWD,

# The type of input
# The source path.
[Parameter(Mandatory = $False)]
[ValidateSet('repository', 'inputPath')]
[String]$InputType = $Env:INPUT_INPUTTYPE,
[String]$IncludePath,

# The path to input files
[Parameter(Mandatory = $False)]
[String]$InputPath = $Env:INPUT_INPUTPATH,

# The path to find rules
[Parameter(Mandatory = $False)]
[String]$Source = $Env:INPUT_SOURCE,
[String]$InputPath,

# Rule modules to use
[Parameter(Mandatory = $False)]
[String]$Modules = $Env:INPUT_MODULES,
[String]$Modules,

# A baseline to use
[Parameter(Mandatory = $False)]
[String]$Baseline = $env:INPUT_BASELINE,
[String]$Baseline,

# The conventions to use
[Parameter(Mandatory = $False)]
[String]$Conventions = $Env:INPUT_CONVENTIONS,
[String]$Conventions,

# The path to an options file.
[Parameter(Mandatory = $False)]
[String]$Option = $Env:INPUT_OPTION,
[String]$Option,

# Filters output to include results with the specified outcome.
[Parameter(Mandatory = $False)]
[String]$Outcome = $Env:INPUT_OUTCOME,
[String]$Outcome,

# The output format
[Parameter(Mandatory = $False)]
[ValidateSet('None', 'Yaml', 'Json', 'NUnit3', 'Csv', 'Markdown', 'Sarif')]
[String]$OutputFormat = $Env:INPUT_OUTPUTFORMAT,
[String]$OutputFormat,

# The path to store formatted output
[Parameter(Mandatory = $False)]
[String]$OutputPath = $Env:INPUT_OUTPUTPATH,
[String]$OutputPath,

# Determine if a pre-release module version is installed.
[Parameter(Mandatory = $False)]
[String]$PreRelease = $Env:INPUT_PRERELEASE,
[String]$PreRelease,

# The name of the PowerShell repository where PSRule modules are installed from.
[String]$Repository = $Env:INPUT_REPOSITORY,
[String]$Repository,

# Determines if a job summary is written.
[Parameter(Mandatory = $False)]
[String]$Summary = $Env:INPUT_SUMMARY,
[ValidateSet('true', 'false')]
[String]$Summary,

# The specific version of PSRule to use.
[Parameter(Mandatory = $False)]
[String]$Version = $Env:INPUT_VERSION
[String]$Version,

[Parameter(Mandatory = $False)]
[ValidateSet('true', 'false')]
[String]$Restore
)

$workspacePath = $Env:GITHUB_WORKSPACE;
# Set debugging verbosity and helpers.
$ProgressPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue;
if ($Env:SYSTEM_DEBUG -eq 'true') {
$VerbosePreference = [System.Management.Automation.ActionPreference]::Continue;
}

# Check inputType
if ([String]::IsNullOrEmpty($InputType) -or $InputType -notin 'repository', 'inputPath') {
$InputType = 'repository';
function WriteDebug {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $True)]
[String]$Message
)
process {
if ($Env:SYSTEM_DEBUG -eq 'true' -or $Env:ACTIONS_STEP_DEBUG -eq 'true') {
Write-Host "[debug] $Message";
}
}
}

# Set workspace
function WriteInfo {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $True)]
[String]$Message
)
process {
Write-Host "[info] $Message";
}
}

# Check .NET version.
dotnet --version

# Setup the workspace path.
if ([String]::IsNullOrEmpty($workspacePath)) {
$workspacePath = $PWD;
}

WriteInfo "Using workspace path: $WorkspacePath";


# Set Path
if ([String]::IsNullOrEmpty($Path)) {
$Path = $workspacePath;
Expand All @@ -104,11 +128,11 @@ else {
}

# Set Source
if ([String]::IsNullOrEmpty($Source)) {
$Source = Join-Path -Path $Path -ChildPath '.ps-rule/';
if ([String]::IsNullOrWhiteSpace($Source)) {
$Source = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($Path, '.ps-rule/'))
}
else {
$Source = Join-Path -Path $Path -ChildPath $Source;
elseif (![System.IO.Path]::IsPathFullyQualified($Source)) {
$Source = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($Path, $Source))
}

# Set conventions
Expand All @@ -126,18 +150,7 @@ if ([String]::IsNullOrEmpty($Repository)) {
$Repository = 'PSGallery'
}

function WriteDebug {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $True)]
[String]$Message
)
process {
if ($Env:SYSTEM_DEBUG -eq 'true' -or $Env:ACTIONS_STEP_DEBUG -eq 'true') {
Write-Host "::debug::$Message";
}
}
}


#
# Check and install modules
Expand Down Expand Up @@ -227,7 +240,6 @@ Write-Host "[info] Using Path: $Path";
Write-Host "[info] Using Source: $Source";
Write-Host "[info] Using Baseline: $Baseline";
Write-Host "[info] Using Conventions: $Conventions";
Write-Host "[info] Using InputType: $InputType";
Write-Host "[info] Using InputPath: $InputPath";
Write-Host "[info] Using Option: $Option";
Write-Host "[info] Using Outcome: $Outcome";
Expand Down Expand Up @@ -275,20 +287,12 @@ try {
$invokeParams['As'] = 'Detail';
}

# repository
if ($InputType -eq 'repository') {
WriteDebug 'Running ''Assert-PSRule'' with repository as input.';
Write-Host '';
Write-Host '---';
Assert-PSRule @invokeParams -InputPath $InputPath -Format File;
}
# inputPath
elseif ($InputType -eq 'inputPath') {
WriteDebug 'Running ''Assert-PSRule'' with input from path.';
Write-Host '';
Write-Host '---';
Assert-PSRule @invokeParams -InputPath $InputPath;
}
Write-Host '';
Write-Host '---';

dotnet tool run ps-rule run --input-path $InputPath

Assert-PSRule @invokeParams -InputPath $InputPath;
}
catch [PSRule.Pipeline.RuleException] {
Write-Host "::error::Rule exception: $($_.Exception.Message)";
Expand Down
15 changes: 15 additions & 0 deletions docs/CHANGELOG-v3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Change log

See [upgrade notes][upgrade-notes] for helpful information when upgrading from previous versions.

[upgrade-notes]: upgrade-notes.md

## Unreleased

What's changed since v2.9.0:

- New features:
- **Breaking change:** Added support for PSRule v3 by @BernieWhite.
[#239](https://github.com/microsoft/ps-rule/issues/239)
- Action now uses PSRule CLI v3.
- The `inputType` input has been removed. This input is no longer required with PSRule v3.
9 changes: 9 additions & 0 deletions ps-rule.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 1,
"modules": {
"PSRule.Rules.MSFT.OSS": {
"version": "1.1.0",
"integrity": "sha512-4oEbkAT3VIQQlrDUOpB9qKkbNU5BMktvkDCriws4LgCMUiyUoYMcN0XovljAIW4FO0cmP7mP6A8Z7MPNGlgK7Q=="
}
}
}
Loading