Skip to content

Instantly share code, notes, and snippets.

@KindDragon
Last active August 22, 2017 02:21
Show Gist options
  • Save KindDragon/0312346f8d2cc70d52d12e5c69188d73 to your computer and use it in GitHub Desktop.
Save KindDragon/0312346f8d2cc70d52d12e5c69188d73 to your computer and use it in GitHub Desktop.
# Place it in vcpkg\scripts folder
function Get-BasicAuthCreds {
param([PSCredential]$Credential)
$AuthString = "{0}:{1}" -f $Credential.Username,$Credential.GetNetworkCredential().Password
$AuthBytes = [System.Text.Encoding]::Ascii.GetBytes($AuthString)
return [Convert]::ToBase64String($AuthBytes)
}
$username = Read-host "GitHub username"
$password = Read-host "GitHub password" -AsSecureString
$cred = New-Object PSCredential $username, $password
$BasicCreds = Get-BasicAuthCreds -Credential $cred
$ports = Get-ChildItem ..\ports | ? {$_.PSIsContainer}
Foreach ($port in $ports)
{
$fileContent = Get-Content (join-path $port.FullName "portfile.cmake") -Raw
$match = $fileContent | Select-String 'vcpkg_from_github\([\s\S]*\bREPO\s+(\S+)[\s\S]+\bREF\s+(\S+)[\s\S]*?\)' |
%{ $_.Matches }
if (!$match)
{
continue
}
$githubPage = $match.Groups[1].Value
$version = $match.Groups[2].Value
$status = $null
$versionMatch = $version | Select-String '\${(\w+)}' | %{ $_.Matches }
if ($versionMatch.Success)
{
$varName = $versionMatch.Groups[1].Value
$variableMatch = $fileContent | Select-String "set\($varName\s+(\S+)\)" |
%{$_.Matches}
if ($versionMatch.Success)
{
$varValue = $variableMatch.Groups[1].Value
$version = "$($version.replace("`${$varName}", "$varValue"))"
}
}
try
{
$wr = Invoke-WebRequest -Uri "https://api.github.com/repos/$githubPage/releases/latest" -Headers @{"Authorization"="Basic $BasicCreds"}
$tag_name = $wr.Content | ConvertFrom-Json | %{ $_.tag_name }
if ($version -eq $tag_name)
{
$status = "Latest"
}
else
{
$status = "New version $tag_name is available"
}
}
catch [System.Net.WebException]
{
$statusCode = $_.Exception.Response.StatusCode
if ($statusCode -eq "Forbidden")
{
$status = "API rate limit exceeded"
}
elseif ($statusCode -eq "NotFound")
{
# Try with latest tag
try
{
$wr = Invoke-WebRequest -Uri "https://api.github.com/repos/$githubPage/tags" -Headers @{"Authorization"="Basic $BasicCreds"}
$name = $wr.Content | ConvertFrom-Json | %{ $_.name } | Select-Object -first 1
if ($name.Count -eq 0)
{
$status = $null
}
elseif ($version -eq $name)
{
$status = "Latest"
}
else
{
$status = "New tag $name is available"
}
}
catch [System.Net.WebException]
{
$statusCode = $_.Exception.Response.StatusCode
if ($statusCode -eq "Forbidden")
{
$status = "API rate limit exceeded"
}
elseif ($statusCode -eq "NotFound")
{
$status = $null
}
else
{
$status = "Unknown error: $statusCode"
}
}
}
else
{
$status = "Unknown error: $statusCode"
}
}
catch
{
$_
}
if ($status)
{
$port.Name
" $githubPage $version"
if ($status.StartsWith("New "))
{
write-host " $status" -foregroundcolor "green"
}
else
{
" $status"
}
}
}
@KindDragon
Copy link
Author

This is great and there might be a room for improvement i.e. opus and opusfile newer and older versions are interchanged

It's because they forgot to create new GitHub releases for 0.8 and 0.9 version: https://github.com/xiph/opusfile/releases

@atkawa7
Copy link

atkawa7 commented Aug 22, 2017

I see. What are your thoughts on a PR? Would love to see this merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment