From 9f7911923c1976351ee7697453960e34087105f5 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Fri, 24 Mar 2017 16:40:41 -0600 Subject: [PATCH 1/5] 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 12640d98e..6bd01f0ec 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 28d539549..acf2e88a9 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 From 80ac0259b8060d623196cd688160dc522f212e43 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Fri, 24 Mar 2017 16:50:15 -0600 Subject: [PATCH 2/5] fix script name --- Jenkinsfile_publish.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile_publish.groovy b/Jenkinsfile_publish.groovy index 6bd01f0ec..3089f39cb 100644 --- a/Jenkinsfile_publish.groovy +++ b/Jenkinsfile_publish.groovy @@ -52,7 +52,7 @@ node('windows') { } stage ('Generate UpdateCheck Files') { - bat "powershell -ExecutionPolicy Bypass -File \"${jobDir}\\Tools\\publish_to_github.ps1\" -TagName \"${env.TagName}\" -UpdateChannel \"${env.UpdateChannel}\"" + bat "powershell -ExecutionPolicy Bypass -File \"${jobDir}\\Tools\\create_upg_chk_files.ps1\" -TagName \"${env.TagName}\" -UpdateChannel \"${env.UpdateChannel}\"" archiveArtifacts artifacts: "Release\\*.txt", caseSensitive: false, onlyIfSuccessful: true } From 16be19b5d39de594b6a8d6253b38ea9c822ce1fa Mon Sep 17 00:00:00 2001 From: David Sparer Date: Fri, 24 Mar 2017 18:07:23 -0600 Subject: [PATCH 3/5] split github functions to a library script --- Tools/github_functions.ps1 | 220 ++++++++++++++++++++++++++++++++++++ Tools/publish_to_github.ps1 | 130 +-------------------- 2 files changed, 224 insertions(+), 126 deletions(-) create mode 100644 Tools/github_functions.ps1 diff --git a/Tools/github_functions.ps1 b/Tools/github_functions.ps1 new file mode 100644 index 000000000..9e87e1e03 --- /dev/null +++ b/Tools/github_functions.ps1 @@ -0,0 +1,220 @@ +$githubUrl = 'https://api.github.com' + + +function Publish-GitHubRelease { + param ( + [string] + [Parameter(Mandatory=$true)] + # + $Owner, + + [string] + [Parameter(Mandatory=$true)] + # + $Repository, + + [string] + [Parameter(Mandatory=$true)] + # + $ReleaseTitle, + + [string] + [Parameter(Mandatory=$true)] + # + $TagName, + + [string] + [Parameter(Mandatory=$true)] + # Either the SHA of the commit to target or the branch name. + $TargetCommitish, + + [string] + [Parameter(Mandatory=$true)] + # + $Description, + + [bool] + [Parameter(Mandatory=$true)] + # + $IsDraft, + + [bool] + [Parameter(Mandatory=$true)] + # + $IsPrerelease, + + [string] + [Parameter(Mandatory=$true)] + # The OAuth2 token to use for authentication. + $AuthToken + ) + + $body = New-GitHubReleaseRequestBody -tag_name $TagName -target_commitish $TargetCommitish -name $ReleaseTitle -body $Description -draft $IsDraft -prerelease $IsPrerelease + $req_publishRelease = Invoke-WebRequest -Uri "$githubUrl/repos/$Owner/$Repository/releases" -Method Post -Headers @{"Authorization"="token $AuthToken"} -Body $body -ErrorAction Stop + $response_publishRelease = ConvertFrom-Json -InputObject $req_publishRelease.Content + + Write-Output $response_publishRelease +} + + +function Edit-GitHubRelease { + param ( + [string] + #[Parameter(Mandatory=$true)] + # + $Owner, + + [string] + #[Parameter(Mandatory=$true)] + # + $Repository, + + [string] + #[Parameter(Mandatory=$true)] + # + $ReleaseId, + + [string] + # + $ReleaseTitle, + + [string] + # + $TagName, + + [string] + # Either the SHA of the commit to target or the branch name. + $TargetCommitish, + + [string] + # + $Description, + + [bool] + # + $IsDraft, + + [bool] + # + $IsPrerelease, + + [string] + #[Parameter(Mandatory=$true)] + # The OAuth2 token to use for authentication. + $AuthToken + ) + + $body_params = @{ + "TagName" = $TagName + "TargetCommitish" = $TargetCommitish + "ReleaseTitle" = $ReleaseTitle + "Description" = $Description + } + if ($PSBoundParameters.ContainsKey("IsDraft")) { $body_params.Add("IsDraft", $IsDraft) } + if ($PSBoundParameters.ContainsKey("IsPrerelease")) { $body_params.Add("IsPrerelease", $IsPrerelease) } + + $body = New-GitHubReleaseRequestBody @body_params + $req_editRelease = Invoke-WebRequest -Uri "$githubUrl/repos/$Owner/$Repository/releases/$ReleaseId" -Method Post -Headers @{"Authorization"="token $AuthToken"} -Body $body -ErrorAction Stop + $response_editRelease = ConvertFrom-Json -InputObject $req_editRelease.Content + + Write-Output $response_editRelease +} + + +function Get-GitHubRelease { + param ( + [string] + [Parameter(Mandatory=$true)] + # + $Owner, + + [string] + [Parameter(Mandatory=$true)] + # + $Repository, + + [string] + [Parameter(Mandatory=$true)] + # + $ReleaseId, + + [string] + [Parameter(Mandatory=$true)] + # The OAuth2 token to use for authentication. + $AuthToken + ) + + $req_getRelease = Invoke-WebRequest -Uri "$githubUrl/repos/$Owner/$Repository/releases/$ReleaseId" -Method Get -Headers @{"Authorization"="token $AuthToken"} -ErrorAction Stop + $response_getRelease = ConvertFrom-Json -InputObject $req_getRelease.Content + + Write-Output $response_getRelease +} + + +function Upload-GitHubReleaseAsset { + param ( + [string] + [Parameter(Mandatory=$true)] + $UploadUri, + + [string] + [Parameter(Mandatory=$true)] + # Path to the file to upload with the release + $FilePath, + + [string] + [Parameter(Mandatory=$true)] + # Content type of the file + $ContentType, + + [string] + [Parameter(Mandatory=$true)] + # The OAuth2 token to use for authentication. + $AuthToken + ) + + $UploadUri = $UploadUri -replace "(\{[\w,\?]*\})$" + $file = Get-Item -Path $FilePath + + $req_uploadZipAsset = Invoke-WebRequest -Uri "$($UploadUri)?name=$($file.Name)" -Method Post -Headers @{"Authorization"="token $AuthToken"} -ContentType $ContentType -InFile $file.FullName -ErrorAction Stop +} + + +function New-GitHubReleaseRequestBody { + param ( + [string] + # + $TagName, + + [string] + # Either the SHA of the commit to target or the branch name. + $TargetCommitish, + + [string] + # Title of the release + $ReleaseTitle, + + [string] + # Description of the release + $Description, + + [bool] + # Is this a draft? + $IsDraft, + + [bool] + # Is this a pre-release? + $IsPrerelease + ) + + $body_params = [ordered]@{} + if ($TagName -ne "") { $body_params.Add("tag_name", $TagName) } + if ($TargetCommitish -ne "") { $body_params.Add("target_commitish", $TargetCommitish) } + if ($ReleaseTitle -ne "") { $body_params.Add("name", $ReleaseTitle) } + if ($Description -ne "") { $body_params.Add("body", $Description) } + if ($PSBoundParameters.ContainsKey("IsDraft")) { $body_params.Add("draft", $IsDraft) } + if ($PSBoundParameters.ContainsKey("IsPrerelease")) { $body_params.Add("prerelease", $IsPrerelease) } + + $json_body = ConvertTo-Json -InputObject $body_params -Compress + Write-Output $json_body +} \ No newline at end of file diff --git a/Tools/publish_to_github.ps1 b/Tools/publish_to_github.ps1 index 6a8344321..4f920a0d8 100644 --- a/Tools/publish_to_github.ps1 +++ b/Tools/publish_to_github.ps1 @@ -62,137 +62,15 @@ param ( ) -$githubUrl = 'https://api.github.com' if ($DescriptionIsBase64Encoded) { $Description = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Description))) } -function Publish-Release { - param ( - [string] - [Parameter(Mandatory=$true)] - # - $Owner, - - [string] - [Parameter(Mandatory=$true)] - # - $Repository, - - [string] - [Parameter(Mandatory=$true)] - # - $ReleaseTitle, - - [string] - [Parameter(Mandatory=$true)] - # - $TagName, - - [string] - [Parameter(Mandatory=$true)] - # Either the SHA of the commit to target or the branch name. - $TargetCommitish, - - [string] - [Parameter(Mandatory=$true)] - # - $Description, - - [bool] - [Parameter(Mandatory=$true)] - # - $IsDraft, - - [bool] - [Parameter(Mandatory=$true)] - # - $IsPrerelease, - - [string] - [Parameter(Mandatory=$true)] - # The OAuth2 token to use for authentication. - $AuthToken - ) - - $body_publishRelease = @{ - "tag_name" = $TagName - "target_commitish" = $TargetCommitish - "name" = $ReleaseTitle - "body" = $Description - "draft" = $IsDraft - "prerelease" = $IsPrerelease - } - - $req_publishRelease = Invoke-WebRequest -Uri "$githubUrl/repos/$Owner/$Repository/releases" -Method Post -Headers @{"Authorization"="token $AuthToken"} -Body (ConvertTo-Json -InputObject $body_publishRelease -Compress) -ErrorAction Stop - $response_publishRelease = ConvertFrom-Json -InputObject $req_publishRelease.Content - - Write-Output $response_publishRelease -} +. "$PSScriptRoot\github_functions.ps1" -function Get-GitHubRelease { - param ( - [string] - [Parameter(Mandatory=$true)] - # - $Owner, - - [string] - [Parameter(Mandatory=$true)] - # - $Repository, - - [string] - [Parameter(Mandatory=$true)] - # - $ReleaseId, - - [string] - [Parameter(Mandatory=$true)] - # The OAuth2 token to use for authentication. - $AuthToken - ) - - $req_getRelease = Invoke-WebRequest -Uri "$githubUrl/repos/$Owner/$Repository/releases/$ReleaseId" -Method Get -Headers @{"Authorization"="token $AuthToken"} -ErrorAction Stop - $response_getRelease = ConvertFrom-Json -InputObject $req_getRelease.Content - - Write-Output $response_getRelease -} - - -function Upload-ReleaseAsset { - param ( - [string] - [Parameter(Mandatory=$true)] - $UploadUri, - - [string] - [Parameter(Mandatory=$true)] - # Path to the file to upload with the release - $FilePath, - - [string] - [Parameter(Mandatory=$true)] - # Content type of the file - $ContentType, - - [string] - [Parameter(Mandatory=$true)] - # The OAuth2 token to use for authentication. - $AuthToken - ) - - $UploadUri = $UploadUri -replace "(\{[\w,\?]*\})$" - $file = Get-Item -Path $FilePath - - $req_uploadZipAsset = Invoke-WebRequest -Uri "$($UploadUri)?name=$($file.Name)" -Method Post -Headers @{"Authorization"="token $AuthToken"} -ContentType $ContentType -InFile $file.FullName -ErrorAction Stop -} - - - -$release = Publish-Release -Owner $Owner -Repository $Repository -ReleaseTitle $ReleaseTitle -TagName $TagName -TargetCommitish $TargetCommitish -Description $Description -IsDraft ([bool]::Parse($IsDraft)) -IsPrerelease ([bool]::Parse($IsPrerelease)) -AuthToken $AuthToken -$zipUpload = Upload-ReleaseAsset -UploadUri $release.upload_url -FilePath $ZipFilePath -ContentType "application/zip" -AuthToken $AuthToken -$msiUpload = Upload-ReleaseAsset -UploadUri $release.upload_url -FilePath $MsiFilePath -ContentType "application/octet-stream" -AuthToken $AuthToken +$release = Publish-GitHubRelease -Owner $Owner -Repository $Repository -ReleaseTitle $ReleaseTitle -TagName $TagName -TargetCommitish $TargetCommitish -Description $Description -IsDraft ([bool]::Parse($IsDraft)) -IsPrerelease ([bool]::Parse($IsPrerelease)) -AuthToken $AuthToken +$zipUpload = Upload-GitHubReleaseAsset -UploadUri $release.upload_url -FilePath $ZipFilePath -ContentType "application/zip" -AuthToken $AuthToken +$msiUpload = Upload-GitHubReleaseAsset -UploadUri $release.upload_url -FilePath $MsiFilePath -ContentType "application/octet-stream" -AuthToken $AuthToken Write-Output (Get-GitHubRelease -Owner $Owner -Repository $Repository -ReleaseId $release.id -AuthToken $AuthToken) \ No newline at end of file From 9e20f1dd335e4d9b8bca2feef4ec0b963367ec1b Mon Sep 17 00:00:00 2001 From: David Sparer Date: Fri, 24 Mar 2017 18:08:27 -0600 Subject: [PATCH 4/5] created script for publishing a github release that is currently in draft mode --- Tools/publish_draft_github_release.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Tools/publish_draft_github_release.ps1 diff --git a/Tools/publish_draft_github_release.ps1 b/Tools/publish_draft_github_release.ps1 new file mode 100644 index 000000000..ab5f0ec87 --- /dev/null +++ b/Tools/publish_draft_github_release.ps1 @@ -0,0 +1,25 @@ +param ( + [string] + [Parameter(Mandatory=$true)] + # + $Owner, + + [string] + [Parameter(Mandatory=$true)] + # + $Repository, + + [string] + [Parameter(Mandatory=$true)] + # + $ReleaseId, + + [string] + [Parameter(Mandatory=$true)] + # The OAuth2 token to use for authentication. + $AuthToken +) + +. "$PSScriptRoot\github_functions.ps1" + +Edit-GitHubRelease -Owner $Owner -Repository $Repository -ReleaseId $ReleaseId -AuthToken $AuthToken -IsDraft $false \ No newline at end of file From e5c2cfd2431a30919af82d3fdbf30167ff674c01 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Thu, 10 Aug 2017 16:35:17 -0500 Subject: [PATCH 5/5] fix github release body builder function --- Tools/github_functions.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/github_functions.ps1 b/Tools/github_functions.ps1 index 9e87e1e03..8f38fbda4 100644 --- a/Tools/github_functions.ps1 +++ b/Tools/github_functions.ps1 @@ -49,7 +49,7 @@ function Publish-GitHubRelease { $AuthToken ) - $body = New-GitHubReleaseRequestBody -tag_name $TagName -target_commitish $TargetCommitish -name $ReleaseTitle -body $Description -draft $IsDraft -prerelease $IsPrerelease + $body = New-GitHubReleaseRequestBody -TagName $TagName -TargetCommitish $TargetCommitish -ReleaseTitle $ReleaseTitle -Description $Description -IsDraft $IsDraft -IsPrerelease $IsPrerelease $req_publishRelease = Invoke-WebRequest -Uri "$githubUrl/repos/$Owner/$Repository/releases" -Method Post -Headers @{"Authorization"="token $AuthToken"} -Body $body -ErrorAction Stop $response_publishRelease = ConvertFrom-Json -InputObject $req_publishRelease.Content