|
| 1 | +name: Build and Publish to PSGallery |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + paths: |
| 7 | + - 'Public/**' |
| 8 | + - 'Private/**' |
| 9 | + - 'Classes/**' |
| 10 | + - 'Build/**' |
| 11 | + - 'Locksmith2.psm1' |
| 12 | + - 'Locksmith2.psd1' |
| 13 | + - 'LICENSE' |
| 14 | + workflow_dispatch: # Allow manual trigger |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-and-publish: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Install required PowerShell modules |
| 25 | + shell: pwsh |
| 26 | + run: | |
| 27 | + Write-Host "Installing required modules..." -ForegroundColor Cyan |
| 28 | + Install-Module -Name Pester -AllowClobber -Scope CurrentUser -SkipPublisherCheck -Force |
| 29 | + Install-Module -Name PSScriptAnalyzer -AllowClobber -Scope CurrentUser -Force |
| 30 | + Install-Module -Name PSPublishModule -AllowClobber -Scope CurrentUser -Force |
| 31 | + Write-Host "Modules installed successfully" -ForegroundColor Green |
| 32 | +
|
| 33 | + - name: Run Pester tests |
| 34 | + shell: pwsh |
| 35 | + run: | |
| 36 | + Write-Host "Running Pester tests..." -ForegroundColor Cyan |
| 37 | + $testResults = Invoke-Pester -Path ./Tests/ -PassThru -CI -Output Detailed |
| 38 | + Write-Host "Tests completed: $($testResults.PassedCount) passed, $($testResults.FailedCount) failed" -ForegroundColor Cyan |
| 39 | +
|
| 40 | + if ($testResults.FailedCount -gt 0) { |
| 41 | + Write-Host "Tests failed! Build aborted." -ForegroundColor Red |
| 42 | + exit 1 |
| 43 | + } |
| 44 | +
|
| 45 | + Write-Host "All tests passed!" -ForegroundColor Green |
| 46 | +
|
| 47 | + - name: Build and Publish to PowerShell Gallery |
| 48 | + shell: pwsh |
| 49 | + env: |
| 50 | + PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }} |
| 51 | + run: | |
| 52 | + Write-Host "Building and publishing Locksmith2 module..." -ForegroundColor Cyan |
| 53 | + ./Build/Build-Module.ps1 -PublishToPSGallery -PSGalleryAPIKey $env:PSGALLERY_API_KEY |
| 54 | + Write-Host "Published successfully" -ForegroundColor Green |
| 55 | +
|
| 56 | + - name: Get module version |
| 57 | + id: version |
| 58 | + shell: pwsh |
| 59 | + run: | |
| 60 | + $manifest = Import-PowerShellDataFile ./Locksmith2.psd1 |
| 61 | + $version = $manifest.ModuleVersion |
| 62 | + echo "version=$version" >> $env:GITHUB_OUTPUT |
| 63 | + Write-Host "Module version: $version" -ForegroundColor Green |
0 commit comments