From 9f7911923c1976351ee7697453960e34087105f5 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Fri, 24 Mar 2017 16:40:41 -0600 Subject: [PATCH] updated the create_upg_check_files script to be parameterized for use within jenkins --- Jenkinsfile_publish.groovy | 5 ++ Tools/create_upg_chk_files.ps1 | 139 ++++++++++++++++++++++++--------- 2 files changed, 108 insertions(+), 36 deletions(-) diff --git a/Jenkinsfile_publish.groovy b/Jenkinsfile_publish.groovy index 12640d98..6bd01f0e 100644 --- a/Jenkinsfile_publish.groovy +++ b/Jenkinsfile_publish.groovy @@ -50,6 +50,11 @@ node('windows') { stage ('Run Unit Tests (Portable)') { bat "\"${vsToolsDir}\\VsDevCmd.bat\" && VSTest.Console.exe /logger:trx /TestAdapterPath:${nunitTestAdapterPath} \"${jobDir}\\mRemoteNGTests\\bin\\Release Portable\\mRemoteNGTests.dll\"" } + + stage ('Generate UpdateCheck Files') { + bat "powershell -ExecutionPolicy Bypass -File \"${jobDir}\\Tools\\publish_to_github.ps1\" -TagName \"${env.TagName}\" -UpdateChannel \"${env.UpdateChannel}\"" + archiveArtifacts artifacts: "Release\\*.txt", caseSensitive: false, onlyIfSuccessful: true + } stage ('Publish to GitHub') { withCredentials([string(credentialsId: '5443a369-dbe8-42d3-b4e8-04d0b4e9039a', variable: 'GH_AUTH_TOKEN')]) { diff --git a/Tools/create_upg_chk_files.ps1 b/Tools/create_upg_chk_files.ps1 index 28d53954..acf2e88a 100644 --- a/Tools/create_upg_chk_files.ps1 +++ b/Tools/create_upg_chk_files.ps1 @@ -1,42 +1,109 @@ #Requires -Version 4.0 +param ( + [string] + [Parameter(Mandatory=$true)] + $TagName, + + [string] + [Parameter(Mandatory=$true)] + [ValidateSet("Stable","Beta","Development")] + $UpdateChannel +) + + + +function New-MsiUpdateFileContent { + param ( + [System.IO.FileInfo] + [Parameter(Mandatory=$true)] + $MsiFile, + + [string] + [Parameter(Mandatory=$true)] + $TagName + ) + + $version = $MsiFile.BaseName -replace "[a-zA-Z-]*" + $certThumbprint = (Get-AuthenticodeSignature -FilePath $MsiFile).SignerCertificate.Thumbprint + $hash = Get-FileHash -Algorithm SHA512 $MsiFile | % { $_.Hash } + + $fileContents = ` +"Version: $version +dURL: https://github.com/mRemoteNG/mRemoteNG/releases/download/$TagName/$($MsiFile.Name) +clURL: https://raw.githubusercontent.com/mRemoteNG/mRemoteNG/$TagName/CHANGELOG.TXT +CertificateThumbprint: $certThumbprint +Checksum: $hash" + Write-Output $fileContents +} + + +function New-ZipUpdateFileContent { + param ( + [System.IO.FileInfo] + [Parameter(Mandatory=$true)] + $ZipFile, + + [string] + [Parameter(Mandatory=$true)] + $TagName + ) + + $version = $ZipFile.BaseName -replace "[a-zA-Z-]*" + $hash = Get-FileHash -Algorithm SHA512 $ZipFile | % { $_.Hash } + + $fileContents = ` +"Version: $version +dURL: https://github.com/mRemoteNG/mRemoteNG/releases/download/$TagName/$($ZipFile.Name) +clURL: https://raw.githubusercontent.com/mRemoteNG/mRemoteNG/$TagName/CHANGELOG.TXT +Checksum: $hash" + Write-Output $fileContents +} + + +function Resolve-UpdateCheckFileName { + param ( + [string] + [Parameter(Mandatory=$true)] + [ValidateSet("Stable","Beta","Development")] + $UpdateChannel, + + [string] + [Parameter(Mandatory=$true)] + [ValidateSet("Normal","Portable")] + $Type + ) + + $fileName = "" + + if ($UpdateChannel -eq "Beta") { $fileName += "beta-" } + elseif ($UpdateChannel -eq "Development") { $fileName += "dev-" } + + $fileName += "update" + + if ($Type -eq "Portable") { $fileName += "-portable" } + + $fileName += ".txt" + + Write-Output $fileName +} + + + + $releaseFolder = Join-Path -Path $PSScriptRoot -ChildPath "..\Release" -Resolve -$tag = Read-Host -Prompt 'Tag name' -Write-Host -Write-Host -Write-Host +# build msi update file +$msiFile = Get-ChildItem -Path "$releaseFolder\*.msi" | sort LastWriteTime | select -last 1 +$msiUpdateContents = New-MsiUpdateFileContent -MsiFile $msiFile -TagName $TagName +$msiUpdateFileName = Resolve-UpdateCheckFileName -UpdateChannel $UpdateChannel -Type Normal +Write-Output "`n`nMSI Update Check File Contents ($msiUpdateFileName)`n------------------------------" +Tee-Object -InputObject $msiUpdateContents -FilePath "$releaseFolder\$msiUpdateFileName" -Write-Host PORTABLE -Write-Host -------- -$file = Get-ChildItem -Path "$releaseFolder\*.zip" | sort LastWriteTime | select -last 1 | % { $_.FullName } -$filename = $file.Split("\") | select -last 1 -$version = $file.tostring().Split("-")[2].trim(".zip") -Write-Host Version: $version - -Write-Host dURL: https://github.com/mRemoteNG/mRemoteNG/releases/download/$tag/$filename -Write-Host clURL: https://raw.githubusercontent.com/mRemoteNG/mRemoteNG/$tag/CHANGELOG.TXT - -$hash = Get-FileHash -Algorithm SHA512 $file | % { $_.Hash } -Write-Host Checksum: $hash - - -Write-Host -Write-Host -Write-Host - -Write-Host MSI -Write-Host --- -$file = Get-ChildItem -Path "$releaseFolder\*.msi" | sort LastWriteTime | select -last 1 | % { $_.FullName } -$filename = $file.Split("\") | select -last 1 - -$version = $file.tostring().Split("-")[2].trim(".msi") -Write-Host Version: $version - -Write-Host dURL: https://github.com/mRemoteNG/mRemoteNG/releases/download/$tag/$filename -Write-Host clURL: https://raw.githubusercontent.com/mRemoteNG/mRemoteNG/$tag/CHANGELOG.TXT - -Write-Host CertificateThumbprint: 0CEA828E5C787EA8AA89268D83816C1EA03375BA -$hash = Get-FileHash -Algorithm SHA512 $file | % { $_.Hash } -Write-Host Checksum: $hash \ No newline at end of file +# build zip update file +$zipFile = Get-ChildItem -Path "$releaseFolder\*.zip" | sort LastWriteTime | select -last 1 +$zipUpdateContents = New-ZipUpdateFileContent -ZipFile $zipFile -TagName $TagName +$zipUpdateFileName = Resolve-UpdateCheckFileName -UpdateChannel $UpdateChannel -Type Portable +Write-Output "`n`nZip Update Check File Contents ($zipUpdateFileName)`n------------------------------" +Tee-Object -InputObject $zipUpdateContents -FilePath "$releaseFolder\$zipUpdateFileName" \ No newline at end of file