|
| 1 | +# New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE) |
| 2 | +# Modifications by Peter Wagner (aka Wagnerp), Simon Coghlan (aka Smurf-IV), tobitege et al. 2025 - 2025. All rights reserved. |
| 3 | + |
| 4 | +name: Nightly Release |
| 5 | + |
| 6 | +on: |
| 7 | + schedule: |
| 8 | + # Run nightly build automatically at midnight UTC every day |
| 9 | + - cron: '0 0 * * *' |
| 10 | + workflow_dispatch: # Allow manual triggering for testing |
| 11 | + |
| 12 | +jobs: |
| 13 | + nightly: |
| 14 | + runs-on: windows-2022 |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v5 |
| 19 | + with: |
| 20 | + ref: alpha |
| 21 | + |
| 22 | + # .NET 9 (GA) |
| 23 | + - name: Setup .NET 9 |
| 24 | + uses: actions/setup-dotnet@v4 |
| 25 | + with: |
| 26 | + dotnet-version: 9.0.x |
| 27 | + |
| 28 | + # .NET 10 (Preview) |
| 29 | + - name: Setup .NET 10 (preview) |
| 30 | + uses: actions/setup-dotnet@v4 |
| 31 | + with: |
| 32 | + dotnet-version: 10.0.x |
| 33 | + dotnet-quality: preview |
| 34 | + |
| 35 | + # global.json dynamically generate (use latest SDK available) |
| 36 | + - name: Force .NET 10 SDK via global.json |
| 37 | + run: | |
| 38 | + $sdkVersion = (dotnet --list-sdks | Select-String "10.0").ToString().Split(" ")[0] |
| 39 | + if (-not $sdkVersion) { |
| 40 | + # Fallback to .NET 8 if .NET 10 is not available |
| 41 | + $sdkVersion = (dotnet --list-sdks | Select-String "8.0").ToString().Split(" ")[0] |
| 42 | + } |
| 43 | + Write-Output "Using SDK $sdkVersion" |
| 44 | + @" |
| 45 | + { |
| 46 | + "sdk": { |
| 47 | + "version": "$sdkVersion", |
| 48 | + "rollForward": "latestFeature" |
| 49 | + } |
| 50 | + } |
| 51 | + "@ | Out-File -Encoding utf8 global.json |
| 52 | +
|
| 53 | + - name: Setup MSBuild |
| 54 | + uses: microsoft/setup-msbuild@v2 |
| 55 | + with: |
| 56 | + msbuild-architecture: x64 |
| 57 | + |
| 58 | + - name: Setup NuGet |
| 59 | + |
| 60 | + |
| 61 | + - name: Cache NuGet |
| 62 | + uses: actions/cache@v4 |
| 63 | + with: |
| 64 | + path: ~/.nuget/packages |
| 65 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-nuget- |
| 68 | +
|
| 69 | + - name: Restore |
| 70 | + run: dotnet restore "Source/Krypton Components/Krypton Toolkit Suite 2022 - VS2022.sln" |
| 71 | + |
| 72 | + - name: Build Nightly |
| 73 | + run: msbuild "Scripts/nightly.proj" /t:Build /p:Configuration=Nightly /p:Platform="Any CPU" |
| 74 | + |
| 75 | + - name: Pack Nightly |
| 76 | + run: msbuild "Scripts/nightly.proj" /t:Pack /p:Configuration=Nightly /p:Platform="Any CPU" |
| 77 | + |
| 78 | + - name: Push NuGet Packages to nuget.org |
| 79 | + id: push_nuget |
| 80 | + shell: pwsh |
| 81 | + run: | |
| 82 | + $ErrorActionPreference = 'Stop' |
| 83 | + if (-not $env:NUGET_API_KEY) { |
| 84 | + Write-Warning "NUGET_API_KEY not set - skipping NuGet push" |
| 85 | + echo "packages_published=false" >> $env:GITHUB_OUTPUT |
| 86 | + exit 0 |
| 87 | + } |
| 88 | + |
| 89 | + $packages = Get-ChildItem "Bin/Packages/Nightly/*.nupkg" -ErrorAction SilentlyContinue |
| 90 | + $publishedAny = $false |
| 91 | + |
| 92 | + if ($packages) { |
| 93 | + foreach ($package in $packages) { |
| 94 | + Write-Output "Pushing package: $($package.Name)" |
| 95 | + try { |
| 96 | + $output = dotnet nuget push "$($package.FullName)" --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate 2>&1 | Out-String |
| 97 | + Write-Output $output |
| 98 | + # Check if package was actually pushed (not skipped) |
| 99 | + if ($output -notmatch "already exists" -and $output -notmatch "was not pushed") { |
| 100 | + $publishedAny = $true |
| 101 | + Write-Host "Package $($package.Name) was published" |
| 102 | + } else { |
| 103 | + Write-Host "Package $($package.Name) already exists - skipped" |
| 104 | + } |
| 105 | + } catch { |
| 106 | + Write-Warning "Failed to push $($package.Name): $_" |
| 107 | + } |
| 108 | + } |
| 109 | + } else { |
| 110 | + Write-Output "No NuGet packages found to push" |
| 111 | + } |
| 112 | + |
| 113 | + echo "packages_published=$publishedAny" >> $env:GITHUB_OUTPUT |
| 114 | + env: |
| 115 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 116 | + |
| 117 | + - name: Get Version |
| 118 | + id: get_version |
| 119 | + shell: pwsh |
| 120 | + run: | |
| 121 | + $ErrorActionPreference = 'Stop' |
| 122 | + $version = $null |
| 123 | + |
| 124 | + # Try to get version from the built assembly (most reliable) |
| 125 | + try { |
| 126 | + $dllPath = Get-ChildItem "Bin/Nightly/net48/Krypton.Toolkit.dll" -ErrorAction Stop |
| 127 | + $assemblyVersion = [System.Reflection.AssemblyName]::GetAssemblyName($dllPath.FullName).Version |
| 128 | + $version = $assemblyVersion.ToString() |
| 129 | + Write-Host "Got version from assembly: $version" |
| 130 | + } catch { |
| 131 | + Write-Host "Could not read version from assembly: $_" |
| 132 | + } |
| 133 | + |
| 134 | + # Fallback: Try to read from csproj XML |
| 135 | + if (-not $version) { |
| 136 | + try { |
| 137 | + $proj = 'Source/Krypton Components/Krypton.Toolkit/Krypton.Toolkit 2022.csproj' |
| 138 | + [xml]$projXml = Get-Content $proj |
| 139 | + $versionNode = $projXml.SelectSingleNode("//Version") |
| 140 | + if ($versionNode) { |
| 141 | + $version = $versionNode.InnerText.Trim() |
| 142 | + Write-Host "Got version from csproj: $version" |
| 143 | + } |
| 144 | + } catch { |
| 145 | + Write-Host "Could not read version from csproj: $_" |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + # Last resort fallback |
| 150 | + if (-not $version) { |
| 151 | + Write-Warning "Version not found, using fallback." |
| 152 | + $version = "100.25.1.1" |
| 153 | + } |
| 154 | + |
| 155 | + Write-Host "Final determined version: $version" |
| 156 | + echo "version=$version" >> $env:GITHUB_OUTPUT |
| 157 | + echo "tag=v$version-nightly" >> $env:GITHUB_OUTPUT |
| 158 | +
|
| 159 | + - name: Announce Nightly Release on Discord |
| 160 | + if: steps.push_nuget.outputs.packages_published == 'True' |
| 161 | + shell: pwsh |
| 162 | + run: | |
| 163 | + if (-not $env:DISCORD_WEBHOOK_NIGHTLY) { |
| 164 | + Write-Warning "DISCORD_WEBHOOK_NIGHTLY not set - skipping Discord notification" |
| 165 | + exit 0 |
| 166 | + } |
| 167 | + |
| 168 | + $payload = @{ |
| 169 | + embeds = @( |
| 170 | + @{ |
| 171 | + title = "🚀 Krypton Toolkit Nightly Release" |
| 172 | + description = "A new nightly build is now available for bleeding-edge testing!" |
| 173 | + color = 10181046 |
| 174 | + fields = @( |
| 175 | + @{ |
| 176 | + name = "📌 Version" |
| 177 | + value = "``${{ steps.get_version.outputs.version }}``" |
| 178 | + inline = $true |
| 179 | + } |
| 180 | + @{ |
| 181 | + name = "📦 NuGet Packages" |
| 182 | + value = "- Krypton.Toolkit`n- Krypton.Ribbon`n- Krypton.Navigator`n- Krypton.Workspace`n- Krypton.Docking" |
| 183 | + inline = $false |
| 184 | + } |
| 185 | + @{ |
| 186 | + name = "🎯 Target Frameworks" |
| 187 | + value = "• .NET Framework 4.7.2`n• .NET Framework 4.8`n• .NET Framework 4.8.1`n• .NET 8.0`n• .NET 9.0`n• .NET 10.0" |
| 188 | + inline = $false |
| 189 | + } |
| 190 | + @{ |
| 191 | + name = "🔗 NuGet Packages" |
| 192 | + value = "• [Toolkit](https://www.nuget.org/packages/Krypton.Toolkit)`n• [Ribbon](https://www.nuget.org/packages/Krypton.Ribbon)`n• [Navigator](https://www.nuget.org/packages/Krypton.Navigator)`n• [Workspace](https://www.nuget.org/packages/Krypton.Workspace)`n• [Docking](https://www.nuget.org/packages/Krypton.Docking)" |
| 193 | + inline = $false |
| 194 | + } |
| 195 | + ) |
| 196 | + footer = @{ |
| 197 | + text = "Released" |
| 198 | + } |
| 199 | + timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ") |
| 200 | + } |
| 201 | + ) |
| 202 | + } | ConvertTo-Json -Depth 10 |
| 203 | + |
| 204 | + Invoke-RestMethod -Uri $env:DISCORD_WEBHOOK_NIGHTLY -Method Post -Body $payload -ContentType "application/json" |
| 205 | + env: |
| 206 | + DISCORD_WEBHOOK_NIGHTLY: ${{ secrets.DISCORD_WEBHOOK_NIGHTLY }} |
| 207 | + |
0 commit comments