|
| 1 | +name: ♻️ ModuleFast CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '*' |
| 7 | + tags: |
| 8 | + - 'v[0-9]*.[0-9]*.[0-9]*' |
| 9 | + pull_request: |
| 10 | + branches: [ main ] |
| 11 | + |
| 12 | +defaults: |
| 13 | + run: |
| 14 | + shell: pwsh |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: 👷 Build |
| 19 | + runs-on: ubuntu-24.04 |
| 20 | + outputs: |
| 21 | + nupkg_artifact_id: ${{ steps.upload_nupkg.outputs.artifact-id }} |
| 22 | + steps: |
| 23 | + - name: 🚚 Checkout |
| 24 | + uses: actions/checkout@v7 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + - name: ⚡ Setup .NET |
| 28 | + uses: actions/setup-dotnet@v5 |
| 29 | + |
| 30 | + - name: ⚡ Cache NuGet packages |
| 31 | + uses: actions/cache@v6 |
| 32 | + with: |
| 33 | + path: | |
| 34 | + ~/.nuget/packages |
| 35 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json', '**/Directory.Packages.props') }} |
| 36 | + restore-keys: | |
| 37 | + ${{ runner.os }}-nuget- |
| 38 | + - name: 👷 Build & Package |
| 39 | + env: |
| 40 | + MODULEVERSION: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || null }} |
| 41 | + run: | |
| 42 | + try { ./build.ps1 BuildNoTest } |
| 43 | + catch { |
| 44 | + "::error::Build failed: $($_.Exception.Message)`n$(Get-Error | Out-String)" -replace "`n","%0A" |
| 45 | + throw |
| 46 | + } |
| 47 | + - name: 📤 Upload Module |
| 48 | + uses: actions/upload-artifact@v7 |
| 49 | + with: |
| 50 | + name: ModuleFast |
| 51 | + path: ./Artifacts/Module |
| 52 | + - name: 📤 Upload Nupkg |
| 53 | + id: upload_nupkg |
| 54 | + uses: actions/upload-artifact@v7 |
| 55 | + with: |
| 56 | + name: ModuleFast-nupkg |
| 57 | + path: ./Artifacts/*.nupkg |
| 58 | + archive: false |
| 59 | + |
| 60 | + test: |
| 61 | + name: 🧪 Test (${{ matrix.os }}) |
| 62 | + needs: build |
| 63 | + strategy: |
| 64 | + fail-fast: false |
| 65 | + matrix: |
| 66 | + os: [ubuntu-24.04, windows-2025] |
| 67 | + runs-on: ${{ matrix.os }} |
| 68 | + steps: |
| 69 | + - name: 🚚 Checkout |
| 70 | + uses: actions/checkout@v7 |
| 71 | + - name: 📥 Download Module |
| 72 | + uses: actions/download-artifact@v8 |
| 73 | + with: |
| 74 | + name: ModuleFast |
| 75 | + path: ./Artifacts/Module |
| 76 | + - name: 🧪 Test |
| 77 | + run: | |
| 78 | + $errorView = 'DetailedView' |
| 79 | + .\build.ps1 Pester |
| 80 | +
|
| 81 | + publish: |
| 82 | + name: 🚢 Publish to PowerShell Gallery |
| 83 | + if: startsWith(github.ref, 'refs/tags/v') |
| 84 | + needs: [build, test] |
| 85 | + environment: |
| 86 | + name: PowerShell Gallery |
| 87 | + url: https://www.powershellgallery.com/packages/ModuleFast |
| 88 | + runs-on: ubuntu-24.04 |
| 89 | + steps: |
| 90 | + - name: 📥 Download Nupkg |
| 91 | + uses: actions/download-artifact@v8 |
| 92 | + with: |
| 93 | + artifact-ids: ${{ needs.build.outputs.nupkg_artifact_id }} |
| 94 | + path: ./Release |
| 95 | + - name: 🚢 Publish to PowerShell Gallery |
| 96 | + env: |
| 97 | + PSGALLERY_API_KEY: ${{ secrets.PSGALLERY }} |
| 98 | + run: | |
| 99 | + $DebugPreference = 'Continue' |
| 100 | + $VerbosePreference = 'Continue' |
| 101 | +
|
| 102 | + $nupkg = Get-ChildItem -Path ./Release/*.nupkg |
| 103 | + if ($nupkg.Count -eq 0) { |
| 104 | + throw "No nupkg found in Release directory" |
| 105 | + } elseif ($nupkg.Count -gt 1) { |
| 106 | + throw "Multiple nupkg files found: $($nupkg.FullName -join ', ')" |
| 107 | + } |
| 108 | +
|
| 109 | + Register-PSResourceRepository -PSGallery -Force |
| 110 | + Publish-PSResource -Nupkg $nupkg.FullName -ApiKey $env:PSGALLERY_API_KEY |
0 commit comments