Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .github/workflows/build-and-package-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,31 @@ jobs:
build-package-windows:
name: Build and package windows
runs-on: windows-latest
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Detect NowPlaying-related changes
id: nowplaying_changes
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
changed_files="$(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}")"

if printf '%s\n' "$changed_files" | grep -Eq '^(\.github/workflows/build-and-package-application\.yml|data/module/media/media_windows\.go|\.scripts/windows/(create-installer\.ps1|download-now-playing\.ps1|installer\.nsi\.template))$'; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Download NowPlaying helper
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
if: ${{ env.GH_TOKEN != '' }}
GH_TOKEN: ${{ github.token }}
ALLOW_RATE_LIMIT_SKIP: ${{ github.event_name == 'pull_request' && steps.nowplaying_changes.outputs.changed != 'true' && 'true' || 'false' }}
if: ${{ github.token != '' }}
run: ./.scripts/windows/download-now-playing.ps1

- name: Setup Go
Expand Down
21 changes: 20 additions & 1 deletion .scripts/windows/download-now-playing.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$ErrorActionPreference = 'Stop'

$ghToken = $env:GH_TOKEN
$allowRateLimitSkip = $env:ALLOW_RATE_LIMIT_SKIP -eq 'true'
if (-not $ghToken -and $env:GITHUB_TOKEN) {
$env:GH_TOKEN = $env:GITHUB_TOKEN
$ghToken = $env:GH_TOKEN
Expand All @@ -16,12 +17,30 @@ try {
Write-Error 'Error calling gh auth status. Please check if the GH_TOKEN is set correctly.'
}

function Test-RateLimitError {
param(
[string]$Message
)

return $Message -match 'rate limit|secondary rate limit|api rate limit exceeded|http 429|too many requests'
}

$outDir = Join-Path (Get-Location) '.scripts/windows/now-playing'

$temp = Join-Path $env:TEMP ("npdl_" + [guid]::NewGuid())
New-Item -ItemType Directory -Path $temp -Force | Out-Null
try {
gh release download -R timmo001/dotnet-now-playing -p '*.zip' -D $temp --clobber | Out-Null
$downloadOutput = & gh release download -R timmo001/dotnet-now-playing -p '*.zip' -D $temp --clobber 2>&1
if ($LASTEXITCODE -ne 0) {
$message = ($downloadOutput | Out-String).Trim()
if ($allowRateLimitSkip -and (Test-RateLimitError -Message $message)) {
Write-Host '::warning title=NowPlaying download skipped::GitHub rate limit hit while downloading the NowPlaying helper. Continuing without it for this pull request.'
return
}

throw "Failed to download NowPlaying helper. $message"
}

$zip = Get-ChildItem -Path $temp -Filter *.zip | Select-Object -First 1
if (-not $zip) { throw 'No zip asset found' }

Expand Down
Loading