diff --git a/.github/workflows/Workflow-Test.yml b/.github/workflows/Workflow-Test.yml index c3113ac9..c4b47330 100644 --- a/.github/workflows/Workflow-Test.yml +++ b/.github/workflows/Workflow-Test.yml @@ -6,8 +6,11 @@ on: [pull_request] jobs: WorkflowTestDefault: - uses: ./.github/workflows/workflow.yml + uses: ./.github/workflows/workflow.test.yml secrets: inherit with: Name: PSModule + Path: tests/src + ModulesOutputPath: tests/outputs/modules + DocsOutputPath: tests/outputs/docs TestProcess: true diff --git a/.github/workflows/workflow.test.yml b/.github/workflows/workflow.test.yml new file mode 100644 index 00000000..56dc7518 --- /dev/null +++ b/.github/workflows/workflow.test.yml @@ -0,0 +1,97 @@ +name: Process-PSModule + +on: + workflow_call: + secrets: + APIKey: + description: The API key to use when publishing modules + required: true + inputs: + Name: + type: string + description: The name of the module to process. Scripts default to the repository name if nothing is specified. + required: false + Path: + type: string + description: The path to the source code of the module. + required: false + default: src + ModulesOutputPath: + type: string + description: The path to the output directory for the modules. + required: false + default: outputs/modules + DocsOutputPath: + type: string + description: The path to the output directory for the documentation. + required: false + default: outputs/docs + SkipTests: + type: boolean + description: Whether to skip tests. + required: false + default: false + TestProcess: + type: boolean + description: Whether to test the process. + required: false + default: false + +env: + GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication + +jobs: + Process-PSModule: + name: Process module + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Checkout tests -> PSModuleTest + uses: actions/checkout@v4 + if: ${{ inputs.TestProcess == true }} + with: + repository: PSModule/PSModuleTest + path: tests + + - name: Delete outputs + if: ${{ inputs.TestProcess == true }} + shell: pwsh + run: | + Remove-Item -Path tests/outputs -Recurse -Force -Verbose + + - name: Initialize environment + uses: PSModule/Initialize-PSModule@v1 + + - name: Test source code + uses: PSModule/Test-PSModule@v1 + if: ${{ inputs.SkipTests != true }} + with: + Name: ${{ inputs.Name }} + Path: ${{ inputs.Path }} + RunModuleTests: false + + - name: Build module + uses: PSModule/Build-PSModule@v1 + with: + Name: ${{ inputs.Name }} + Path: ${{ inputs.Path }} + ModulesOutputPath: ${{ inputs.ModulesOutputPath }} + DocsOutputPath: ${{ inputs.DocsOutputPath }} + + - name: Test built module + uses: PSModule/Test-PSModule@v1 + if: ${{ inputs.SkipTests != true }} + with: + Name: ${{ inputs.Name }} + Path: ${{ inputs.ModulesOutputPath }} + + - name: Publish module + uses: PSModule/Publish-PSModule@v1 + with: + Name: ${{ inputs.Name }} + ModulePath: ${{ inputs.ModulesOutputPath }} + DocsPath: ${{ inputs.DocsOutputPath }} + APIKey: ${{ secrets.APIKEY }} + WhatIf: ${{ inputs.TestProcess }} diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 393e7bfd..93598307 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -11,6 +11,21 @@ on: type: string description: The name of the module to process. Scripts default to the repository name if nothing is specified. required: false + Path: + type: string + description: The path to the source code of the module. + required: false + default: src + ModulesOutputPath: + type: string + description: The path to the output directory for the modules. + required: false + default: outputs/modules + DocsOutputPath: + type: string + description: The path to the output directory for the documentation. + required: false + default: outputs/docs SkipTests: type: boolean description: Whether to skip tests. @@ -41,29 +56,29 @@ jobs: if: ${{ inputs.SkipTests != true }} with: Name: ${{ inputs.Name }} - Path: src + Path: ${{ inputs.Path }} RunModuleTests: false - name: Build module uses: PSModule/Build-PSModule@v1 with: Name: ${{ inputs.Name }} - Path: src - ModulesOutputPath: outputs/modules - DocsOutputPath: outputs/docs + Path: ${{ inputs.Path }} + ModulesOutputPath: ${{ inputs.ModulesOutputPath }} + DocsOutputPath: ${{ inputs.DocsOutputPath }} - name: Test built module uses: PSModule/Test-PSModule@v1 if: ${{ inputs.SkipTests != true }} with: Name: ${{ inputs.Name }} - Path: outputs/modules + Path: ${{ inputs.ModulesOutputPath }} - name: Publish module uses: PSModule/Publish-PSModule@v1 with: Name: ${{ inputs.Name }} - ModulePath: outputs/modules - DocsPath: outputs/docs + ModulePath: ${{ inputs.ModulesOutputPath }} + DocsPath: ${{ inputs.DocsOutputPath }} APIKey: ${{ secrets.APIKEY }} WhatIf: ${{ inputs.TestProcess }} diff --git a/README.md b/README.md index 2e76e334..df0500b3 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,11 @@ The workflow is designed to be trigger on pull requests to the repository's defa When a pull request is opened, closed, reopened, synchronized (push), or labeled, the workflow will run. Depending on the labels in the pull requests, the workflow will result in different outcomes. -- [Initialize-PSModule](https://github.com/PSModule/Initialize-PSModule/) - To prepare the runner for all requirements of the framework. -- [Test-PSModule](https://github.com/PSModule/Test-PSModule/) - Testing the source code using only PSScriptAnalyzer and the PSModule test suites. -- [Build-PSModule](https://github.com/PSModule/Build-PSModule/) - To compile the repository into an efficient PowerShell module. -- [Test-PSModule](https://github.com/PSModule/Test-PSModule/) - Testing the compiled module using PSScriptAnalyzer, PSModule test suites and custom module tests. -- [Publish-PSModule](https://github.com/PSModule/Publish-PSModule/) - Publish the module to the PowerShell Gallery, publish docs to GitHub Pages, and create a release on the GitHub repository. +- [Initialize-PSModule](https://github.com/PSModule/Initialize-PSModule/) - Prepares the runner with all the framework requirements. +- [Test-PSModule](https://github.com/PSModule/Test-PSModule/) - Tests the source code using only PSScriptAnalyzer and the PSModule test suites. +- [Build-PSModule](https://github.com/PSModule/Build-PSModule/) - Compiles the repository into an efficient PowerShell module. +- [Test-PSModule](https://github.com/PSModule/Test-PSModule/) - Tests the compiled module using PSScriptAnalyzer, PSModule and module tests suites from the module repository. +- [Publish-PSModule](https://github.com/PSModule/Publish-PSModule/) - Publishes the module to the PowerShell Gallery, docs to GitHub Pages, and creates a release on the GitHub repository. To use the workflow, create a new file in the `.github/workflows` directory of the module repository and add the following content.
@@ -64,6 +64,9 @@ jobs: | Name | Type | Description | Required | Default | | ---- | ---- | ----------- | -------- | ------- | | `Name` | `string` | The name of the module to process. This defaults to the repository name if nothing is specified. | `false` | N/A | +| `Path` | `string` | The path to the source code of the module. | `false` | `src` | +| `ModulesOutputPath` | `string` | The path to the output directory for the modules. | `false` | `outputs/modules` | +| `DocsOutputPath` | `string` | The path to the output directory for the documentation. | `false` | `outputs/docs` | | `SkipTests` | `boolean` | Whether to skip the tests. | false | `false` | | `TestProcess` | `boolean` | Whether to test the process. | false | `false` | diff --git a/src/PSModule/PSModule.psd1 b/src/PSModule/PSModule.psd1 deleted file mode 100644 index f2ac5e28..00000000 --- a/src/PSModule/PSModule.psd1 +++ /dev/null @@ -1,5 +0,0 @@ -@{ - ModuleVersion = '0.0.1' - RootModule = 'PSModule.psm1' - Description = 'PSModule Framework Test Module' -} diff --git a/src/PSModule/PSModule.psm1 b/src/PSModule/PSModule.psm1 deleted file mode 100644 index 302c035f..00000000 --- a/src/PSModule/PSModule.psm1 +++ /dev/null @@ -1,32 +0,0 @@ -[Cmdletbinding()] -param() - -Write-Verbose 'Importing subcomponents' -$Folders = 'classes', 'private', 'public' -# Import everything in these folders -Foreach ($Folder in $Folders) { - $Root = Join-Path -Path $PSScriptRoot -ChildPath $Folder - Write-Verbose "Processing folder: $Root" - if (Test-Path -Path $Root) { - Write-Verbose "Getting all files in $Root" - $Files = $null - $Files = Get-ChildItem -Path $Root -Include '*.ps1', '*.psm1' -Recurse - # dot source each file - foreach ($File in $Files) { - Write-Verbose "Importing $($File)" - Import-Module $File - Write-Verbose "Importing $($File): Done" - } - } -} - -$Param = @{ - Function = (Get-ChildItem -Path "$PSScriptRoot\public" -Include '*.ps1' -Recurse).BaseName - Variable = '*' - Cmdlet = '*' - Alias = '*' -} - -Write-Verbose 'Exporting module members' - -Export-ModuleMember @Param diff --git a/src/PSModule/public/Test-PSModule.ps1 b/src/PSModule/public/Test-PSModule.ps1 deleted file mode 100644 index 131dcffb..00000000 --- a/src/PSModule/public/Test-PSModule.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -Function Test-PSModule { - <# - .SYNOPSIS - Performs tests on a module. - - .EXAMPLE - Test-PSModule -Name 'World' - - "Hello, World!" - #> - [CmdletBinding()] - param ( - # Name of the person to greet. - [Parameter(Mandatory)] - [string] $Name - ) - Write-Output "Hello, $Name!" -} diff --git a/tests/PSModule.Tests.ps1 b/tests/PSModule.Tests.ps1 deleted file mode 100644 index 2e152118..00000000 --- a/tests/PSModule.Tests.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -Describe 'PSModule.Tests.ps1' { - It "Should be able to import the module" { - Import-Module -Name 'PSModule' - Get-Module -Name 'PSModule' | Should -Not -BeNullOrEmpty - Write-Verbose (Get-Module -Name 'PSModule' | Out-String) -Verbose - } - It "Should be able to call the function" { - Test-PSModule -Name 'World' | Should -Be "Hello, World!" - Write-Verbose (Test-PSModule -Name 'World' | Out-String) -Verbose - } -}