Adding end to end tests for the guides and samples #11
Workflow file for this run
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: Test Samples & Guides | |
| on: | |
| pull_request: | |
| branches: [ "main" ] | |
| workflow_run: | |
| workflows: ["Build and Package"] | |
| types: [completed] | |
| workflow_dispatch: | |
| inputs: | |
| sample: | |
| description: 'Specific sample to test (or "all")' | |
| required: false | |
| default: 'all' | |
| type: choice | |
| options: | |
| - all | |
| - cpp-app | |
| - dotnet-app | |
| - electron | |
| - flutter-app | |
| - packaging-cli | |
| - rust-app | |
| - tauri-app | |
| - wpf-app | |
| permissions: | |
| contents: read | |
| actions: read # Required for downloading cross-workflow artifacts | |
| jobs: | |
| # Build npm package for pull_request events (workflow_run already has it) | |
| build: | |
| if: github.event_name == 'pull_request' | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - uses: actions/setup-node@v5 | |
| with: | |
| node-version: '24' | |
| - name: Build npm package | |
| shell: pwsh | |
| run: .\scripts\build-cli.ps1 -SkipTests -SkipMsix | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: npm-package | |
| path: artifacts/*.tgz | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: artifacts/nuget/*.nupkg | |
| if-no-files-found: ignore | |
| test-sample: | |
| needs: [build] | |
| # Run when: PR build succeeded, workflow_run build succeeded, or manual dispatch | |
| if: >- | |
| always() && | |
| (needs.build.result == 'success' || needs.build.result == 'skipped') && | |
| ( | |
| github.event_name == 'pull_request' || | |
| github.event_name == 'workflow_dispatch' || | |
| github.event.workflow_run.conclusion == 'success' | |
| ) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| sample: [cpp-app, dotnet-app, electron, flutter-app, packaging-cli, rust-app, tauri-app, wpf-app] | |
| runs-on: windows-latest | |
| name: ${{ matrix.sample }} | |
| steps: | |
| - name: Check if sample should run | |
| id: check | |
| shell: pwsh | |
| run: | | |
| $requested = '${{ github.event.inputs.sample || 'all' }}' | |
| if ($requested -ne 'all' -and $requested -ne '${{ matrix.sample }}') { | |
| echo "skip=true" >> $env:GITHUB_OUTPUT | |
| } else { | |
| echo "skip=false" >> $env:GITHUB_OUTPUT | |
| } | |
| - name: Checkout | |
| if: steps.check.outputs.skip != 'true' | |
| uses: actions/checkout@v5 | |
| # Download the npm package artifact — source varies by trigger | |
| - name: Download npm package (pull_request) | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| github.event_name == 'pull_request' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: npm-package | |
| path: artifacts/npm | |
| - name: Download npm package (workflow_run) | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| github.event_name == 'workflow_run' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: npm-package | |
| path: artifacts/npm | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download npm package (workflow_dispatch) | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| github.event_name == 'workflow_dispatch' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: npm-package | |
| path: artifacts/npm | |
| continue-on-error: true | |
| # Download NuGet package for .NET samples | |
| - name: Download NuGet package (pull_request) | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| github.event_name == 'pull_request' && | |
| contains(fromJson('["dotnet-app", "wpf-app"]'), matrix.sample) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: artifacts/nuget | |
| continue-on-error: true | |
| - name: Download NuGet package (workflow_run) | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| github.event_name == 'workflow_run' && | |
| contains(fromJson('["dotnet-app", "wpf-app"]'), matrix.sample) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: artifacts/nuget | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| - name: Download NuGet package (workflow_dispatch) | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| github.event_name == 'workflow_dispatch' && | |
| contains(fromJson('["dotnet-app", "wpf-app"]'), matrix.sample) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: artifacts/nuget | |
| continue-on-error: true | |
| - name: Add local NuGet source | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| contains(fromJson('["dotnet-app", "wpf-app"]'), matrix.sample) | |
| shell: pwsh | |
| run: | | |
| $nugetPath = "artifacts/nuget" | |
| if (Test-Path $nugetPath) { | |
| $resolvedPath = (Resolve-Path $nugetPath).Path | |
| dotnet nuget add source $resolvedPath --name WinAppLocal | |
| Write-Host "Added local NuGet source: $resolvedPath" | |
| } else { | |
| Write-Warning "No NuGet artifacts found — .NET samples may fail to restore" | |
| } | |
| # --- Toolchain setup (conditional per sample) --- | |
| - name: Setup .NET | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| contains(fromJson('["dotnet-app", "wpf-app", "packaging-cli", "electron"]'), matrix.sample) | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Setup Node.js | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| contains(fromJson('["electron", "tauri-app", "cpp-app", "dotnet-app", "wpf-app", "rust-app", "flutter-app", "packaging-cli"]'), matrix.sample) | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: '24' | |
| - name: Setup Flutter | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| matrix.sample == 'flutter-app' | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| channel: stable | |
| - name: Setup Rust | |
| if: >- | |
| steps.check.outputs.skip != 'true' && | |
| contains(fromJson('["rust-app", "tauri-app"]'), matrix.sample) | |
| uses: dtolnay/rust-toolchain@stable | |
| # --- Run the sample's self-contained Pester test --- | |
| - name: Install Pester | |
| if: steps.check.outputs.skip != 'true' | |
| shell: pwsh | |
| run: | | |
| Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.0 | |
| - name: Run ${{ matrix.sample }} test | |
| if: steps.check.outputs.skip != 'true' | |
| shell: pwsh | |
| run: | | |
| $winappPath = "artifacts/npm" | |
| if (-not (Test-Path $winappPath)) { | |
| $winappPath = "src/winapp-npm" | |
| } | |
| $container = New-PesterContainer -Path "samples/${{ matrix.sample }}/test.Tests.ps1" -Data @{ | |
| WinappPath = $winappPath | |
| } | |
| $config = New-PesterConfiguration | |
| $config.Run.Container = $container | |
| $config.Run.Exit = $true | |
| $config.Output.Verbosity = 'Detailed' | |
| $config.TestResult.Enabled = $true | |
| $config.TestResult.OutputPath = "test-results-${{ matrix.sample }}.xml" | |
| $config.TestResult.OutputFormat = 'JUnitXml' | |
| Invoke-Pester -Configuration $config | |
| - name: Upload test results | |
| if: always() && steps.check.outputs.skip != 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ matrix.sample }} | |
| path: test-results-${{ matrix.sample }}.xml | |
| if-no-files-found: ignore | |
| # Summary job to provide a single check status for branch protection | |
| test-samples-result: | |
| if: always() | |
| needs: [build, test-sample] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check results | |
| run: | | |
| if [ "${{ needs.test-sample.result }}" = "failure" ]; then | |
| echo "::error::One or more sample tests failed" | |
| exit 1 | |
| fi | |
| echo "All sample tests passed (or were skipped)" |