Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows PowerShell Support #22

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
1,601 changes: 0 additions & 1,601 deletions _init/index.js

This file was deleted.

11 changes: 7 additions & 4 deletions action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ else {
$output_level = splitListInput $inputs.output_level

Write-ActionInfo "Running Pester tests with following:"
Write-ActionInfo " * realtive to PWD: $PWD"
Write-ActionInfo " * relative to PWD: $PWD"
Write-ActionInfo " * PowerShell version: $($PSVersionTable.PSVersion.ToString()) $($PSVersionTable.PSEdition)"
$pesterConfig = [PesterConfiguration]::new()

if ($full_names_filters) {
Expand Down Expand Up @@ -141,6 +142,7 @@ else {
$pesterConfig.Run.PassThru = $true
$pesterConfig.TestResult.Enabled = $true
$pesterConfig.TestResult.OutputPath = $test_results_path
$pesterConfig.TestResult.TestSuiteName = "Pester on PowerShell $($PSVersionTable.PSVersion.ToString()) $($PSVersionTable.PSEdition)"

$error_message = ''
$error_clixml_path = ''
Expand Down Expand Up @@ -205,6 +207,7 @@ function Resolve-EscapeTokens {
$m += $Message.Substring($p2 + 1)

if ($UrlEncode) {
Add-Type -AssemblyName System.Web
$m = [System.Web.HTTPUtility]::UrlEncode($m).Replace('+', '%20')
}

Expand Down Expand Up @@ -329,7 +332,7 @@ function Publish-ToGist {
$listGistsResp = Invoke-WebRequest -Headers $apiHeaders -Uri $gistsApiUrl

## Parse response content as JSON
$listGists = $listGistsResp.Content | ConvertFrom-Json -AsHashtable
$listGists = $listGistsResp.Content | ConvertFrom-Json
Write-ActionInfo "Got [$($listGists.Count)] Gists for current account"

## Isolate the first Gist with a file matching the expected metadata name
Expand Down Expand Up @@ -432,7 +435,7 @@ function Publish-ToGist {
public = $true ## Set thit to false to make it a Secret Gist
files = $gistFiles
} | ConvertTo-Json)
$createGist = $createGistResp.Content | ConvertFrom-Json -AsHashtable
$createGist = $createGistResp.Content | ConvertFrom-Json
$reportGist = $createGist
Write-ActionInfo "Create Response: $createGistResp"
}
Expand Down Expand Up @@ -478,6 +481,6 @@ if ($test_results_path) {
}

if ($stepShouldFail) {
Write-ActionInfo "Thowing error as ne or more tests failed and 'tests_fail_step' was true."
Write-ActionInfo "Thowing error as one or more tests failed and 'tests_fail_step' was true."
throw "One or more tests failed."
}
51 changes: 47 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ description: |
## You also use these to identify the *required* inputs.
inputs:

shell:
description: |
Specifies whether pester should run in Powershell or Windows
PowerShell. Valid values are 'pwsh' (PowerShell) and 'powershell'
(Windows Powershell). Defaults to 'pwsh'. Note that the 'powershell'
option is only valid when run on Windows.
required: false
default: pwsh

test_results_path:
description: |
Path to the test results file which will be used to generate
Expand Down Expand Up @@ -182,51 +191,85 @@ outputs:
was provided to this action, this value will be the same.
Otherwise, this will be the path to where the test results
file was generated from running the resolved Pester tests.
value: ${{ steps.runaction.outputs.test_results_path }}

error_message:
description: |
The summary message of the error returned by Pester, or
empty if no error was produced.
value: ${{ steps.runaction.outputs.error_message }}

error_clixml_path:
description:
If Pester produced an error during invocation, this will
be the path to an export of the full error record in the
CLIXML form. A subsequent PowerShell step can recover
this object using the `Import-Clixml` cmdlet.
value: ${{ steps.runaction.outputs.error_clixml_path }}

result_clixml_path:
description:
If Pester produced an invocation result, this will
be the path to an export of the full result record in the
CLIXML form. A subsequent PowerShell step can recover
this object using the `Import-Clixml` cmdlet.
value: ${{ steps.runaction.outputs.result_clixml_path }}

result_value:
description: |
A single string indicating the final result such as
`Failed` or `Passed`.
value: ${{ steps.runaction.outputs.result_value }}

total_count:
description: Total number of tests discovered.
value: ${{ steps.runaction.outputs.total_count }}

passed_count:
description: Total number of tests passed.
value: ${{ steps.runaction.outputs.passed_count }}

failed_count:
description: Total number of tests failed.
value: ${{ steps.runaction.outputs.failed_count }}

coverage_results_path:
description: |
Path to the code coverage results file in JaCoCo XML format.
value: ${{ steps.runaction.outputs.coverage_results_path }}


branding:
color: purple
icon: check-circle

## Even though the Action logic may be implemented
## in PWSH, we still need a NodeJS entry point
runs:
using: node12
main: _init/index.js
using: composite
steps:
- name: Run Action
id: runaction
run: . "$env:GITHUB_ACTION_PATH\action.ps1"
shell: ${{ inputs.shell }}
env:
INPUT_TEST_RESULTS_PATH: ${{ inputs.test_results_path }}
INPUT_FULL_NAMES_FILTERS: ${{ inputs.full_names_filters }}
INPUT_INCLUDE_PATHS: ${{ inputs.include_paths }}
INPUT_EXCLUDE_PATHS: ${{ inputs.exclude_paths }}
INPUT_INCLUDE_TAGS: ${{ inputs.include_tags }}
INPUT_EXCLUDE_TAGS: ${{ inputs.exclude_tags }}
INPUT_OUTPUT_LEVEL: ${{ inputs.output_level }}
INPUT_REPORT_NAME: ${{ inputs.report_name }}
INPUT_REPORT_TITLE: ${{ inputs.report_title }}
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
INPUT_SKIP_CHECK_RUN: ${{ inputs.skip_check_run }}
INPUT_GIST_NAME: ${{ inputs.gist_name }}
INPUT_GIST_BADGE_LABEL: ${{ inputs.gist_badge_label }}
INPUT_GIST_BADGE_MESSAGE: ${{ inputs.gist_badge_message }}
INPUT_GIST_TOKEN: ${{ inputs.gist_token }}
INPUT_COVERAGE_PATHS: ${{ inputs.coverage_paths }}
INPUT_COVERAGE_REPORT_NAME: ${{ inputs.coverage_report_name }}
INPUT_COVERAGE_REPORT_TITLE: ${{ inputs.coverage_report_title }}
INPUT_COVERAGE_GIST: ${{ inputs.coverage_gist }}
INPUT_COVERAGE_GIST_BADGE_LABEL: ${{ inputs.coverage_gist_badge_label }}
INPUT_TESTS_FAIL_STEP: ${{ inputs.tests_fail_step }}

10 changes: 0 additions & 10 deletions build.ps1

This file was deleted.

14 changes: 0 additions & 14 deletions invoke-pwsh.js

This file was deleted.

2 changes: 1 addition & 1 deletion jacoco-report/embedmissedlines.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ foreach ($line in $mdData) {
}
$workspaceFiles = Get-ChildItem -Path "$env:GITHUB_WORKSPACE" -Recurse -File
$resolvedFilePath = $workspaceFiles | Where-Object {$_.FullName -like "*$filePath"}
$fileContents = Get-Content -Path $resolvedFilePath
$fileContents = Get-Content -Path $resolvedFilePath.FullName
$missedLine = $fileContents[$arrayLineNumber]

$outputData += $linePrefix
Expand Down
4 changes: 2 additions & 2 deletions jacoco-report/jacocoxml2md.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ $script:wrtr = [System.IO.StreamWriter]::new($mdFile)
try {
Write-Verbose "Transforming XML to MD"
$script:readerSettings = [System.Xml.XmlReaderSettings]::new()
$script:readerSettings.DtdProcessing = "Parse"
$script:reader = [System.Xml.XmlReader]::Create($xmlFile,$script:readerSettings)
$script:readerSettings.DtdProcessing = "Ignore"
$script:reader = [System.Xml.XmlReader]::Create($xmlFile, $script:readerSettings)

$script:xslt.Transform(
[System.Xml.XmlReader]$script:reader,
Expand Down
26 changes: 0 additions & 26 deletions package-lock.json

This file was deleted.

15 changes: 0 additions & 15 deletions package.json

This file was deleted.