|
| 1 | +name: Nightly Build |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # 6:00 AM UTC (1:00 AM EST / 2:00 AM EDT) |
| 6 | + - cron: '0 6 * * *' |
| 7 | + workflow_dispatch: # manual trigger |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + check: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + has_changes: ${{ steps.check.outputs.has_changes }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + ref: dev |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Check for new commits in last 24 hours |
| 24 | + id: check |
| 25 | + run: | |
| 26 | + RECENT=$(git log --since="24 hours ago" --oneline | head -1) |
| 27 | + if [ -n "$RECENT" ]; then |
| 28 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 29 | + echo "New commits found — building nightly" |
| 30 | + else |
| 31 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 32 | + echo "No new commits — skipping nightly build" |
| 33 | + fi |
| 34 | +
|
| 35 | + build: |
| 36 | + needs: check |
| 37 | + if: needs.check.outputs.has_changes == 'true' || github.event_name == 'workflow_dispatch' |
| 38 | + runs-on: windows-latest |
| 39 | + |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + ref: dev |
| 44 | + |
| 45 | + - name: Setup .NET 8.0 |
| 46 | + uses: actions/setup-dotnet@v4 |
| 47 | + with: |
| 48 | + dotnet-version: 8.0.x |
| 49 | + |
| 50 | + - name: Set nightly version |
| 51 | + id: version |
| 52 | + shell: pwsh |
| 53 | + run: | |
| 54 | + $base = ([xml](Get-Content src/PlanViewer.App/PlanViewer.App.csproj)).Project.PropertyGroup.Version | Where-Object { $_ } |
| 55 | + $date = Get-Date -Format "yyyyMMdd" |
| 56 | + $nightly = "$base-nightly.$date" |
| 57 | + echo "VERSION=$nightly" >> $env:GITHUB_OUTPUT |
| 58 | + echo "Nightly version: $nightly" |
| 59 | +
|
| 60 | + - name: Restore dependencies |
| 61 | + run: | |
| 62 | + dotnet restore src/PlanViewer.Core/PlanViewer.Core.csproj |
| 63 | + dotnet restore src/PlanViewer.App/PlanViewer.App.csproj |
| 64 | + dotnet restore src/PlanViewer.Cli/PlanViewer.Cli.csproj |
| 65 | + dotnet restore tests/PlanViewer.Core.Tests/PlanViewer.Core.Tests.csproj |
| 66 | +
|
| 67 | + - name: Run tests |
| 68 | + run: dotnet test tests/PlanViewer.Core.Tests/PlanViewer.Core.Tests.csproj -c Release --verbosity normal |
| 69 | + |
| 70 | + - name: Publish App (all platforms) |
| 71 | + run: | |
| 72 | + dotnet publish src/PlanViewer.App/PlanViewer.App.csproj -c Release -r win-x64 --self-contained -o publish/win-x64 |
| 73 | + dotnet publish src/PlanViewer.App/PlanViewer.App.csproj -c Release -r linux-x64 --self-contained -o publish/linux-x64 |
| 74 | + dotnet publish src/PlanViewer.App/PlanViewer.App.csproj -c Release -r osx-x64 --self-contained -o publish/osx-x64 |
| 75 | + dotnet publish src/PlanViewer.App/PlanViewer.App.csproj -c Release -r osx-arm64 --self-contained -o publish/osx-arm64 |
| 76 | +
|
| 77 | + - name: Package artifacts |
| 78 | + shell: pwsh |
| 79 | + env: |
| 80 | + VERSION: ${{ steps.version.outputs.VERSION }} |
| 81 | + run: | |
| 82 | + New-Item -ItemType Directory -Force -Path releases |
| 83 | +
|
| 84 | + # Package Windows and Linux as flat zips |
| 85 | + foreach ($rid in @('win-x64', 'linux-x64')) { |
| 86 | + if (Test-Path 'README.md') { Copy-Item 'README.md' "publish/$rid/" } |
| 87 | + if (Test-Path 'LICENSE') { Copy-Item 'LICENSE' "publish/$rid/" } |
| 88 | + Compress-Archive -Path "publish/$rid/*" -DestinationPath "releases/PerformanceStudio-$rid-$env:VERSION.zip" -Force |
| 89 | + } |
| 90 | +
|
| 91 | + # Package macOS as proper .app bundles |
| 92 | + foreach ($rid in @('osx-x64', 'osx-arm64')) { |
| 93 | + $appName = "PerformanceStudio.app" |
| 94 | + $bundleDir = "publish/$rid-bundle/$appName" |
| 95 | +
|
| 96 | + New-Item -ItemType Directory -Force -Path "$bundleDir/Contents/MacOS" |
| 97 | + New-Item -ItemType Directory -Force -Path "$bundleDir/Contents/Resources" |
| 98 | +
|
| 99 | + Copy-Item -Path "publish/$rid/*" -Destination "$bundleDir/Contents/MacOS/" -Recurse |
| 100 | +
|
| 101 | + if (Test-Path "$bundleDir/Contents/MacOS/Info.plist") { |
| 102 | + Move-Item -Path "$bundleDir/Contents/MacOS/Info.plist" -Destination "$bundleDir/Contents/Info.plist" -Force |
| 103 | + } |
| 104 | +
|
| 105 | + $plist = Get-Content "$bundleDir/Contents/Info.plist" -Raw |
| 106 | + $plist = $plist -replace '(<key>CFBundleVersion</key>\s*<string>)[^<]*(</string>)', "`${1}$env:VERSION`${2}" |
| 107 | + $plist = $plist -replace '(<key>CFBundleShortVersionString</key>\s*<string>)[^<]*(</string>)', "`${1}$env:VERSION`${2}" |
| 108 | + Set-Content -Path "$bundleDir/Contents/Info.plist" -Value $plist -NoNewline |
| 109 | +
|
| 110 | + if (Test-Path "$bundleDir/Contents/MacOS/EDD.icns") { |
| 111 | + Move-Item -Path "$bundleDir/Contents/MacOS/EDD.icns" -Destination "$bundleDir/Contents/Resources/EDD.icns" -Force |
| 112 | + } |
| 113 | +
|
| 114 | + $wrapperDir = "publish/$rid-bundle" |
| 115 | + if (Test-Path 'README.md') { Copy-Item 'README.md' "$wrapperDir/" } |
| 116 | + if (Test-Path 'LICENSE') { Copy-Item 'LICENSE' "$wrapperDir/" } |
| 117 | +
|
| 118 | + Compress-Archive -Path "$wrapperDir/*" -DestinationPath "releases/PerformanceStudio-$rid-$env:VERSION.zip" -Force |
| 119 | + } |
| 120 | +
|
| 121 | + - name: Generate checksums |
| 122 | + shell: pwsh |
| 123 | + run: | |
| 124 | + $checksums = Get-ChildItem releases/*.zip | ForEach-Object { |
| 125 | + $hash = (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLower() |
| 126 | + "$hash $($_.Name)" |
| 127 | + } |
| 128 | + $checksums | Out-File -FilePath releases/SHA256SUMS.txt -Encoding utf8 |
| 129 | + Write-Host "Checksums:" |
| 130 | + $checksums | ForEach-Object { Write-Host $_ } |
| 131 | +
|
| 132 | + - name: Delete previous nightly release |
| 133 | + env: |
| 134 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + run: gh release delete nightly --yes --cleanup-tag 2>$null; exit 0 |
| 136 | + shell: pwsh |
| 137 | + |
| 138 | + - name: Create nightly release |
| 139 | + env: |
| 140 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 141 | + shell: pwsh |
| 142 | + run: | |
| 143 | + $version = "${{ steps.version.outputs.VERSION }}" |
| 144 | + $sha = git rev-parse --short HEAD |
| 145 | + $body = @" |
| 146 | + Automated nightly build from ``dev`` branch. |
| 147 | +
|
| 148 | + **Version:** ``$version`` |
| 149 | + **Commit:** ``$sha`` |
| 150 | + **Built:** $(Get-Date -Format "yyyy-MM-dd HH:mm UTC") |
| 151 | +
|
| 152 | + > These builds include the latest changes and may be unstable. |
| 153 | + > For production use, download the [latest stable release](https://github.com/erikdarlingdata/PerformanceStudio/releases/latest). |
| 154 | + "@ |
| 155 | +
|
| 156 | + gh release create nightly ` |
| 157 | + --target dev ` |
| 158 | + --title "Nightly Build ($version)" ` |
| 159 | + --notes $body ` |
| 160 | + --prerelease ` |
| 161 | + releases/*.zip releases/SHA256SUMS.txt |
0 commit comments