Workflow-Test [Default] - pull_request [🩹 [Patch]: Workflow artifacts stay isolated] by @MariusStorhaug #1995
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Workflow-Test [Default] | |
| run-name: 'Workflow-Test [Default] - ${{ github.event_name }} [${{ github.event.pull_request.title || github.event.head_commit.message || github.ref_name }}] by @${{ github.actor }}' | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '.github/actions/**' | |
| - '.github/workflows/**' | |
| - 'tests/srcTestRepo/**' | |
| - '!.github/workflows/Release.yml' | |
| - '!.github/workflows/Linter.yml' | |
| pull_request: | |
| types: | |
| - closed | |
| - opened | |
| - reopened | |
| - synchronize | |
| - labeled | |
| - unlabeled | |
| paths: | |
| - '.github/actions/**' | |
| - '.github/workflows/**' | |
| - 'tests/srcTestRepo/**' | |
| - '!.github/workflows/Release.yml' | |
| - '!.github/workflows/Linter.yml' | |
| schedule: | |
| - cron: '0 0 * * *' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| jobs: | |
| WorkflowTestDefault: | |
| if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} | |
| uses: ./.github/workflows/workflow.yml | |
| secrets: | |
| PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }} | |
| GitHubAppClientId: ${{ secrets.SHELLY_CLIENT_ID }} | |
| GitHubAppPrivateKey: ${{ secrets.SHELLY_PRIVATE_KEY }} | |
| TestData: >- | |
| { | |
| "secrets": { | |
| "PSMODULE_TEST_SINGLELINE_SECRET": "${{ secrets.PSMODULE_TEST_SINGLELINE_SECRET }}" | |
| }, | |
| "variables": { | |
| "PSMODULE_TEST_VARIABLE": ${{ toJSON(vars.PSMODULE_TEST_VARIABLE) }} | |
| } | |
| } | |
| with: | |
| WorkingDirectory: tests/srcTestRepo | |
| ImportantFilePatterns: | | |
| ^tests/srcTestRepo/ | |
| ^\.github/actions/ | |
| ^\.github/workflows/(?!Release\.yml$|Linter\.yml$) | |
| VerifyRootFunctionsIndexDefault: | |
| if: github.event.action != 'closed' | |
| name: Verify root Functions index [Default] | |
| runs-on: ubuntu-latest | |
| needs: | |
| - WorkflowTestDefault | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - name: Verify generated artifacts remain isolated | |
| shell: pwsh | |
| run: | | |
| $runnerOsExpression = '$' + '{{ runner.os }}' | |
| $expectedAnalyzerReportPaths = @{ | |
| '.github/workflows/Test-Module.yml' = "TestResult_OutputPath: .PSModule/TestResult/PSModuleLint-Module-$runnerOsExpression-TestResult-Report.xml" | |
| '.github/workflows/Lint-SourceCode.yml' = "TestResult_OutputPath: .PSModule/TestResult/PSModuleLint-SourceCode-$runnerOsExpression-TestResult-Report.xml" | |
| } | |
| foreach ($workflowPath in $expectedAnalyzerReportPaths.Keys) { | |
| $content = Get-Content -Path $workflowPath -Raw | |
| $expectedPath = $expectedAnalyzerReportPaths[$workflowPath] | |
| if (-not $content.Contains($expectedPath)) { | |
| throw "Expected isolated analyzer report path was not found in $workflowPath." | |
| } | |
| $expectedAction = 'uses: PSModule/Invoke-ScriptAnalyzer@9acddbd55ff4634b738be3a219c76e3676aaf1cd # v5.0.1' | |
| if (-not $content.Contains($expectedAction)) { | |
| throw "Expected released analyzer action pin was not found in $workflowPath." | |
| } | |
| } | |
| $buildDocsWorkflow = Get-Content -Path '.github/workflows/Build-Docs.yml' -Raw | |
| $forbiddenStagingPatterns = @( | |
| 'Rename-Item\s+-Path\s+[''"]\.gitignore[''"]' | |
| 'git add \.' | |
| 'PSModule/GitHub-Script' | |
| ) | |
| foreach ($pattern in $forbiddenStagingPatterns) { | |
| if ($buildDocsWorkflow -match $pattern) { | |
| throw "Build-Docs.yml must not use generated-artifact staging: $pattern" | |
| } | |
| } | |
| $legacyArtifactPaths = @( | |
| 'tests/srcTestRepo/TestResult' | |
| 'tests/srcTestRepo/CodeCoverage' | |
| 'tests/srcTestRepo/.temp' | |
| ) | |
| foreach ($path in $legacyArtifactPaths) { | |
| if (Test-Path -Path $path) { | |
| throw "Legacy root artifact path was created: $path" | |
| } | |
| } | |
| - name: Download docs artifact | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: docs | |
| path: tests/srcTestRepo/.PSModule/docs | |
| - name: Verify generated Functions index | |
| shell: pwsh | |
| run: | | |
| $path = 'tests/srcTestRepo/.PSModule/docs/index.md' | |
| if (-not (Test-Path -Path $path)) { | |
| throw 'Expected root Functions index at ' + | |
| 'tests/srcTestRepo/.PSModule/docs/index.md.' | |
| } | |
| $content = Get-Content -Path $path -Raw | |
| $expectedSnippets = @( | |
| '# Functions' | |
| 'This landing page is authored from the root of ' + | |
| '`src/functions/public`.' | |
| 'Use it to introduce the module''s function surface ' + | |
| 'before readers drill into each group.' | |
| ) | |
| foreach ($snippet in $expectedSnippets) { | |
| if (-not $content.Contains($snippet)) { | |
| throw 'Expected snippet not found in generated root ' + | |
| "Functions index: $snippet" | |
| } | |
| } |