Skip to content

Commit

Permalink
add Logitech.OptionsPlus automation (dryrun)
Browse files Browse the repository at this point in the history
  • Loading branch information
Utesgui authored Apr 18, 2024
1 parent b089f9f commit 4197776
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/Logitech.OptionsPlus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Logitech.OptionsPlus PR
# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml
env:
PackageName: Logitech.OptionsPlus

on:
workflow_dispatch:
schedule:
- cron: 3 0/4 * * *

jobs:
winget:
name: Publish winget package
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: Utesgui
- name: Install winget
uses: Cyberboss/install-winget@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Install wingetcreate
# run: winget install wingetcreate --disable-interactivity --accept-source-agreements
- name: Submit package to Windows Package Manager Community Repository
working-directory: Utesgui
env:
GITHUB_TOKEN: ${{ secrets.WINGET_PAT }}
WINGET_PKGS_FORK_REPO: ${{ vars.WINGET_PKGS_FORK_REPO }}
run: .\Scripts\Update-${{ env.PackageName }}.ps1

67 changes: 67 additions & 0 deletions Scripts/Update-Logitech.OptionsPlus.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
if ($Env:GITHUB_TOKEN) {
Write-Host 'GITHUB_TOKEN detected'
$gitToken = ${Env:GITHUB_TOKEN}
}
else {
Write-Host 'GITHUB_TOKEN not detected'
exit 1
}

$wingetPackage = "Logitech.OptionsPlus"


# download latest version from loupedeck.com and get version by filename
$latestVersionUrl = "https://download01.logi.com/web/ftp/pub/techsupport/optionsplus/logioptionsplus_installer.exe"
#create directory downloads and change into it
$DownloadFileName = "logioptionsplus_installer.exe"
Invoke-WebRequest -Uri $latestVersionUrl -OutFile $DownloadFileName
$file = Get-ChildItem -Path $DownloadFileName
$versionInfo = $file.VersionInfo.ProductVersion

if ($null -eq $versionInfo) {
Write-Host "Could not find version info in file"
exit 1
}

Write-Host "Found latest version: $versionInfo"

$fullDownloadURL = $latestVersionUrl

$prMessage = "Update version: $wingetPackage version $latestVersion"

$foundMessage, $textVersion, $separator, $wingetVersions = winget search --id $wingetPackage --source winget --versions

# Check for existing versions in winget
if ($wingetVersions -contains $latestVersion) {
Write-Output "Latest version of $wingetPackage $latestVersion is already present in winget."
exit 0
}
else {
# Check for existing PRs
$ExistingPRs = gh pr list --search "$($wingetPackage) version $($latestVersion) in:title draft:false" --state 'all' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json

# TODO Check if PR is already merged, if so exit

# TODO if PR from us is already open, update PR with new version

# TODO if PR is closed, not from us and no PR got merged, create new PR

# TODO if PR is closed, from us and no PR got merged, throw error

if ($ExistingPRs.Count -gt 0) {
Write-Output "$foundMessage"
$ExistingPRs | ForEach-Object {
Write-Output "Found existing PR: $($_.title)"
Write-Output "-> $($_.url)"
}
}
elseif ($wingetVersions -and ($wingetVersions -notmatch $latestVersion)) {
Write-Output "Downloading wingetcreate and open PR for $wingetPackage Version $latestVersion"
# Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
# .\wingetcreate.exe update $wingetPackage -s -v $latestVersion -u "$latestVersionUrl" --prtitle $prMessage -t $gitToken
}
else {
Write-Output "$foundMessage"
Write-Output "No existing PRs found. Check why wingetcreate has not run."
}
}

0 comments on commit 4197776

Please sign in to comment.