Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersign committed Feb 25, 2019
2 parents 631ea89 + d4f71ed commit 9eb4daa
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 22 deletions.
4 changes: 2 additions & 2 deletions BenchManager/BenchCLI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.21.0.0")]
[assembly: AssemblyFileVersion("0.21.0.0")]
[assembly: AssemblyVersion("0.21.1.0")]
[assembly: AssemblyFileVersion("0.21.1.0")]
4 changes: 2 additions & 2 deletions BenchManager/BenchDashboard/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.21.0.0")]
[assembly: AssemblyFileVersion("0.21.0.0")]
[assembly: AssemblyVersion("0.21.1.0")]
[assembly: AssemblyFileVersion("0.21.1.0")]
4 changes: 2 additions & 2 deletions BenchManager/BenchLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.21.0.0")]
[assembly: AssemblyFileVersion("0.21.0.0")]
[assembly: AssemblyVersion("0.21.1.0")]
[assembly: AssemblyFileVersion("0.21.1.0")]
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Add a link to the GitHub diff like

[Unreleased]: https://github.com/winbench/bench/compare/master...dev

## [0.21.1] - 2019-02-25

[0.21.1]: https://github.com/winbench/bench/compare/v0.21.0...v0.21.1

### Changed
* Reactivated old TLS 1.0 to support some ill configured web servers

## [0.21.0] - 2018-12-14

[0.21.0]: https://github.com/winbench/bench/compare/v0.20.5...v0.21.0
Expand Down
180 changes: 166 additions & 14 deletions auto/lib/Check-Apps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,137 @@ $Script:scriptsDir = [IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definit
. "$Script:scriptsDir\config.lib.ps1"

# $DebugPreference = "Continue"
# $InformationPreference = "Continue"
$InformationPreference = "Continue"

if ($GitHubUserName) {
$GitHubPassword = Read-Host "GitHub Password" -AsSecureString
$GitHubPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($GitHubPassword))
$Script:GitHubCredential = New-Object System.Management.Automation.PSCredential @($GitHubUserName, $GitHubPassword)
}

$_ = [Reflection.Assembly]::LoadFrom("$Script:scriptsDir\..\bin\HtmlAgilityPack.dll")
$_ = Add-Type -AssemblyName System.Web

$Script:web = New-Object HtmlAgilityPack.HtmlWeb
[Net.ServicePointManager]::SecurityProtocol = 'Tls11,Tls12'
$webClientClassCode = @"
using System;
using System.Net;
public class DecompressingWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = base.GetWebRequest(address) as HttpWebRequest;
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
return request;
}
public void AdditionalMethodToSuppressWarning() { }
}
"@
$_ = Add-Type -TypeDefinition $webClientClassCode
$Script:webClient = New-Object DecompressingWebClient
$Script:webClient.Credentials = $CredentialCache

[Net.ServicePointManager]::SecurityProtocol = 'Tls,Tls11,Tls12'

$Script:cacheDir = "${env:TEMP}\bench-app-check-$([DateTime]::Now.ToString("yyyyMMddHH"))"
if (!(Test-Path $Script:cacheDir)) {
mkdir $cacheDir | Out-Null
}

#
# ---- CACHING ----
#

function AuthHeaders($user, $pass) {
if ($user) {
function hash($s) {
$algo = [System.Security.Cryptography.MD5]::Create()
$data = $algo.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($s))
return [BitConverter]::ToString($data).Replace("-", "")
}

function cacheFile($name) {
return [IO.Path]::Combine($Script:cacheDir, (hash $name))
}

function loadDataFromCache($url) {
$cacheFile = cacheFile $url
if (Test-Path $cacheFile) {
Write-Debug "Read from cache: $cacheFile"
return [IO.File]::ReadAllBytes($cacheFile)
} else {
Write-Debug "Cache miss: $cacheFile"
return $null
}
}

function storeDataToCache($url, $data) {
$cacheFile = cacheFile $url
Write-Debug "Write to cache: $cacheFile"
[IO.File]::WriteAllBytes($cacheFile, $data)
}

#
# ---- LOADING WEB RESOURCES ----
#

function encodeCredential($Credential = $null) {

if ($Credential) {
$user = $Credential.UserName
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password))
$pair = "${user}:${pass}"
$encodedCreds = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair))
return @{ Authorization = "Basic $encodedCreds" }
return "Basic $encodedCreds"
} else {
return @{}
return $null
}
}

function downloadData($url, $Credential = $null) {
Write-Information "Download of $url"
$Script:webClient.Headers.Add("User-Agent", "Bench App Version Check")
if ($Credential) {
$Script:webClient.Headers.Add("Authorization", (encodeCredential $Credential))
}
$Script:webClient.UseDefaultCredentials = $false
return $Script:webClient.DownloadData($url)
}

function loadData($url, $Credential = $null) {
[byte[]]$content = loadDataFromCache $url
if (!$content) {
$content = downloadData $url -Credential $Credential
storeDataToCache $url $content
}
return $content
}

function loadHtmlDoc($url, $Credential = $null) {
$content = loadData $url -Credential $Credential
$ms = New-Object System.IO.MemoryStream -ArgumentList @(,$content)
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.Load($ms)
$ms.Dispose()
return $doc
}

function loadJsonDoc($url, $Credential = $null) {
$content = loadData $url -Credential $Credential
$json = [System.Text.Encoding]::UTF8.GetString($content, 0, $content.Length)
return $json | ConvertFrom-Json
}

#
# ---- PARSING HTML DOCS ----
#

function findVersionsInNode($app, $node, $attr, $re) {
if ($attr) {
$text = $node.Attributes[$attr].Value
} else {
$text = $node.InnerText
}
if ($text) {
$text = $text.Trim()
$text = [System.Web.HttpUtility]::HtmlDecode($text)
Write-Debug "TEST: $($text.Substring(0, [Math]::Min(128, $text.Length)))"
foreach ($m in $re.Matches($text)) {
$m.Groups["Version"].Value
}
Expand Down Expand Up @@ -69,6 +171,36 @@ function findVersionsInDoc($app, $doc, $xpath, $re) {
}
}

#
# ---- PARSING JSON ----
#

function findVersionsInData($app, $data, $path, $re) {
$pathParts = $path.Split("/")
Write-Debug "Data Selection Path: $([string]::Join(" -> ", $pathParts))"
$pivot = $data
foreach ($part in $pathParts) {
if ($pivot -eq $null) { break }
if ($pivot -is [PSCustomObject]) {
$pivot = $pivot.$part
} else {
$pivot = $pivot[$part]
}
}
if ($pivot) {
Write-Debug "String: $pivot"
foreach ($m in $re.Matches($pivot)) {
$m.Groups["Version"].Value
}
} else {
Write-Debug "Path not found in data."
}
}

#
# ---- FIND LATEST VERSION ----
#

function normalizeVersion($version) {
$parts = $version.Split('.')
$norms = $parts | % { $_.PadLeft(6, '0') }
Expand All @@ -81,20 +213,32 @@ function findHighestAppVersion($app) {
$checkPattern = Get-AppConfigValue $app.ID "VersionCheckPattern"
if (!$checkPattern) { return $false }
$checkXPath = Get-AppConfigValue $app.ID "VersionCheckXPath"
$checkJsonPath = Get-AppConfigValue $app.ID "VersionCheckJsonPath"
Write-Host ""
Write-Host "Checking $($app.AppLibrary.ID):$($app.ID) ..."
[regex]$checkRe = $checkPattern
Write-Debug "Version Check Pattern: $checkRe"
$doc = $Script:web.Load($checkUrl)
$versions = findVersionsInDoc $app $doc $checkXPath $checkRe `
| sort -Descending -Property { normalizeVersion $_ }
if ($checkJsonPath) {
$data = loadJsonDoc $checkUrl
$versions = findVersionsInData $app $data $checkJsonPath $checkRe
} else {
$doc = loadHtmlDoc $checkUrl
$versions = findVersionsInDoc $app $doc $checkXPath $checkRe
}
$ignoredVersions = Get-AppConfigListValue $app.ID "VersionCheckIgnore"
if ($ignoredVersions) {
$versions = $versions | ? { $_ -notin $ignoredVersions }
}
if ($versions -is [string]) {
$version = $versions
Write-Information "Found one version: $version"
return $version
}
if ($versions) {
$versions = $versions | sort -Descending -Property { normalizeVersion $_ }
Write-Information "Found versions: $([string]::Join(", ", $versions))"
$normVersions = $versions | % { normalizeVersion $_ }
Write-Debug "Normalized versions: $([string]::Join(", ", $normVersions))"
return $versions[0]
}
return $null
Expand All @@ -108,15 +252,21 @@ function findLatestGitHubRelease($app) {
if (!$m.Success) { return $false }
$owner = $m.Groups["Owner"].Value
$project = $m.Groups["Project"].Value
$ignoredVersions = Get-AppConfigListValue $app.ID "VersionCheckIgnore"
Write-Host ""
Write-Host "Checking $($app.AppLibrary.ID):$($app.ID) on GitHub $owner/$project ..."
$apiUrl = "https://api.github.com/repos/$owner/$project/releases"
$authHeaders = AuthHeaders $Script:GitHubUserName $Script:GitHubPassword
$releases = Invoke-WebRequest $apiUrl -Headers $authHeaders | ConvertFrom-Json
$releases = loadJsonDoc $apiUrl -Credential $Script:GitHubCredential
if (Get-AppConfigBooleanValue $app.ID "VersionCheckAllowPreRelease") {
Write-Information "Allow Pre-Release"
$releases = $releases | ? { !$_.draft }
} else {
$releases = $releases | ? { !$_.draft -and !$_.prerelease }
}
$tags = $releases `
| ? { !$_.draft -and !$_.prerelease } `
| % { $_.tag_name } `
| % { if ($_.StartsWith("v")) { $_.Substring(1) } else { $_ } } `
| ? { if (!$ignoredVersions) { return $true } else { return $_ -notin $ignoredVersions } } `
| sort -Descending -Property { normalizeVersion $_ }
if ($tags -is [string]) {
$tag = $tags
Expand All @@ -125,6 +275,8 @@ function findLatestGitHubRelease($app) {
}
if ($tags) {
Write-Information "Found releases: $([string]::Join(", ", $tags))"
$normTags = $tags | % { normalizeVersion $_ }
Write-Debug "Normalized releases: $([string]::Join(", ", $normTags))"
return $tags[0]
}
return $null
Expand Down
2 changes: 1 addition & 1 deletion res/bench-install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SetLocal
:: https://winbench.org/guide/setup/
::

SET VERSION=0.21.0
SET VERSION=0.21.1
SET TAG=v%VERSION%
SET ROOT=%~dp0
IF [%1] NEQ [] SET ROOT=%~dpnx1\
Expand Down
1 change: 1 addition & 0 deletions res/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* DownloadAttempts: 3
* ParallelDownloads: 4
* HttpsSecurityProtocols:
+ `Tls`
+ `Tls11`
+ `Tls12`
* LogLevel: `Info`
Expand Down
2 changes: 1 addition & 1 deletion res/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.21.0
0.21.1

0 comments on commit 9eb4daa

Please sign in to comment.