|
| 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 Dashboard/Dashboard.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 Dashboard/Dashboard.csproj |
| 63 | + dotnet restore Lite/PerformanceMonitorLite.csproj |
| 64 | + dotnet restore Installer/PerformanceMonitorInstaller.csproj |
| 65 | + dotnet restore InstallerGui/InstallerGui.csproj |
| 66 | + dotnet restore Lite.Tests/Lite.Tests.csproj |
| 67 | +
|
| 68 | + - name: Run tests |
| 69 | + run: dotnet test Lite.Tests/Lite.Tests.csproj -c Release --verbosity normal |
| 70 | + |
| 71 | + - name: Publish Dashboard |
| 72 | + run: dotnet publish Dashboard/Dashboard.csproj -c Release -o publish/Dashboard |
| 73 | + |
| 74 | + - name: Publish Lite |
| 75 | + run: dotnet publish Lite/PerformanceMonitorLite.csproj -c Release -o publish/Lite |
| 76 | + |
| 77 | + - name: Publish CLI Installer |
| 78 | + run: dotnet publish Installer/PerformanceMonitorInstaller.csproj -c Release |
| 79 | + |
| 80 | + - name: Publish GUI Installer |
| 81 | + run: dotnet publish InstallerGui/InstallerGui.csproj -c Release |
| 82 | + |
| 83 | + - name: Package artifacts |
| 84 | + shell: pwsh |
| 85 | + run: | |
| 86 | + $version = "${{ steps.version.outputs.VERSION }}" |
| 87 | + New-Item -ItemType Directory -Force -Path releases |
| 88 | +
|
| 89 | + Compress-Archive -Path 'publish/Dashboard/*' -DestinationPath "releases/PerformanceMonitorDashboard-$version.zip" -Force |
| 90 | + Compress-Archive -Path 'publish/Lite/*' -DestinationPath "releases/PerformanceMonitorLite-$version.zip" -Force |
| 91 | +
|
| 92 | + $instDir = 'publish/Installer' |
| 93 | + New-Item -ItemType Directory -Force -Path $instDir |
| 94 | + New-Item -ItemType Directory -Force -Path "$instDir/install" |
| 95 | + New-Item -ItemType Directory -Force -Path "$instDir/upgrades" |
| 96 | +
|
| 97 | + Copy-Item 'Installer/bin/Release/net8.0/win-x64/publish/PerformanceMonitorInstaller.exe' $instDir |
| 98 | + Copy-Item 'InstallerGui/bin/Release/net8.0-windows/win-x64/publish/PerformanceMonitorInstallerGui.exe' $instDir -ErrorAction SilentlyContinue |
| 99 | + Copy-Item 'install/*.sql' "$instDir/install/" |
| 100 | + if (Test-Path 'install/templates') { Copy-Item 'install/templates' "$instDir/install/templates" -Recurse -ErrorAction SilentlyContinue } |
| 101 | + if (Test-Path 'upgrades') { Copy-Item 'upgrades/*' "$instDir/upgrades/" -Recurse -ErrorAction SilentlyContinue } |
| 102 | + if (Test-Path 'README.md') { Copy-Item 'README.md' $instDir } |
| 103 | + if (Test-Path 'LICENSE') { Copy-Item 'LICENSE' $instDir } |
| 104 | + if (Test-Path 'THIRD_PARTY_NOTICES.md') { Copy-Item 'THIRD_PARTY_NOTICES.md' $instDir } |
| 105 | +
|
| 106 | + Compress-Archive -Path 'publish/Installer/*' -DestinationPath "releases/PerformanceMonitorInstaller-$version.zip" -Force |
| 107 | +
|
| 108 | + - name: Generate checksums |
| 109 | + shell: pwsh |
| 110 | + run: | |
| 111 | + $checksums = Get-ChildItem releases/*.zip | ForEach-Object { |
| 112 | + $hash = (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLower() |
| 113 | + "$hash $($_.Name)" |
| 114 | + } |
| 115 | + $checksums | Out-File -FilePath releases/SHA256SUMS.txt -Encoding utf8 |
| 116 | + Write-Host "Checksums:" |
| 117 | + $checksums | ForEach-Object { Write-Host $_ } |
| 118 | +
|
| 119 | + - name: Delete previous nightly release |
| 120 | + env: |
| 121 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 122 | + run: gh release delete nightly --yes --cleanup-tag 2>$null; exit 0 |
| 123 | + shell: pwsh |
| 124 | + |
| 125 | + - name: Create nightly release |
| 126 | + env: |
| 127 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + shell: pwsh |
| 129 | + run: | |
| 130 | + $version = "${{ steps.version.outputs.VERSION }}" |
| 131 | + $sha = git rev-parse --short HEAD |
| 132 | + $body = @" |
| 133 | + Automated nightly build from ``dev`` branch. |
| 134 | +
|
| 135 | + **Version:** ``$version`` |
| 136 | + **Commit:** ``$sha`` |
| 137 | + **Built:** $(Get-Date -Format "yyyy-MM-dd HH:mm UTC") |
| 138 | +
|
| 139 | + > These builds include the latest changes and may be unstable. |
| 140 | + > For production use, download the [latest stable release](https://github.com/erikdarlingdata/PerformanceMonitor/releases/latest). |
| 141 | + "@ |
| 142 | +
|
| 143 | + gh release create nightly ` |
| 144 | + --target dev ` |
| 145 | + --title "Nightly Build ($version)" ` |
| 146 | + --notes $body ` |
| 147 | + --prerelease ` |
| 148 | + releases/*.zip releases/SHA256SUMS.txt |
0 commit comments