Auto-update Publii in WinGet #154
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: Auto-update Publii in WinGet | |
| on: | |
| schedule: | |
| - cron: "17 5 * * *" # daily at 05:17 UTC | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout Publii repo | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: GetPublii/Publii | |
| fetch-depth: 1 | |
| - name: Get latest stable tag | |
| id: get_tag | |
| shell: pwsh | |
| run: | | |
| git fetch --tags | |
| $items = git tag --list | ForEach-Object { | |
| if ($_ -match '(\d+\.\d+\.\d+)') { | |
| [PSCustomObject]@{ Tag = $_; Base = [version]$Matches[1] } | |
| } | |
| } | |
| $latest = ($items | Sort-Object Base -Descending | Select-Object -First 1).Base.ToString() | |
| "tag=$latest" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| Write-Host "Latest Publii tag: $latest" | |
| - name: Check if version already exists in winget-pkgs | |
| id: check_version | |
| shell: pwsh | |
| run: | | |
| $packageId = "TidyCustoms.Publii" | |
| $tag = "${{ steps.get_tag.outputs.tag }}" | |
| $url = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TidyCustoms/Publii" | |
| $resp = Invoke-RestMethod -Uri $url -Headers @{ 'Accept' = 'application/vnd.github.v3+json' } | |
| $versions = $resp | Where-Object { $_.type -eq 'dir' } | Select-Object -ExpandProperty name | |
| Write-Host "Versions currently in winget-pkgs for ${packageId}:" | |
| $versions | Sort-Object -Descending | ForEach-Object { Write-Host " - $_" } | |
| if ($versions -contains $tag) { | |
| Write-Host "Version $tag already exists in winget-pkgs. Skipping update." | |
| "skip=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| } else { | |
| Write-Host "Version $tag not found in winget-pkgs. Will update." | |
| "skip=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| } | |
| - name: Download wingetcreate | |
| if: steps.check_version.outputs.skip == 'false' | |
| shell: pwsh | |
| run: | | |
| Invoke-WebRequest -Uri https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe | |
| - name: Update WinGet package | |
| if: steps.check_version.outputs.skip == 'false' | |
| shell: pwsh | |
| env: | |
| TAG: ${{ steps.get_tag.outputs.tag }} | |
| # Use a classic PAT because fine-grained tokens are not supported by wingetcreate | |
| WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }} | |
| run: | | |
| .\wingetcreate.exe update TidyCustoms.Publii ` | |
| -u "https://getpublii.com/download/Publii-$env:TAG.exe|x64|user" ` | |
| -v "$env:TAG" ` | |
| --submit |