Skip to content

Implement wait loop for final file creation #20

Implement wait loop for final file creation

Implement wait loop for final file creation #20

Workflow file for this run

name: Build and Release Extension
on:
push:
tags:
- 'v*' # Matches v1.6.0, v2.0, etc.
permissions:
contents: write
jobs:
build-and-release:
runs-on: windows-latest # Required for .NET Framework
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Build with MSBuild
shell: pwsh
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" LocalLibrary.sln /p:Configuration=Release
- name: Set variables
id: vars
shell: pwsh
run: |
$tag = "${{ github.ref_name }}" # e.g., v1.6.0
$versiondots = $tag.TrimStart("v")
$version = $versiondots -replace '\.', '_'
echo "TAG=$tag" >> $env:GITHUB_ENV
echo "VERSION=$version" >> $env:GITHUB_ENV
echo "VERSIONDOTS=$versiondots" >> $env:GITHUB_ENV
echo "OUTFILE=LocalLibrary_2d01017d-024e-444d-80d3-f62f5be3fca5_$version.pext" >> $env:GITHUB_ENV
- name: Update extension.yaml version
shell: pwsh
run: |
(Get-Content extension.yaml) `
-replace '^(Version:\s*).+$', "Version: $env:VERSIONDOTS" `
| Set-Content extension.yaml
- name: Download latest Playnite release zip
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get latest release info
$release = gh api repos/JosefNemec/Playnite/releases/latest | ConvertFrom-Json
$pntag = $release.tag_name # e.g., "10.37"
# Remove periods to form the zip name
$versionNoDot = $pntag -replace '\.', ''
$zipFileName = "Playnite$versionNoDot.zip"
# Build download URL
$zipUrl = "https://github.com/JosefNemec/Playnite/releases/download/$pntag/$zipFileName"
$pnoutPath = "$env:TEMP\$zipFileName"
Write-Host "Downloading $zipUrl ..."
Invoke-WebRequest -Uri $zipUrl -OutFile $pnoutPath
# Persist
echo "PNOUTPATH=$pnoutPath" >> $env:GITHUB_ENV
- name: Extract Toolbox.exe
shell: pwsh
run: |
$extractPath = "$env:TEMP\Playnite"
$pnoutPath = "$env:PNOUTPATH"
Expand-Archive -Path "$pnoutPath" -DestinationPath $extractPath -Force
$toolboxPath = Join-Path $extractPath "Toolbox.exe"
# Persist
echo "TBPATH=$toolboxPath" >> $env:GITHUB_ENV
echo "EXPATH=$extractPath" >> $env:GITHUB_ENV
- name: Package with Toolbox
shell: pwsh
run: |
$toolboxPath = "$env:TBPATH"
$sourceDir = "$env:GITHUB_WORKSPACE\bin\Release\"
$destDir = "$env:GITHUB_WORKSPACE\package"
$finalFile = "$destDir\$env:OUTFILE"
# Persist
echo "FINALFILE=$finalFile" >> $env:GITHUB_ENV
# Ensure output directory exists
New-Item -ItemType Directory -Force -Path $destDir | Out-Null
# Pack the extension
& $toolboxPath pack "$sourceDir" "$destDir"
while (-not (Test-Path $finalFile)) {
Start-Sleep -Milliseconds 200
}
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
files: ${{ env.FINALFILE }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Append to LocalLibraryManifest.yaml
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required for gh CLI
run: |
$version = $env:VERSION
$versiondots = $env:VERSIONDOTS
$tag = $env:TAG
$releaseDate = (Get-Date -Format 'yyyy-MM-dd')
# Download release notes using GitHub CLI
$notes = gh api repos/${{ github.repository }}/releases/tags/$tag | ConvertFrom-Json
$changes = $notes.body -split "`n" | ForEach-Object { " - $_" }
# Compose manifest block
$block = @"
- Version: $versiondots
RequiredApiVersion: 6.11.0
ReleaseDate: $releaseDate
PackageUrl: https://github.com/azuravian/playnite-LocalLibrary/releases/download/$tag/LocalLibrary_2d01017d-024e-444d-80d3-f62f5be3fca5_$version.pext
Changelog:
$($changes -join "`n")
"@
# debug
Write-Host "Appended manifest block:"
Write-Host $block
# Append to manifest file
Add-Content "manifests/LocalLibraryManifest.yaml" $block
- name: Commit manifest update
shell: pwsh
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin main
git checkout main
git pull origin main
git add manifests/LocalLibraryManifest.yaml
git commit -m "Update manifest for $env:VERSIONDOTS"
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}