|
| 1 | +name: Publish plugins |
| 2 | + |
| 3 | +# Plugin packages are released independently from the host: |
| 4 | +# * The host's release workflow (release.yml) handles the Velopack |
| 5 | +# installer + draft GitHub Release; it does NOT touch nuget.org. |
| 6 | +# * This workflow handles plugin .nupkg publish. Run it manually |
| 7 | +# whenever a plugin's <Version> in its csproj changes. |
| 8 | +# |
| 9 | +# Each plugin tracks its own version in its csproj. nuget.org's |
| 10 | +# `--skip-duplicate` makes pushing an unchanged version a no-op, so |
| 11 | +# selecting "all" never republishes versions that already exist. |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + plugin: |
| 17 | + description: Which package to publish |
| 18 | + type: choice |
| 19 | + required: true |
| 20 | + default: all |
| 21 | + options: |
| 22 | + - all |
| 23 | + - Contracts |
| 24 | + - PIM |
| 25 | + - LAPS |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | + id-token: write # for attest-build-provenance |
| 30 | + attestations: write # for attest-build-provenance |
| 31 | + |
| 32 | +concurrency: |
| 33 | + group: publish-plugins |
| 34 | + cancel-in-progress: false |
| 35 | + |
| 36 | +jobs: |
| 37 | + publish: |
| 38 | + runs-on: windows-latest |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + fetch-depth: 0 # SourceLink needs commit history |
| 45 | + |
| 46 | + - name: Setup .NET |
| 47 | + uses: actions/setup-dotnet@v4 |
| 48 | + with: |
| 49 | + global-json-file: global.json |
| 50 | + |
| 51 | + - name: Restore |
| 52 | + run: dotnet restore AzureTray.sln |
| 53 | + |
| 54 | + - name: Build (Release) |
| 55 | + run: dotnet build AzureTray.sln --configuration Release --no-restore |
| 56 | + |
| 57 | + # Pack only the selected projects. Each csproj declares its own |
| 58 | + # <Version> so no /p:Version override is passed — the package |
| 59 | + # version is whatever the csproj says. |
| 60 | + - name: Pack |
| 61 | + shell: pwsh |
| 62 | + run: | |
| 63 | + $plugin = '${{ github.event.inputs.plugin }}' |
| 64 | + $projects = @{ |
| 65 | + 'Contracts' = 'src/AzureTray.Plugin.Contracts/AzureTray.Plugin.Contracts.csproj' |
| 66 | + 'PIM' = 'src/AzureTray.Plugin.PIM/AzureTray.Plugin.PIM.csproj' |
| 67 | + 'LAPS' = 'src/AzureTray.Plugin.LAPS/AzureTray.Plugin.LAPS.csproj' |
| 68 | + } |
| 69 | + $selected = if ($plugin -eq 'all') { $projects.Values } else { @($projects[$plugin]) } |
| 70 | +
|
| 71 | + if (-not (Test-Path NuGet)) { New-Item -ItemType Directory -Path NuGet | Out-Null } |
| 72 | + foreach ($csproj in $selected) { |
| 73 | + Write-Host "Packing $csproj …" -ForegroundColor Cyan |
| 74 | + dotnet pack $csproj --configuration Release --no-build --output NuGet |
| 75 | + if ($LASTEXITCODE -ne 0) { throw "dotnet pack failed for $csproj" } |
| 76 | + } |
| 77 | +
|
| 78 | + - name: Upload nupkgs as artifact |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: plugin-packages |
| 82 | + path: NuGet/*.nupkg |
| 83 | + if-no-files-found: error |
| 84 | + |
| 85 | + - name: Attest build provenance |
| 86 | + uses: actions/attest-build-provenance@v2 |
| 87 | + with: |
| 88 | + subject-path: NuGet/*.nupkg |
| 89 | + |
| 90 | + - name: Check NuGet config |
| 91 | + id: nugetcfg |
| 92 | + shell: pwsh |
| 93 | + env: |
| 94 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 95 | + run: | |
| 96 | + $enabled = -not [string]::IsNullOrWhiteSpace($env:NUGET_API_KEY) |
| 97 | + "enabled=$($enabled.ToString().ToLower())" >> $env:GITHUB_OUTPUT |
| 98 | + Write-Host "Push to nuget.org enabled: $enabled" |
| 99 | +
|
| 100 | + - name: Push to nuget.org |
| 101 | + if: steps.nugetcfg.outputs.enabled == 'true' |
| 102 | + shell: pwsh |
| 103 | + env: |
| 104 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 105 | + run: | |
| 106 | + # --skip-duplicate keeps re-runs idempotent: a plugin whose |
| 107 | + # csproj version hasn't been bumped since its last publish |
| 108 | + # is a no-op rather than a failure. |
| 109 | + $packages = Get-ChildItem NuGet\*.nupkg | Where-Object { $_.Name -notlike '*.symbols.nupkg' } |
| 110 | + foreach ($pkg in $packages) { |
| 111 | + Write-Host "Pushing $($pkg.Name)…" |
| 112 | + dotnet nuget push $pkg.FullName ` |
| 113 | + --api-key $env:NUGET_API_KEY ` |
| 114 | + --source https://api.nuget.org/v3/index.json ` |
| 115 | + --skip-duplicate |
| 116 | + if ($LASTEXITCODE -ne 0) { throw "nuget push failed for $($pkg.Name)" } |
| 117 | + } |
0 commit comments