|
1 | | -name: CI |
| 1 | +name: Build & Test |
2 | 2 |
|
3 | | -on: |
4 | | - workflow_dispatch: |
5 | | - inputs: |
6 | | - configuration: |
7 | | - description: 'Build configuration' |
8 | | - required: true |
9 | | - default: 'Release' |
10 | | - type: choice |
11 | | - options: |
12 | | - - Debug |
13 | | - - Release |
14 | | - - All |
15 | | - targetFramework: |
16 | | - description: 'Target framework' |
17 | | - required: true |
18 | | - default: 'net8.0-windows' |
19 | | - noRestore: |
20 | | - description: 'Skip dotnet restore' |
21 | | - required: false |
22 | | - default: 'false' |
23 | | - type: boolean |
24 | | - verbose: |
25 | | - description: 'Verbose dotnet output' |
26 | | - required: false |
27 | | - default: 'false' |
28 | | - type: boolean |
| 3 | +on: [push, pull_request] |
29 | 4 |
|
30 | 5 | jobs: |
31 | 6 | build: |
32 | | - name: Build (${{ matrix.configuration }}) |
33 | 7 | runs-on: windows-latest |
34 | | - # Run this matrix row only if user asked for All or it matches the chosen configuration |
35 | | - if: ${{ github.event.inputs.configuration == 'All' || matrix.configuration == github.event.inputs.configuration }} |
36 | | - strategy: |
37 | | - fail-fast: false |
38 | | - matrix: |
39 | | - configuration: [Debug, Release] |
40 | | - |
41 | | - env: |
42 | | - PROJECT_PATH: src/IoTPowerShellAgent/IoTPowerShellAgent.csproj |
43 | | - TARGET_FRAMEWORK: ${{ github.event.inputs.targetFramework }} |
44 | | - VERBOSE_FLAG: ${{ github.event.inputs.verbose == 'true' ? '--verbosity detailed' : '--verbosity minimal' }} |
45 | | - NO_RESTORE_FLAG: ${{ github.event.inputs.noRestore == 'true' ? '--no-restore' : '' }} |
46 | | - |
47 | 8 | steps: |
48 | | - - name: Checkout |
49 | | - uses: actions/checkout@v4 |
50 | | - |
51 | | - - name: Setup .NET SDK |
52 | | - uses: actions/setup-dotnet@v3 |
| 9 | + - uses: actions/checkout@v4 |
53 | 10 | with: |
54 | | - dotnet-version: '8.0.x' |
55 | | - |
56 | | - - name: Show .NET SDK version |
57 | | - run: dotnet --version |
| 11 | + fetch-depth: 0 # Fetch all history for semantic versioning |
58 | 12 |
|
59 | | - - name: Cache NuGet packages |
60 | | - uses: actions/cache@v4 |
| 13 | + - uses: actions/setup-dotnet@v4 |
61 | 14 | with: |
62 | | - path: ~/.nuget/packages |
63 | | - # fallback to OS-based key if no lock file is present |
64 | | - key: nuget-${{ runner.os }}-${{ hashFiles('**/packages.lock.json') }} |
65 | | - restore-keys: | |
66 | | - nuget-${{ runner.os }}- |
| 15 | + dotnet-version: "8.0.x" |
| 16 | + |
| 17 | + - name: Determine version from Git tag |
| 18 | + id: version |
| 19 | + run: | |
| 20 | + $tag = git describe --tags --abbrev=0 2>$null |
| 21 | + if ($tag) { |
| 22 | + $version = $tag -replace '^v', '' |
| 23 | + Write-Host "Version from tag: $version" |
| 24 | + echo "version=$version" >> $env:GITHUB_OUTPUT |
| 25 | + } else { |
| 26 | + Write-Host "No tag found, using default version" |
| 27 | + echo "version=1.0.0" >> $env:GITHUB_OUTPUT |
| 28 | + } |
| 29 | + shell: pwsh |
67 | 30 |
|
68 | | - - name: Restore (conditional) |
69 | | - if: ${{ github.event.inputs.noRestore != 'true' }} |
70 | | - run: dotnet restore ${{ env.PROJECT_PATH }} |
| 31 | + - name: Restore dependencies |
| 32 | + run: dotnet restore |
71 | 33 |
|
72 | 34 | - name: Build |
73 | | - shell: pwsh |
74 | | - run: | |
75 | | - Write-Host "Building project: $env:PROJECT_PATH" |
76 | | - Write-Host "Configuration: ${{ matrix.configuration }}" |
77 | | - Write-Host "Framework: $env:TARGET_FRAMEWORK" |
78 | | - dotnet build "$env:PROJECT_PATH" ` |
79 | | - --configuration "${{ matrix.configuration }}" ` |
80 | | - --framework "$env:TARGET_FRAMEWORK" ` |
81 | | - --no-incremental ` |
82 | | - $env:NO_RESTORE_FLAG ` |
83 | | - $env:VERBOSE_FLAG ` |
84 | | - /p:BuildInParallel=true ` |
85 | | - /p:Deterministic=true ` |
86 | | - /p:EnableSourceLink=true ` |
87 | | - /p:GenerateAssemblyInfo=true |
| 35 | + run: dotnet build --no-restore /p:Version=${{ steps.version.outputs.version }} |
88 | 36 |
|
89 | | - - name: Show output file info (if present) |
90 | | - if: always() |
| 37 | + - name: Test |
| 38 | + run: dotnet test --no-build --logger trx |
| 39 | + |
| 40 | + - name: Run Pester Tests |
91 | 41 | shell: pwsh |
92 | 42 | run: | |
93 | | - $out = Join-Path $PWD "src/IoTPowerShellAgent/bin/${{ matrix.configuration }}/$($env:TARGET_FRAMEWORK)" |
94 | | - Write-Host "Looking for output in: $out" |
95 | | - if (Test-Path $out) { |
96 | | - Get-ChildItem -Path $out -File -Recurse | ForEach-Object { |
97 | | - $sizeMB = [math]::Round($_.Length / 1MB, 2) |
98 | | - Write-Host "$($_.FullName) - $sizeMB MB" |
99 | | - } |
| 43 | + if (Test-Path "src\IoTPowerShellAgent.Tests.Pester\run-pester.ps1") { |
| 44 | + Set-Location src\IoTPowerShellAgent.Tests.Pester |
| 45 | + .\run-pester.ps1 -OutputFormat NUnitXml -OutputFile PesterResults.xml |
| 46 | + Set-Location ..\.. |
100 | 47 | } else { |
101 | | - Write-Host "Output directory not found." |
| 48 | + Write-Host "Pester tests not found, skipping..." |
102 | 49 | } |
103 | 50 |
|
104 | | - - name: Upload build artifacts |
105 | | - uses: actions/upload-artifact@v4 |
| 51 | + - name: Publish test results |
| 52 | + if: always() |
| 53 | + uses: EnricoMi/publish-unit-test-result-action@v2 |
106 | 54 | with: |
107 | | - name: IoTPowerShellAgent-${{ matrix.configuration }} |
108 | | - path: src/IoTPowerShellAgent/bin/${{ matrix.configuration }}/$${{ github.event.inputs.targetFramework }} |
| 55 | + files: "**/*.trx,**/PesterResults.xml" |
0 commit comments