diff --git a/.github/linters/.markdown-lint.yml b/.github/linters/.markdown-lint.yml new file mode 100644 index 0000000..b9ecdfa --- /dev/null +++ b/.github/linters/.markdown-lint.yml @@ -0,0 +1,25 @@ +########################### +## Markdown Linter rules ## +########################### + +# Linter rules doc: +# - https://github.com/DavidAnson/markdownlint + +############### +# Rules by id # +############### +MD004: false # Unordered list style +MD007: + indent: 2 # Unordered list indentation +MD013: + line_length: 808 # Line length +MD026: + punctuation: ".,;:!。,;:" # List of not allowed +MD029: false # Ordered list item prefix +MD033: false # Allow inline HTML +MD036: false # Emphasis used instead of a heading + +################# +# Rules by tags # +################# +blank_lines: false # Error on blank lines diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..9f0f4ca --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,17 @@ +# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes + +changelog: + categories: + - title: Breaking Changes + labels: + - Major + - Breaking + - title: New Features + labels: + - Minor + - Feature + - Improvement + - Enhancement + - title: Other Changes + labels: + - '*' diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml new file mode 100644 index 0000000..63f9acf --- /dev/null +++ b/.github/workflows/Action-Test.yml @@ -0,0 +1,23 @@ +name: Verify Action + +on: + workflow_call: + push: + paths: + - action.yml + - .github/workflows/Action-Test.yml + - scripts/** + +jobs: + DefaultTest: + name: Test Action - [Default] + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + + - name: Test local action + uses: ./ diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml new file mode 100644 index 0000000..57724be --- /dev/null +++ b/.github/workflows/Auto-Release.yml @@ -0,0 +1,27 @@ +name: Auto-Release + +on: + pull_request: + branches: + - main + types: + - closed + - opened + - reopened + - synchronize + - labeled + +concurrency: + group: ${{ github.workflow }} + +jobs: + Auto-Release: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Auto-Release + uses: PSModule/Auto-Release@v1 + env: + GH_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml new file mode 100644 index 0000000..fa6e15f --- /dev/null +++ b/.github/workflows/Linter.yml @@ -0,0 +1,17 @@ +name: Linter + +on: + pull_request: + +jobs: + Lint: + name: Lint code base + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Lint code base + uses: github/super-linter@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..af4061f --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +## Ignore Visual Studio Code temporary files, build results, and +## files generated by popular Visual Studio Code add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/Global/VisualStudioCode.gitignore +.vscode/* +!.vscode/settings.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ diff --git a/README.md b/README.md index 310f097..f8a7e4f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ -# test -Action that is used to test PowerShell modules +# Test-Module + +Action that is used to test PowerShell modules. + +## Tools + +- [PSScriptAnalyzer | PS Gallery](https://www.powershellgallery.com/packages/PSScriptAnalyzer/) +- [PowerShell Core | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest) +- [PowerShellGet | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/PowerShellGet/test-scriptfileinfo) +- [pester.dev](https://www.pester.dev) +- [Pester | GitHub](https://github.com/Pester/Pester) diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..cdd30bf --- /dev/null +++ b/action.yml @@ -0,0 +1,70 @@ +name: 'Test-PSModule' +description: 'Test a PowerShell module before publishing the module to the PowerShell Gallery.' +branding: + icon: activity + color: blue + +inputs: + Name: + description: 'The name of the module to build.' + required: false + default: '*' + Path: + description: 'The path to the module to build.' + required: false + default: 'outputs' + CustomTestsPath: + description: 'The path to the custom tests to run.' + required: false + default: $null + ErrorAction: + description: 'The action to take if an error occurs.' + required: false + default: 'Stop' + Verbose: + description: 'Enable verbose output.' + required: false + default: 'true' + WhatIf: + description: 'Run in WhatIf mode.' + required: false + default: 'false' + +runs: + using: 'composite' + steps: + - name: Run Test-PSModule + shell: pwsh + run: | + # Test-PSModule + $ErrorActionPreference = '${{ inputs.ErrorAction }}' + + Write-Host '::group::Initializing...' + Write-Output '-------------------------------------------' + Write-Output 'Action inputs:' + $params = @{ + Name = "${{ inputs.Name }}" + Path = Join-Path $env:GITHUB_WORKSPACE '${{ inputs.Path }}' + Verbose = [System.Convert]::ToBoolean('${{ inputs.Verbose }}') + WhatIf = [System.Convert]::ToBoolean('${{ inputs.WhatIf }}') + ErrorAction = $ErrorActionPreference + } + + if (-not [string]::IsNullOrEmpty("${{ inputs.CustomTestsPath }}")) { + $params['CustomTestsPath'] = Join-Path $env:GITHUB_WORKSPACE "${{ inputs.CustomTestsPath }}" + } + + $params.GetEnumerator() | Sort-Object -Property Name + Write-Host '::endgroup::' + + try { + $failedTests = Test-PSModule @params + } catch { + Write-Host "::error::$_" + exit 1 + } + + if ($ErrorActionPreference -like '*Continue') { + Write-Host '::warning::Errors were ignored.' + return + }