Skip to content

Update IntuneWinAppUtil Versions #13

Update IntuneWinAppUtil Versions

Update IntuneWinAppUtil Versions #13

name: Update IntuneWinAppUtil Versions
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
permissions:
contents: write
jobs:
update-if-new-release:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Get latest release tag from Microsoft repo
id: get_latest
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Build authenticated headers for GitHub REST API
$headers = @{
"User-Agent" = "PowerShell"
"Authorization" = "Bearer $env:GITHUB_TOKEN"
"Accept" = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
}
$uri = "https://api.github.com/repos/microsoft/Microsoft-Win32-Content-Prep-Tool/releases/latest"
$maxRetries = 5
$delay = 2
for ($i=1; $i -le $maxRetries; $i++) {
try {
$response = Invoke-RestMethod -Uri $uri -Headers $headers -Method GET -TimeoutSec 30
$tagName = $response.tag_name
if (-not $tagName) { throw "Empty tag_name in response." }
Add-Content -Path $env:GITHUB_OUTPUT -Value "latest_tag=$tagName"
break
} catch {
if ($i -eq $maxRetries) { throw }
# Exponential backoff on known transient/rate-limited responses
Start-Sleep -Seconds $delay
$delay = [Math]::Min($delay * 2, 30)
}
}
- name: Read last processed version if exists
id: read_version
shell: pwsh
run: |
if (Test-Path ./Tools/last_processed_version.txt) {
$version = Get-Content ./Tools/last_processed_version.txt -Raw
Write-Host "Last processed version: $version"
Add-Content -Path $env:GITHUB_OUTPUT -Value "last_version=$version"
} else {
Write-Host "No previous version file found."
Add-Content -Path $env:GITHUB_OUTPUT -Value "last_version="
}
- name: Check if update is needed
id: check_update
shell: pwsh
run: |
$latest = "${{ steps.get_latest.outputs.latest_tag }}"
$last = "${{ steps.read_version.outputs.last_version }}"
if ($latest -and $latest -ne $last) {
Write-Host "New version detected: $latest"
Add-Content -Path $env:GITHUB_OUTPUT -Value "do_update=true"
} else {
Write-Host "No new version detected, skipping update."
Add-Content -Path $env:GITHUB_OUTPUT -Value "do_update=false"
}
- name: Run PowerShell script and update files
if: steps.check_update.outputs.do_update == 'true'
shell: pwsh
run: |
.\Tools\Update-IntuneWinAppUtilVersions.ps1 -OutputDirectory .\Tools
# Save new version for next runs
"${{ steps.get_latest.outputs.latest_tag }}" | Out-File -FilePath Tools/last_processed_version.txt -Encoding utf8
- name: Commit and push if changes detected
if: steps.check_update.outputs.do_update == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Tools/IntuneWinAppUtilVersions.md Tools/last_processed_version.txt
git diff --cached --quiet || git commit -m "Update IntuneWinAppUtil version list to ${{ steps.get_latest.outputs.latest_tag }}"
git push
shell: bash