|
| 1 | +name: Publish to WinGet |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + publish-winget: |
| 8 | + runs-on: windows-latest |
| 9 | + if: github.event.pull_request.merged == true |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Setup Node.js |
| 16 | + uses: actions/setup-node@v4 |
| 17 | + with: |
| 18 | + node-version: '18.14.0' |
| 19 | + |
| 20 | + - name: Install wingetcreate |
| 21 | + run: winget install --id Microsoft.WingetCreate --source winget --accept-package-agreements --accept-source-agreements |
| 22 | + |
| 23 | + - name: Read version from winget manifest |
| 24 | + id: manifest_version |
| 25 | + shell: pwsh |
| 26 | + run: | |
| 27 | + $content = Get-Content "build/winget/manifest.yaml" |
| 28 | + $line = $content | Where-Object { $_ -match '^PackageVersion:\s*(.+)$' } |
| 29 | + if (-not $line) { throw "PackageVersion not found in manifest" } |
| 30 | + $version = $line -replace '^PackageVersion:\s*', '' |
| 31 | + $version = $version.Trim() |
| 32 | + "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 33 | +
|
| 34 | + - name: Compute SHA256 for the latest release |
| 35 | + id: hash |
| 36 | + shell: pwsh |
| 37 | + run: | |
| 38 | + $version = "${{ steps.manifest_version.outputs.version }}" |
| 39 | + $url = "https://github.com/${{ github.repository }}/releases/download/v$version/Owlet-$version-win-x64.exe" |
| 40 | + Write-Host "Downloading: $url" |
| 41 | + Invoke-WebRequest -Uri $url -OutFile installer.exe |
| 42 | + $hash = (Get-FileHash -Path installer.exe -Algorithm SHA256).Hash |
| 43 | + "sha256=$hash" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 44 | + "url=$url" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 45 | +
|
| 46 | + - name: Update winget manifest |
| 47 | + shell: pwsh |
| 48 | + run: | |
| 49 | + $version = "${{ steps.manifest_version.outputs.version }}" |
| 50 | + $hash = "${{ steps.hash.outputs.sha256 }}" |
| 51 | + $url = "${{ steps.hash.outputs.url }}" |
| 52 | + wingetcreate.exe update ` |
| 53 | + --manifest "build/winget/manifest.yaml" ` |
| 54 | + --url "$url" ` |
| 55 | + --sha256 "$hash" |
| 56 | +
|
| 57 | + - name: Validate manifest |
| 58 | + shell: pwsh |
| 59 | + run: | |
| 60 | + wingetcreate.exe validate --path "build/winget/manifest.yaml" |
| 61 | +
|
| 62 | + - name: Submit manifest |
| 63 | + if: ${{ secrets.WINGET_TOKEN != '' }} |
| 64 | + shell: pwsh |
| 65 | + run: | |
| 66 | + wingetcreate.exe submit ` |
| 67 | + --path "build/winget/manifest.yaml" ` |
| 68 | + --token "${{ secrets.WINGET_TOKEN }}" ` |
| 69 | + --silent |
0 commit comments