From 8815235ab325fb9792bd484c858921335a3aa4fd Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Thu, 13 Jan 2022 23:00:08 +0300 Subject: [PATCH] add GitHub release step to deploy pipeline. closes #11313 --- ...hub-release__NOT_ACTIVE_USE_MANUAL_WAY.ps1 | 35 -------- deploy/7-publish-github-release.ps1 | 86 +++++++++++++++++++ deploy/_run_all.ps1 | 40 ++++++++- nupkg/common.ps1 | 18 ++++ 4 files changed, 142 insertions(+), 37 deletions(-) delete mode 100644 deploy/7-new-github-release__NOT_ACTIVE_USE_MANUAL_WAY.ps1 create mode 100644 deploy/7-publish-github-release.ps1 diff --git a/deploy/7-new-github-release__NOT_ACTIVE_USE_MANUAL_WAY.ps1 b/deploy/7-new-github-release__NOT_ACTIVE_USE_MANUAL_WAY.ps1 deleted file mode 100644 index 87ab47cbcc..0000000000 --- a/deploy/7-new-github-release__NOT_ACTIVE_USE_MANUAL_WAY.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -#THIS IS NOT BEING USED CURRENTLY. RELEASE GITHUB MANUALLY - -# Import the module dynamically from the PowerShell Gallery. Use CurrentUser scope to avoid having to run as admin. -Import-Module -Name new-github-release-function.psm1 - -# Specify the parameters required to create the release. Do it as a hash table for easier readability. -$newGitHubReleaseParameters = -@{ - GitHubUsername = 'abpframework' - GitHubRepositoryName = 'abp' - GitHubAccessToken = '*******************' - ReleaseName = "5.0.0-rc.2" - TagName = "5.0.0-rc.2" - ReleaseNotes = "N/A" - #AssetFilePaths = @('C:\MyProject\Installer.exe','C:\MyProject\Documentation.md') - IsPreRelease = $true - IsDraft = $true # Set to true when testing so we don't publish a real release (visible to everyone) by accident. -} - -# Try to create the Release on GitHub and save the results. -$result = New-GitHubRelease @newGitHubReleaseParameters - -# Provide some feedback to the user based on the results. -if ($result.Succeeded -eq $true) -{ - Write-Output "Release published successfully! View it at $($result.ReleaseUrl)" -} -elseif ($result.ReleaseCreationSucceeded -eq $false) -{ - Write-Error "The release was not created. Error message is: $($result.ErrorMessage)" -} -elseif ($result.AllAssetUploadsSucceeded -eq $false) -{ - Write-Error "The release was created, but not all of the assets were uploaded to it. View it at $($result.ReleaseUrl). Error message is: $($result.ErrorMessage)" -} diff --git a/deploy/7-publish-github-release.ps1 b/deploy/7-publish-github-release.ps1 new file mode 100644 index 0000000000..9512af0d43 --- /dev/null +++ b/deploy/7-publish-github-release.ps1 @@ -0,0 +1,86 @@ +param( + [string]$branchName, + [string]$version, + [string]$isRcVersion, + [string]$isDraft, + [string]$gitHubApiKey +) + +. ..\nupkg\common.ps1 + +Write-Info "Publishing GitHub Release..." ## Further info see https://docs.github.com/en/rest/reference/releases + +if ($isRcVersion -eq "") +{ + $isRcVersion = Read-Host "Is this a RC/Preview version? (y/n)" +} + +if ($gitHubApiKey -eq "") +{ + $gitHubApiKey = Read-File "github-api-key.txt" + echo "GitHub API Key assigned from github-api-key.txt" +} + +if(!$gitHubApiKey) +{ + $gitHubApiKey = Read-Host "Enter the GitHub API Key" +} + +if ($version -eq "") +{ + $version = Get-Current-Version # The version number for this release +} + +if ($branchName -eq "") +{ + $branchName = Get-Current-Branch # The branch name also the tag name +} + +if ($isDraft -eq "") +{ + $draft = $FALSE +} +else +{ + $draft = [boolean]::Parse($isDraft) +} + +############################################################################## +$preRelease = ( ($isRcVersion -eq "true") -or ($isRcVersion -eq "y") -or ($isRcVersion -eq "rc") ) # Set to true to mark this as a pre-release version +$gitHubUsername = 'abpframework' # The github username +$gitHubRepository = 'abp' # The github repository name +$releaseNotes = '' # The notes to accompany this release, uses the commit message in this case +############################################################################## + +echo "Current version: $version" +echo "Current branch: $branchName" +echo "Preview version: $preRelease" +echo "Draft: $draft" + +############################################################################## + +$releaseData = @{ + tag_name = $version; + target_commitish = $branchName; + name = $version; + body = $releaseNotes; + draft = $draft; + prerelease = $preRelease; + } + +$releaseParams = @{ + Uri = "https://api.github.com/repos/$gitHubUsername/$gitHubRepository/releases"; + Method = 'POST'; + Headers = @{ + Authorization = 'Basic ' + [Convert]::ToBase64String( + [Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic")); + } + ContentType = 'application/json'; + Body = (ConvertTo-Json $releaseData -Compress) + } + +$response = Invoke-RestMethod @releaseParams + +echo "---------------------------------------------" +echo "$version has been successfully released." + diff --git a/deploy/_run_all.ps1 b/deploy/_run_all.ps1 index fa2596925e..9c43035a41 100644 --- a/deploy/_run_all.ps1 +++ b/deploy/_run_all.ps1 @@ -1,7 +1,43 @@ -./1-fetch-and-build.ps1 +param( + [string]$branch, + [string]$newVersion, + [string]$isRcVersion +) + +. ..\nupkg\common.ps1 + +if (!$branch) +{ + $branch = Read-Host "Enter the branch name" +} + +if (!$newVersion) +{ + $currentVersion = Get-Current-Version + $newVersion = Read-Host "Current version is '$currentVersion'. Enter the new version (empty for no change) " + if($newVersion -eq "") + { + $newVersion = $currentVersion + } +} + +if ($isRcVersion -eq "") +{ + $isRcVersion = Read-Host "Is this a RC/Preview version? (y/n)" +} + +$publishGithubReleaseParams = @{ + branchName=$branch + isRcVersion=$isRcVersion +} + + +./1-fetch-and-build.ps1 $branch $newVersion ./2-nuget-pack.ps1 ./3-nuget-push.ps1 ./4-npm-publish-mvc.ps1 ./5-npm-publish-angular.ps1 ./6-git-commit.ps1 -echo "Create a new release on GitHub manually and run the step 8..." \ No newline at end of file +./7-publish-github-release.ps1 @publishGithubReleaseParams +./8-download-release-zip.ps1 + diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index fbcbae15dd..2ba7e15a16 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -38,6 +38,24 @@ function Seperator Write-Host ("_" * 100) -ForegroundColor gray } + +function Read-File { + param( + [Parameter(Mandatory = $true)] + [string] + $filePath + ) + + $pathExists = Test-Path -Path $filePath -PathType Leaf + if ($pathExists) + { + return Get-Content $filePath + } + else{ + Write-Error "$filePath path does not exist!" + } +} + # List of solutions $solutions = ( "framework",