|
| 1 | +name: Publish |
| 2 | + |
| 3 | +"on": |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'Package version (e.g. 1.2.3 or 1.2.3-preview.1)' |
| 11 | + required: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + # ── Job 1: Pack Core & SkiaSharp ──────────────────────────────────────────── |
| 15 | + pack-core: |
| 16 | + name: Pack Core & SkiaSharp |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 # required for SourceLink |
| 24 | + |
| 25 | + - name: Resolve version |
| 26 | + id: version |
| 27 | + run: | |
| 28 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 29 | + echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT" |
| 30 | + else |
| 31 | + echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" |
| 32 | + fi |
| 33 | +
|
| 34 | + - name: Setup .NET 10 |
| 35 | + uses: actions/setup-dotnet@v4 |
| 36 | + with: |
| 37 | + dotnet-version: '10.x' |
| 38 | + |
| 39 | + - name: Restore |
| 40 | + run: | |
| 41 | + dotnet restore src/MintedTextEditor.Core/ |
| 42 | + dotnet restore src/MintedTextEditor.SkiaSharp/ |
| 43 | +
|
| 44 | + - name: Build |
| 45 | + run: | |
| 46 | + dotnet build src/MintedTextEditor.Core/ --no-restore --configuration Release /p:Version=${{ steps.version.outputs.version }} |
| 47 | + dotnet build src/MintedTextEditor.SkiaSharp/ --no-restore --configuration Release /p:Version=${{ steps.version.outputs.version }} |
| 48 | +
|
| 49 | + - name: Pack Core |
| 50 | + run: > |
| 51 | + dotnet pack src/MintedTextEditor.Core/MintedTextEditor.Core.csproj |
| 52 | + --no-build |
| 53 | + --configuration Release |
| 54 | + /p:Version=${{ steps.version.outputs.version }} |
| 55 | + --include-symbols |
| 56 | + -p:SymbolPackageFormat=snupkg |
| 57 | + --output ./packages |
| 58 | +
|
| 59 | + - name: Pack SkiaSharp |
| 60 | + run: > |
| 61 | + dotnet pack src/MintedTextEditor.SkiaSharp/MintedTextEditor.SkiaSharp.csproj |
| 62 | + --no-build |
| 63 | + --configuration Release |
| 64 | + /p:Version=${{ steps.version.outputs.version }} |
| 65 | + --include-symbols |
| 66 | + -p:SymbolPackageFormat=snupkg |
| 67 | + --output ./packages |
| 68 | +
|
| 69 | + - name: Upload .nupkg artifacts |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + with: |
| 72 | + name: packages-core |
| 73 | + path: ./packages/*.nupkg |
| 74 | + |
| 75 | + - name: Upload .snupkg artifacts |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: symbol-packages-core |
| 79 | + path: ./packages/*.snupkg |
| 80 | + |
| 81 | + # ── Job 2: Pack MAUI ──────────────────────────────────────────────────────── |
| 82 | + pack-maui: |
| 83 | + name: Pack MAUI |
| 84 | + runs-on: windows-latest |
| 85 | + |
| 86 | + steps: |
| 87 | + - name: Checkout |
| 88 | + uses: actions/checkout@v4 |
| 89 | + with: |
| 90 | + fetch-depth: 0 |
| 91 | + |
| 92 | + - name: Resolve version |
| 93 | + id: version |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 97 | + echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT" |
| 98 | + else |
| 99 | + echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" |
| 100 | + fi |
| 101 | +
|
| 102 | + - name: Setup .NET 10 |
| 103 | + uses: actions/setup-dotnet@v4 |
| 104 | + with: |
| 105 | + dotnet-version: '10.x' |
| 106 | + |
| 107 | + - name: Cache MAUI workloads |
| 108 | + uses: actions/cache@v4 |
| 109 | + id: maui-cache |
| 110 | + with: |
| 111 | + path: | |
| 112 | + ~/.dotnet/workloads |
| 113 | + ~/.nuget/packages |
| 114 | + key: maui-workloads-${{ runner.os }}-${{ hashFiles('**/*.csproj') }} |
| 115 | + restore-keys: maui-workloads-${{ runner.os }}- |
| 116 | + |
| 117 | + - name: Install MAUI workloads |
| 118 | + if: steps.maui-cache.outputs.cache-hit != 'true' |
| 119 | + run: dotnet workload install maui --source https://api.nuget.org/v3/index.json |
| 120 | + |
| 121 | + - name: Restore |
| 122 | + run: dotnet restore src/MintedTextEditor.Maui/ |
| 123 | + |
| 124 | + - name: Build |
| 125 | + run: > |
| 126 | + dotnet build src/MintedTextEditor.Maui/ |
| 127 | + --no-restore |
| 128 | + --configuration Release |
| 129 | + /p:Version=${{ steps.version.outputs.version }} |
| 130 | +
|
| 131 | + - name: Pack MAUI |
| 132 | + run: > |
| 133 | + dotnet pack src/MintedTextEditor.Maui/MintedTextEditor.Maui.csproj |
| 134 | + --no-build |
| 135 | + --configuration Release |
| 136 | + /p:Version=${{ steps.version.outputs.version }} |
| 137 | + --include-symbols |
| 138 | + -p:SymbolPackageFormat=snupkg |
| 139 | + --output ./packages |
| 140 | +
|
| 141 | + - name: Upload .nupkg artifact |
| 142 | + uses: actions/upload-artifact@v4 |
| 143 | + with: |
| 144 | + name: packages-maui |
| 145 | + path: ./packages/*.nupkg |
| 146 | + |
| 147 | + - name: Upload .snupkg artifact |
| 148 | + uses: actions/upload-artifact@v4 |
| 149 | + with: |
| 150 | + name: symbol-packages-maui |
| 151 | + path: ./packages/*.snupkg |
| 152 | + |
| 153 | + # ── Job 3: Publish to NuGet.org ───────────────────────────────────────────── |
| 154 | + publish-nuget: |
| 155 | + name: Publish to NuGet.org |
| 156 | + needs: [pack-core, pack-maui] |
| 157 | + runs-on: ubuntu-latest |
| 158 | + |
| 159 | + steps: |
| 160 | + - name: Download Core packages |
| 161 | + uses: actions/download-artifact@v4 |
| 162 | + with: |
| 163 | + name: packages-core |
| 164 | + path: ./packages |
| 165 | + |
| 166 | + - name: Download MAUI packages |
| 167 | + uses: actions/download-artifact@v4 |
| 168 | + with: |
| 169 | + name: packages-maui |
| 170 | + path: ./packages |
| 171 | + |
| 172 | + - name: Setup .NET 10 |
| 173 | + uses: actions/setup-dotnet@v4 |
| 174 | + with: |
| 175 | + dotnet-version: '10.x' |
| 176 | + |
| 177 | + - name: Push to NuGet.org |
| 178 | + run: > |
| 179 | + dotnet nuget push "./packages/*.nupkg" |
| 180 | + --api-key ${{ secrets.NUGET_API_KEY }} |
| 181 | + --source https://api.nuget.org/v3/index.json |
| 182 | + --skip-duplicate |
| 183 | +
|
| 184 | + # ── Job 4: Create GitHub Release ──────────────────────────────────────────── |
| 185 | + create-release: |
| 186 | + name: Create GitHub Release |
| 187 | + needs: [pack-core, pack-maui] |
| 188 | + runs-on: ubuntu-latest |
| 189 | + permissions: |
| 190 | + contents: write |
| 191 | + |
| 192 | + steps: |
| 193 | + - name: Resolve version and tag |
| 194 | + id: version |
| 195 | + run: | |
| 196 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 197 | + VER="${{ github.event.inputs.version }}" |
| 198 | + echo "version=${VER}" >> "$GITHUB_OUTPUT" |
| 199 | + echo "tag=v${VER}" >> "$GITHUB_OUTPUT" |
| 200 | + else |
| 201 | + echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" |
| 202 | + echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" |
| 203 | + fi |
| 204 | +
|
| 205 | + - name: Download Core packages |
| 206 | + uses: actions/download-artifact@v4 |
| 207 | + with: |
| 208 | + name: packages-core |
| 209 | + path: ./packages |
| 210 | + |
| 211 | + - name: Download MAUI packages |
| 212 | + uses: actions/download-artifact@v4 |
| 213 | + with: |
| 214 | + name: packages-maui |
| 215 | + path: ./packages |
| 216 | + |
| 217 | + - name: Create release and attach packages |
| 218 | + uses: actions/github-script@v7 |
| 219 | + with: |
| 220 | + script: | |
| 221 | + const fs = require('fs'); |
| 222 | + const path = require('path'); |
| 223 | +
|
| 224 | + const version = '${{ steps.version.outputs.version }}'; |
| 225 | + const tag = '${{ steps.version.outputs.tag }}'; |
| 226 | + const isPreRelease = version.includes('-'); |
| 227 | +
|
| 228 | + const release = await github.rest.repos.createRelease({ |
| 229 | + owner: context.repo.owner, |
| 230 | + repo: context.repo.repo, |
| 231 | + tag_name: tag, |
| 232 | + name: `MintedTextEditor v${version}`, |
| 233 | + generate_release_notes: true, |
| 234 | + draft: false, |
| 235 | + prerelease: isPreRelease, |
| 236 | + }); |
| 237 | +
|
| 238 | + const packagesDir = './packages'; |
| 239 | + const nupkgs = fs.readdirSync(packagesDir).filter(f => f.endsWith('.nupkg')); |
| 240 | + for (const file of nupkgs) { |
| 241 | + const filePath = path.join(packagesDir, file); |
| 242 | + const data = fs.readFileSync(filePath); |
| 243 | + await github.rest.repos.uploadReleaseAsset({ |
| 244 | + owner: context.repo.owner, |
| 245 | + repo: context.repo.repo, |
| 246 | + release_id: release.data.id, |
| 247 | + name: file, |
| 248 | + data: data, |
| 249 | + headers: { 'content-type': 'application/zip' }, |
| 250 | + }); |
| 251 | + } |
0 commit comments