From a3fa1e541c9efb36a7c7ff0c49f42fa2a5e227e0 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sat, 25 Aug 2018 17:02:54 -0500 Subject: [PATCH 1/2] modified build to label assets --- Jenkinsfile_publish.groovy | 5 ++--- Tools/github_functions.ps1 | 13 +++++++++++-- Tools/publish_to_github.ps1 | 23 ++++++++++++++--------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile_publish.groovy b/Jenkinsfile_publish.groovy index d304d0f6f..4ced70c2d 100644 --- a/Jenkinsfile_publish.groovy +++ b/Jenkinsfile_publish.groovy @@ -62,11 +62,10 @@ node('windows') { stage ('Publish to GitHub') { withCredentials([string(credentialsId: '5443a369-dbe8-42d3-b4e8-04d0b4e9039a', variable: 'GH_AUTH_TOKEN')]) { - def zipPath = "${jobDir}\\Release\\*.zip" - def msiPath = "${jobDir}\\Release\\*.msi" + def releaseFolder = "${jobDir}\\Release" // because batch files suck at handling newline characters, we have to convert to base64 in groovy and back to text in powershell def base64Description = env.ReleaseDescription.bytes.encodeBase64().toString() - bat "powershell -ExecutionPolicy Bypass -File \"${jobDir}\\Tools\\publish_to_github.ps1\" -Owner \"mRemoteNG\" -Repository \"mRemoteNG\" -ReleaseTitle \"${env.ReleaseTitle}\" -TagName \"${env.TagName}\" -TargetCommitish \"${env.TargetBranch}\" -Description \"${base64Description}\" -IsDraft ${env.IsDraft} -IsPrerelease ${env.IsPreRelease} -ZipFilePath \"${zipPath}\" -MsiFilePath \"${msiPath}\" -AuthToken \"${env.GH_AUTH_TOKEN}\" -DescriptionIsBase64Encoded" + bat "powershell -ExecutionPolicy Bypass -File \"${jobDir}\\Tools\\publish_to_github.ps1\" -Owner \"mRemoteNG\" -Repository \"mRemoteNG\" -ReleaseTitle \"${env.ReleaseTitle}\" -TagName \"${env.TagName}\" -TargetCommitish \"${env.TargetBranch}\" -Description \"${base64Description}\" -IsDraft ${env.IsDraft} -IsPrerelease ${env.IsPreRelease} -ReleaseFolderPath \"${releaseFolder}\" -AuthToken \"${env.GH_AUTH_TOKEN}\" -DescriptionIsBase64Encoded" } } } \ No newline at end of file diff --git a/Tools/github_functions.ps1 b/Tools/github_functions.ps1 index db17cb0ae..f4b3881a3 100644 --- a/Tools/github_functions.ps1 +++ b/Tools/github_functions.ps1 @@ -171,17 +171,26 @@ function Upload-GitHubReleaseAsset { [string] [Parameter(Mandatory=$true)] # The OAuth2 token to use for authentication. - $AuthToken + $AuthToken, + + [string] + # A short description label for the asset + $Label = "" ) $UploadUri = $UploadUri -replace "(\{[\w,\?]*\})$" $files = Get-Item -Path $FilePath + $labelParam = "" + if ($Label -ne "") { + $labelParam = "&label=$Label" + } + # Get-Item could produce an array of files if a wildcard is provided. (C:\*.txt) # Upload each matching item individually foreach ($file in $files) { Write-Output "Uploading asset to GitHub release: '$($file.FullName)'" - $req_uploadZipAsset = Invoke-WebRequest -Uri "$($UploadUri)?name=$($file.Name)" -Method Post -Headers @{"Authorization"="token $AuthToken"} -ContentType $ContentType -InFile $file.FullName -ErrorAction Stop + $req_uploadZipAsset = Invoke-WebRequest -Uri "$($UploadUri)?name=$($file.Name)$labelParam" -Method Post -Headers @{"Authorization"="token $AuthToken"} -ContentType $ContentType -InFile $file.FullName -ErrorAction Stop } } diff --git a/Tools/publish_to_github.ps1 b/Tools/publish_to_github.ps1 index 4f920a0d8..a50a67eee 100644 --- a/Tools/publish_to_github.ps1 +++ b/Tools/publish_to_github.ps1 @@ -43,13 +43,8 @@ param ( [string] [Parameter(Mandatory=$true)] - # Path to the zip file to upload with the release - $ZipFilePath, - - [string] - [Parameter(Mandatory=$true)] - #Path to the msi file to upload with the release - $MsiFilePath, + # Path to the folder which contains release assets to upload + $ReleaseFolderPath, [string] [Parameter(Mandatory=$true)] @@ -70,7 +65,17 @@ if ($DescriptionIsBase64Encoded) { . "$PSScriptRoot\github_functions.ps1" +$releaseFolderItems = Get-ChildItem -Path $ReleaseFolderPath +$mrngPortablePath = ($releaseFolderItems | ?{$_.Name -match "portable-[\d\.]+\.zip"}).FullName +$mrngNormalPath = ($releaseFolderItems | ?{$_.Name -match "installer-[\d\.]+\.msi"}).FullName +$mrngPortableSymbolsPath = ($releaseFolderItems | ?{$_.Name -match "portable-symbols-[\d\.]+\.zip"}).FullName +$mrngNormalSymbolsPath = ($releaseFolderItems | ?{$_.Name -match "installer-symbols-[\d\.]+\.msi"}).FullName + + $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 +$zipUpload = Upload-GitHubReleaseAsset -UploadUri $release.upload_url -FilePath $mrngPortablePath -ContentType "application/zip" -AuthToken $AuthToken -Label "portable-edition" +$msiUpload = Upload-GitHubReleaseAsset -UploadUri $release.upload_url -FilePath $mrngNormalPath -ContentType "application/octet-stream" -AuthToken $AuthToken -Label "normal-edition" + +$portableEditionSymbols = Upload-GitHubReleaseAsset -UploadUri $release.upload_url -FilePath $mrngPortableSymbolsPath -ContentType "application/zip" -AuthToken $AuthToken -Label "portable-symbols" +$normalEditionSymbols = Upload-GitHubReleaseAsset -UploadUri $release.upload_url -FilePath $mrngNormalSymbolsPath -ContentType "application/zip" -AuthToken $AuthToken -Label "normal-symbols" Write-Output (Get-GitHubRelease -Owner $Owner -Repository $Repository -ReleaseId $release.id -AuthToken $AuthToken) \ No newline at end of file From cc872cd2b44f44169fcc33187c00e6b3d7b10458 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sat, 25 Aug 2018 17:03:28 -0500 Subject: [PATCH 2/2] fixed powershell script --- Tools/publish_to_github.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/publish_to_github.ps1 b/Tools/publish_to_github.ps1 index a50a67eee..ee2df9dfe 100644 --- a/Tools/publish_to_github.ps1 +++ b/Tools/publish_to_github.ps1 @@ -68,8 +68,8 @@ if ($DescriptionIsBase64Encoded) { $releaseFolderItems = Get-ChildItem -Path $ReleaseFolderPath $mrngPortablePath = ($releaseFolderItems | ?{$_.Name -match "portable-[\d\.]+\.zip"}).FullName $mrngNormalPath = ($releaseFolderItems | ?{$_.Name -match "installer-[\d\.]+\.msi"}).FullName -$mrngPortableSymbolsPath = ($releaseFolderItems | ?{$_.Name -match "portable-symbols-[\d\.]+\.zip"}).FullName -$mrngNormalSymbolsPath = ($releaseFolderItems | ?{$_.Name -match "installer-symbols-[\d\.]+\.msi"}).FullName +$mrngPortableSymbolsPath = ($releaseFolderItems | ?{$_.Name -match "mremoteng-portable-symbols-[\d\.]+\.zip"}).FullName +$mrngNormalSymbolsPath = ($releaseFolderItems | ?{$_.Name -match "mremoteng-symbols-[\d\.]+\.zip"}).FullName $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