diff --git a/Jenkinsfile_publish.groovy b/Jenkinsfile_publish.groovy index eaf8990c..2c30f879 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\\create_upg_chk_files.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 diff --git a/Tools/github_functions.ps1 b/Tools/github_functions.ps1 new file mode 100644 index 00000000..8f38fbda --- /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 -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 + + 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_draft_github_release.ps1 b/Tools/publish_draft_github_release.ps1 new file mode 100644 index 00000000..ab5f0ec8 --- /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 diff --git a/Tools/publish_to_github.ps1 b/Tools/publish_to_github.ps1 index 6a834432..4f920a0d 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