Weekly Release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Weekly Release | |
| on: | |
| schedule: | |
| # Every Sunday at 03:00 UTC | |
| - cron: "0 3 * * 0" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Check if release is needed | |
| id: gate | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| let latestTag = ""; | |
| try { | |
| const latest = await github.rest.repos.getLatestRelease({ owner, repo }); | |
| latestTag = latest.data.tag_name; | |
| core.info(`Latest release tag: ${latestTag}`); | |
| core.setOutput("latest_tag", latestTag); | |
| } catch (error) { | |
| if (error.status === 404) { | |
| core.info("No previous release found. A release will be created."); | |
| core.setOutput("latest_tag", ""); | |
| core.setOutput("should_release", "true"); | |
| return; | |
| } | |
| throw error; | |
| } | |
| const compare = await github.rest.repos.compareCommitsWithBasehead({ | |
| owner, | |
| repo, | |
| basehead: `${latestTag}...${context.sha}`, | |
| }); | |
| const aheadBy = compare.data.ahead_by || 0; | |
| core.info(`Commits since ${latestTag}: ${aheadBy}`); | |
| core.setOutput("should_release", aheadBy > 0 ? "true" : "false"); | |
| - name: Skip (no new commits) | |
| if: steps.gate.outputs.should_release != 'true' | |
| shell: pwsh | |
| run: | | |
| Write-Host "No commits since latest release tag '$env:LATEST_TAG'. Skipping build." | |
| env: | |
| LATEST_TAG: ${{ steps.gate.outputs.latest_tag }} | |
| - name: Compute release metadata | |
| if: steps.gate.outputs.should_release == 'true' | |
| id: meta | |
| shell: pwsh | |
| run: | | |
| $date = Get-Date -Format 'yyyyMMdd' | |
| $sha = $env:GITHUB_SHA.Substring(0, 7) | |
| $tag = "weekly-$date-$sha" | |
| $name = "Weekly build $date ($sha)" | |
| "tag=$tag" >> $env:GITHUB_OUTPUT | |
| "name=$name" >> $env:GITHUB_OUTPUT | |
| - name: Build binaries | |
| if: steps.gate.outputs.should_release == 'true' | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = "Stop" | |
| $csc = "$env:windir\Microsoft.NET\Framework64\v4.0.30319\csc.exe" | |
| if (-not (Test-Path $csc)) { | |
| throw "csc.exe not found at: $csc" | |
| } | |
| & $csc /target:exe /out:GpdControl.exe GpdControl.cs | |
| & $csc /target:winexe /out:GpdGui.exe /main:GpdGui.Program GpdGui.cs GpdControl.cs | |
| - name: Package release assets | |
| if: steps.gate.outputs.should_release == 'true' | |
| id: package | |
| shell: pwsh | |
| run: | | |
| $artifact = "gpd-win-controls-access-${{ steps.meta.outputs.tag }}.zip" | |
| Add-Type -AssemblyName System.IO.Compression.FileSystem | |
| if (Test-Path $artifact) { | |
| Remove-Item -Path $artifact -Force | |
| } | |
| $archive = [System.IO.Compression.ZipFile]::Open($artifact, [System.IO.Compression.ZipArchiveMode]::Create) | |
| try { | |
| [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, "GpdControl.exe", "GpdControl.exe") | Out-Null | |
| [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, "GpdGui.exe", "GpdGui.exe") | Out-Null | |
| [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, "default_mappings.txt", "default_mappings.txt") | Out-Null | |
| $archive.CreateEntry("profiles/") | Out-Null | |
| } finally { | |
| $archive.Dispose() | |
| } | |
| "artifact=$artifact" >> $env:GITHUB_OUTPUT | |
| - name: Create GitHub release | |
| if: steps.gate.outputs.should_release == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.meta.outputs.tag }} | |
| name: ${{ steps.meta.outputs.name }} | |
| generate_release_notes: true | |
| files: ${{ steps.package.outputs.artifact }} | |
| make_latest: true |