Skip to content

Commit

Permalink
(scripts) Added helper script for urls without version info
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Apr 23, 2018
1 parent 01513da commit b781e63
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions scripts/Update-OnETagChanged.ps1
@@ -0,0 +1,50 @@
# NOTE: No documentation will be written for this script.
# This is only a temporary script until a generic version
# have been added to the wormies-au-helpers powershell package

function Update-OnETagChanged() {
param(
[uri]$execUrl,
[string]$saveFile = ".\info",
[scriptblock]$OnETagChanged,
[scriptblock]$OnUpdated
)

$request = [System.Net.WebRequest]::CreateDefault($execUrl)

try {
$response = $request.GetResponse()
$etag = $response.Headers.Get("ETag")
}
finally {
$response.Dispose()
$response = $null
}

$saveResult = $false
if (!(Test-Path $saveFile) -or ($global:au_Force -eq $true)) {
$result = . $OnETagChanged
$saveResult = $true
}
else {
$existingInfo = (Get-Content $saveFile -Encoding UTF8 -TotalCount 1) -split '\|'

if ($existingInfo[0] -ne $etag) {
$result = . $OnETagChanged
$saveResult = $true
}
else {
$result = . $OnUpdated
$result["Version"] = $existingInfo[1]
$result["ETAG"] = $existingInfo[0]
$saveResult = $false
}
}

if ($saveResult) {
$result["ETAG"] = $etag
"$($result["ETAG"])|$($result["Version"])" | Out-File $saveFile -Encoding utf8 -NoNewline
}

return $result
}
1 change: 1 addition & 0 deletions scripts/au_extensions.psm1
Expand Up @@ -7,6 +7,7 @@
$funcs = @(
'Set-DescriptionFromReadme'
'Update-ChangelogVersion'
'Update-OnETagChanged'
)

$funcs | % {
Expand Down

0 comments on commit b781e63

Please sign in to comment.