|
| 1 | +name: Publish NuGet Packages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' # e.g. v1.2.3 |
| 7 | + - 'v[0-9]+.[0-9]+.[0-9]+-*' # e.g. v1.2.3-beta.1 |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version: |
| 11 | + description: 'Package version (e.g. 1.2.3 or 1.2.3-beta.1) — overrides the tag' |
| 12 | + required: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write # needed to create the GitHub Release |
| 16 | + |
| 17 | +env: |
| 18 | + DOTNET_NOLOGO: true |
| 19 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + # ───────────────────────────────────────────────────────────────────────────── |
| 23 | + # 1. Resolve the version string from tag or manual input |
| 24 | + # ───────────────────────────────────────────────────────────────────────────── |
| 25 | + resolve-version: |
| 26 | + name: Resolve version |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + version: ${{ steps.ver.outputs.version }} |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Determine version |
| 33 | + id: ver |
| 34 | + run: | |
| 35 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 36 | + VERSION="${{ github.event.inputs.version }}" |
| 37 | + else |
| 38 | + # Strip leading 'v' from tag (v1.2.3 → 1.2.3) |
| 39 | + VERSION="${GITHUB_REF_NAME#v}" |
| 40 | + fi |
| 41 | + echo "Resolved version: $VERSION" |
| 42 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 43 | +
|
| 44 | + # ───────────────────────────────────────────────────────────────────────────── |
| 45 | + # 2. Pack KumikoUI.Core and KumikoUI.SkiaSharp (plain net9.0 — Linux is fine) |
| 46 | + # ───────────────────────────────────────────────────────────────────────────── |
| 47 | + pack-core: |
| 48 | + name: Pack Core & SkiaSharp |
| 49 | + runs-on: ubuntu-latest |
| 50 | + needs: resolve-version |
| 51 | + env: |
| 52 | + VERSION: ${{ needs.resolve-version.outputs.version }} |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + |
| 57 | + - name: Setup .NET 9 |
| 58 | + uses: actions/setup-dotnet@v4 |
| 59 | + with: |
| 60 | + dotnet-version: '9.x' |
| 61 | + |
| 62 | + - name: Restore |
| 63 | + run: | |
| 64 | + dotnet restore src/KumikoUI.Core/KumikoUI.Core.csproj |
| 65 | + dotnet restore src/KumikoUI.SkiaSharp/KumikoUI.SkiaSharp.csproj |
| 66 | +
|
| 67 | + - name: Pack — MauiKumikoUI.Core |
| 68 | + run: | |
| 69 | + dotnet pack src/KumikoUI.Core/KumikoUI.Core.csproj \ |
| 70 | + --no-restore \ |
| 71 | + -c Release \ |
| 72 | + -p:Version=${{ env.VERSION }} \ |
| 73 | + --include-symbols \ |
| 74 | + -p:SymbolPackageFormat=snupkg \ |
| 75 | + -o ./artifacts |
| 76 | +
|
| 77 | + - name: Pack — MauiKumikoUI.SkiaSharp |
| 78 | + run: | |
| 79 | + dotnet pack src/KumikoUI.SkiaSharp/KumikoUI.SkiaSharp.csproj \ |
| 80 | + --no-restore \ |
| 81 | + -c Release \ |
| 82 | + -p:Version=${{ env.VERSION }} \ |
| 83 | + --include-symbols \ |
| 84 | + -p:SymbolPackageFormat=snupkg \ |
| 85 | + -o ./artifacts |
| 86 | +
|
| 87 | + - name: List artifacts |
| 88 | + run: ls -lh artifacts/ |
| 89 | + |
| 90 | + - name: Upload Core + SkiaSharp packages |
| 91 | + uses: actions/upload-artifact@v4 |
| 92 | + with: |
| 93 | + name: nuget-core-skiasharp |
| 94 | + path: artifacts/*.nupkg |
| 95 | + if-no-files-found: error |
| 96 | + |
| 97 | + - name: Upload Core + SkiaSharp symbol packages |
| 98 | + uses: actions/upload-artifact@v4 |
| 99 | + with: |
| 100 | + name: snupkg-core-skiasharp |
| 101 | + path: artifacts/*.snupkg |
| 102 | + if-no-files-found: warn |
| 103 | + |
| 104 | + # ───────────────────────────────────────────────────────────────────────────── |
| 105 | + # 3. Pack KumikoUI.Maui (multi-target MAUI — needs Windows for Windows TFM) |
| 106 | + # ───────────────────────────────────────────────────────────────────────────── |
| 107 | + pack-maui: |
| 108 | + name: Pack KumikoUI.Maui (all TFMs) |
| 109 | + runs-on: windows-latest |
| 110 | + needs: resolve-version |
| 111 | + env: |
| 112 | + VERSION: ${{ needs.resolve-version.outputs.version }} |
| 113 | + |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v4 |
| 116 | + |
| 117 | + - name: Setup .NET 9 + 10 |
| 118 | + uses: actions/setup-dotnet@v4 |
| 119 | + with: |
| 120 | + dotnet-version: | |
| 121 | + 9.x |
| 122 | + 10.x |
| 123 | +
|
| 124 | + - name: Cache MAUI workloads |
| 125 | + uses: actions/cache@v4 |
| 126 | + id: workload-cache |
| 127 | + with: |
| 128 | + path: | |
| 129 | + ${{ env.USERPROFILE }}\.dotnet\toolResolverCache |
| 130 | + ${{ env.PROGRAMFILES }}\dotnet\packs |
| 131 | + ${{ env.PROGRAMFILES }}\dotnet\metadata\workloads |
| 132 | + ${{ env.PROGRAMFILES }}\dotnet\sdk-manifests |
| 133 | + key: maui-workloads-win-${{ hashFiles('**/KumikoUI.Maui.csproj') }} |
| 134 | + restore-keys: maui-workloads-win- |
| 135 | + |
| 136 | + - name: Install MAUI workloads |
| 137 | + if: steps.workload-cache.outputs.cache-hit != 'true' |
| 138 | + run: dotnet workload install maui --source https://api.nuget.org/v3/index.json |
| 139 | + |
| 140 | + - name: Restore |
| 141 | + run: dotnet restore src/KumikoUI.Maui/KumikoUI.Maui.csproj |
| 142 | + |
| 143 | + - name: Pack — KumikoUI.Maui |
| 144 | + run: | |
| 145 | + dotnet pack src/KumikoUI.Maui/KumikoUI.Maui.csproj ` |
| 146 | + --no-restore ` |
| 147 | + -c Release ` |
| 148 | + -p:Version=${{ env.VERSION }} ` |
| 149 | + --include-symbols ` |
| 150 | + -p:SymbolPackageFormat=snupkg ` |
| 151 | + -o ./artifacts |
| 152 | +
|
| 153 | + - name: List artifacts |
| 154 | + run: Get-ChildItem artifacts -Recurse | Format-Table Name, Length |
| 155 | + |
| 156 | + - name: Upload Maui package |
| 157 | + uses: actions/upload-artifact@v4 |
| 158 | + with: |
| 159 | + name: nuget-maui |
| 160 | + path: artifacts/*.nupkg |
| 161 | + if-no-files-found: error |
| 162 | + |
| 163 | + - name: Upload Maui symbol package |
| 164 | + uses: actions/upload-artifact@v4 |
| 165 | + with: |
| 166 | + name: snupkg-maui |
| 167 | + path: artifacts/*.snupkg |
| 168 | + if-no-files-found: warn |
| 169 | + |
| 170 | + # ───────────────────────────────────────────────────────────────────────────── |
| 171 | + # 4. Run tests before publishing (gate publish on green tests) |
| 172 | + # ───────────────────────────────────────────────────────────────────────────── |
| 173 | + test: |
| 174 | + name: Run tests |
| 175 | + runs-on: ubuntu-latest |
| 176 | + needs: resolve-version |
| 177 | + |
| 178 | + steps: |
| 179 | + - uses: actions/checkout@v4 |
| 180 | + |
| 181 | + - name: Setup .NET 9 |
| 182 | + uses: actions/setup-dotnet@v4 |
| 183 | + with: |
| 184 | + dotnet-version: '9.x' |
| 185 | + |
| 186 | + - name: Restore & Test |
| 187 | + run: | |
| 188 | + dotnet restore tests/KumikoUI.Core.Tests/KumikoUI.Core.Tests.csproj |
| 189 | + dotnet test tests/KumikoUI.Core.Tests/KumikoUI.Core.Tests.csproj \ |
| 190 | + -c Release --logger "github-actions" |
| 191 | +
|
| 192 | + # ───────────────────────────────────────────────────────────────────────────── |
| 193 | + # 5. Publish all packages to NuGet.org and create a GitHub Release |
| 194 | + # ───────────────────────────────────────────────────────────────────────────── |
| 195 | + publish: |
| 196 | + name: Publish to NuGet.org |
| 197 | + runs-on: ubuntu-latest |
| 198 | + needs: [ pack-core, pack-maui, test ] |
| 199 | + environment: nuget-publish # optional: require manual approval in repo settings |
| 200 | + |
| 201 | + steps: |
| 202 | + - uses: actions/checkout@v4 |
| 203 | + |
| 204 | + - name: Setup .NET 9 |
| 205 | + uses: actions/setup-dotnet@v4 |
| 206 | + with: |
| 207 | + dotnet-version: '9.x' |
| 208 | + |
| 209 | + - name: Download all package artifacts |
| 210 | + uses: actions/download-artifact@v4 |
| 211 | + with: |
| 212 | + pattern: nuget-* |
| 213 | + path: ./publish |
| 214 | + merge-multiple: true |
| 215 | + |
| 216 | + - name: Download all symbol artifacts |
| 217 | + uses: actions/download-artifact@v4 |
| 218 | + with: |
| 219 | + pattern: snupkg-* |
| 220 | + path: ./publish |
| 221 | + merge-multiple: true |
| 222 | + |
| 223 | + - name: List packages to publish |
| 224 | + run: ls -lh publish/ |
| 225 | + |
| 226 | + - name: Push .nupkg packages to NuGet.org |
| 227 | + run: | |
| 228 | + for f in publish/*.nupkg; do |
| 229 | + echo "Pushing $f …" |
| 230 | + dotnet nuget push "$f" \ |
| 231 | + --api-key ${{ secrets.NUGET_API_KEY }} \ |
| 232 | + --source https://api.nuget.org/v3/index.json \ |
| 233 | + --skip-duplicate |
| 234 | + done |
| 235 | +
|
| 236 | + - name: Push .snupkg symbol packages to NuGet.org |
| 237 | + run: | |
| 238 | + for f in publish/*.snupkg; do |
| 239 | + [ -f "$f" ] || continue |
| 240 | + echo "Pushing symbol package $f …" |
| 241 | + dotnet nuget push "$f" \ |
| 242 | + --api-key ${{ secrets.NUGET_API_KEY }} \ |
| 243 | + --source https://api.nuget.org/v3/index.json \ |
| 244 | + --skip-duplicate |
| 245 | + done |
| 246 | +
|
| 247 | + # ── GitHub Release ───────────────────────────────────────────────────── |
| 248 | + - name: Create GitHub Release |
| 249 | + uses: softprops/action-gh-release@v2 |
| 250 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 251 | + with: |
| 252 | + tag_name: ${{ github.ref_name }} |
| 253 | + name: ${{ github.ref_name }} |
| 254 | + draft: false |
| 255 | + prerelease: ${{ contains(github.ref_name, '-') }} |
| 256 | + generate_release_notes: true |
| 257 | + files: publish/*.nupkg |
0 commit comments