Skip to content

Commit

Permalink
chore: Release script draft (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda committed Nov 10, 2021
1 parent 3d0a8a9 commit 55234bf
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -15,7 +15,6 @@
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

Expand Down
12 changes: 12 additions & 0 deletions .versionrc
@@ -0,0 +1,12 @@
{
"types": [
{"type": "feat", "section": "**New Features and Enhancements:**", "hidden": false},
{"type": "fix", "section": "**Bug Fixes:**", "hidden": false},
{"type": "chore", "hidden": true},
{"type": "docs", "hidden": true},
{"type": "style", "hidden": true},
{"type": "refactor", "hidden": true},
{"type": "test", "hidden": true},
{"type": "ci", "hidden":true}
]
}
4 changes: 2 additions & 2 deletions Box.V2/Box.V2.csproj
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -310,4 +310,4 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 4.0.0 [2021-11-02]

**Breaking changes:**
Expand Down
93 changes: 93 additions & 0 deletions build/bump_version.ps1
@@ -0,0 +1,93 @@
Param
(
[Alias('dr')]
[bool]$DryRun = $true,

[Parameter(Mandatory)]
[Alias('gh')]
[string]$GithubToken,

[Alias('b')]
[string]$Branch="main"
)

$ErrorActionPreference = "Stop"

$ROOT_DIR=$pwd
$GIT_SCRIPT="$PSScriptRoot" + "\ensure_git_clean.ps1"
$CHANGELOG_PATH="$ROOT_DIR" + "\CHANGELOG.md"
$FRAMEWORK_PROJ_DIR="$ROOT_DIR" + "\Box.V2"
$CORE_PROJ_DIR="$ROOT_DIR" + "\Box.V2.Core"
$CORE_CSPROJ_PATH="$CORE_PROJ_DIR" + "\Box.V2.Core.csproj"
$ASSEMBLYINFO_PATH="$FRAMEWORK_PROJ_DIR" + "\Utility\AssemblyInfo.cs"
$FRAMEWORK_NUSPEC_PATH="$FRAMEWORK_PROJ_DIR" + "\Box.V2.nuspec"
$REPO_OWNER="box"
$REPO_NAME="box-windows-sdk-v2"

###########################################################################
# Install dependencies
###########################################################################

npm install -g standard-version
Install-Module -Name PowerShellForGitHub

###########################################################################
# Ensure git tree is clean
###########################################################################

Invoke-Expression "& `"$GIT_SCRIPT`" -b $Branch"
if ($LASTEXITCODE -ne 0) {
exit 1
}

###########################################################################
# Update changelog
###########################################################################

standard-version release --skip.commit --skip.tag
$NEXT_VERSION = (Select-String -Pattern [0-9]+\.[0-9]+\.[0-9]+ -Path $CHANGELOG_PATH | Select-Object -First 1).Matches.Value
$NEXT_VERSION_TAG = "v" + "$NEXT_VERSION"
$RELEASE_DATE = (Select-String -Pattern "\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])" -Path $CHANGELOG_PATH | Select-Object -First 1).Matches.Value
$RELEASE_NOTE_LINK = $NEXT_VERSION.Replace(".", "") + "-" + "$RELEASE_DATE"

###########################################################################
# Bump version files
###########################################################################

(Get-Content $CORE_CSPROJ_PATH) -replace '(?<=<Version>).*(?=</Version>)', $NEXT_VERSION | Set-Content $CORE_CSPROJ_PATH
(Get-Content $CORE_CSPROJ_PATH) -replace '(?<=CHANGELOG\.md#).*(?=</PackageReleaseNotes>)', $RELEASE_NOTE_LINK | Set-Content $CORE_CSPROJ_PATH
(Get-Content $FRAMEWORK_NUSPEC_PATH) -replace '(?<=<version>).*(?=</version>)', $NEXT_VERSION | Set-Content $FRAMEWORK_NUSPEC_PATH
(Get-Content $FRAMEWORK_NUSPEC_PATH) -replace '(?<=CHANGELOG\.md#).*(?=</releaseNotes>)', $RELEASE_NOTE_LINK | Set-Content $FRAMEWORK_NUSPEC_PATH
(Get-Content $ASSEMBLYINFO_PATH) -replace '(?<=NuGetVersion = ").*(?=";)', $NEXT_VERSION | Set-Content $ASSEMBLYINFO_PATH

###########################################################################
# Create PR with version bump
###########################################################################

if($DryRun){
Write-Output "Dry run. PR with version bump will not be created."
}else{
git branch -D $NEXT_VERSION_TAG
git checkout -b $NEXT_VERSION_TAG
git commit -am $NEXT_VERSION_TAG
git push --set-upstream origin $NEXT_VERSION_TAG

$password = ConvertTo-SecureString "$GithubToken" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("Release_Bot", $password)
Set-GitHubAuthentication -SessionOnly -Credential $Cred

$prParams = @{
OwnerName = $REPO_OWNER
RepositoryName = $REPO_NAME
Title = "chore: " + $NEXT_VERSION_TAG
Head = $NEXT_VERSION_TAG
Base = 'main'
Body = "Bumping version files for the next release! " + $NEXT_VERSION_TAG
MaintainerCanModify = $true
}
New-GitHubPullRequest @prParams

Clear-GitHubAuthentication
}

exit 0
30 changes: 30 additions & 0 deletions build/ensure_git_clean.ps1
@@ -0,0 +1,30 @@
Param
(
[Alias('b')]
[string]$ReleaseBranch="main"
)

$ErrorActionPreference = "Stop"

git remote update
$currentBranch = ''
git branch | ForEach-Object {
if ($_ -match "^\* (.*)") {
$currentBranch += $matches[1]
}
}
if(!($currentBranch -eq $ReleaseBranch)){
Write-Output "Local branch is not the same as the release branch " + $ReleaseBranch + ". Aborting script"
exit 1
}
$NumberOfDifferentCommits = git rev-list HEAD...origin/main --count
if(!($NumberOfDifferentCommits -eq "0")){
Write-Output "Different commits local and on remote. Aborting script"
exit 1
}
if (git status --porcelain) {
Write-Output "There are local changes that are not present on the remote. Aborting script."
exit 1
}

exit 0
52 changes: 52 additions & 0 deletions build/publish_core_package.ps1
@@ -0,0 +1,52 @@
Param
(
[Alias('dr')]
[bool]$DryRun = $true,

[Parameter(Mandatory)]
[Alias('ng')]
[string]$NugetKey,

[Parameter(Mandatory)]
[Alias('nv')]
[string]$NextVersion,

[Alias('b')]
[string]$Branch="main"
)

$ErrorActionPreference = "Stop"

$ROOT_DIR=$pwd
$GIT_SCRIPT="$PSScriptRoot" + "\ensure_git_clean.ps1"
$CORE_PROJ_DIR="$ROOT_DIR" + "\Box.V2.Core"
$CORE_ASSEMBLY_NAME="Box.V2.Core"
$NUGET_URL="https://api.nuget.org/v3/index.json"
$CORE_NUPKG_PATH="$CORE_PROJ_DIR" + "\bin\Release\" + "$CORE_ASSEMBLY_NAME" + "." + "$NextVersion" + ".nupkg"

###########################################################################
# Ensure git tree is clean
###########################################################################

Invoke-Expression "& `"$GIT_SCRIPT`" -b $Branch"
if ($LASTEXITCODE -ne 0) {
exit 1
}

###########################################################################
# Pack Core
###########################################################################

dotnet pack $CORE_PROJ_DIR -c Release

###########################################################################
# Publish Core to the Nuget
###########################################################################

if ($DryRun) {
Write-Output "Dry run. Package will not be published"
}else{
dotnet nuget push $CORE_NUPKG_PATH -k $NugetKey -s $NUGET_URL
}

exit 0
52 changes: 52 additions & 0 deletions build/publish_framework_package.ps1
@@ -0,0 +1,52 @@
Param
(
[Alias('dr')]
[bool]$DryRun = $true,

[Parameter(Mandatory)]
[Alias('ng')]
[string]$NugetKey,

[Parameter(Mandatory)]
[Alias('nv')]
[string]$NextVersion,

[Alias('b')]
[string]$Branch="main"
)

$ErrorActionPreference = "Stop"

$ROOT_DIR=$pwd
$GIT_SCRIPT="$PSScriptRoot" + "\ensure_git_clean.ps1"
$FRAMEWORK_PROJ_DIR="$ROOT_DIR" + "\Box.V2"
$FRAMEWORK_ASSEMBLY_NAME="Box.V2"
$NUGET_URL="https://api.nuget.org/v3/index.json"
$FRAMEWORK_NUPKG_PATH="$FRAMEWORK_PROJ_DIR" + "\bin\Release\" + "$FRAMEWORK_ASSEMBLY_NAME" + "." + "$NextVersion" + ".nupkg"

###########################################################################
# Ensure git tree is clean
###########################################################################

Invoke-Expression "& `"$GIT_SCRIPT`" -b $Branch"
if ($LASTEXITCODE -ne 0) {
exit 1
}

###########################################################################
# Pack Framework
###########################################################################



###########################################################################
# Publish Framework to the Nuget
###########################################################################

if ($DryRun) {
Write-Output "Running in Dry Run mode. Package will not be published"
}else{
dotnet nuget push $FRAMEWORK_NUPKG_PATH -k $NugetKey -s $NUGET_URL
}

exit 0
63 changes: 63 additions & 0 deletions build/release.ps1
@@ -0,0 +1,63 @@
Param
(
[Alias('dr')]
[bool]$DryRun = $true,

[Parameter(Mandatory)]
[Alias('gh')]
[string]$GithubToken,

[Parameter(Mandatory)]
[Alias('nv')]
[string]$NextVersion,

[Alias('rs')]
[string]$ReleaseNotes="Release notes"
)

$ErrorActionPreference = "Stop"

$ROOT_DIR=$pwd
$FRAMEWORK_PROJ_DIR="$ROOT_DIR" + "\Box.V2"
$CORE_PROJ_DIR="$ROOT_DIR" + "\Box.V2.Core"
$REPO_OWNER="box"
$REPO_NAME="box-windows-sdk-v2"
$FRAMEWORK_NUPKG_PATH=$FRAMEWORK_PROJ_DIR + "\Box.V2." + $NextVersion + ".nupkg"
$FRAMEWORK_PDB_PATH=$FRAMEWORK_PROJ_DIR + "\bin\Release\Box.V2.pdb"
$CORE_NUPKG_PATH=$CORE_PROJ_DIR + "\bin\Release\Box.V2.Core." + $NextVersion + ".nupkg"
$CORE_PDB_PATH=$CORE_PROJ_DIR + "\bin\Release\netstandard2.0\Box.V2.Core.pdb"

###########################################################################
# Install dependencies
###########################################################################

Install-Module -Name PowerShellForGitHub

###########################################################################
# Create git release
###########################################################################

if($DryRun){
Write-Output "Dry run. Release will not be created."
}else{
$password = ConvertTo-SecureString "$GithubToken" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("Release_Bot", $password)
Set-GitHubAuthentication -SessionOnly -Credential $Cred
$releaseParams = @{
OwnerName = $REPO_OWNER
RepositoryName = $REPO_NAME
Tag = "v" + $NextVersion
Name = "v" + $NextVersion
Body = $ReleaseNotes
}
$release = New-GitHubRelease @releaseParams

$release | New-GitHubReleaseAsset -Path $FRAMEWORK_NUPKG_PATH
$release | New-GitHubReleaseAsset -Path $FRAMEWORK_PDB_PATH
$release | New-GitHubReleaseAsset -Path $CORE_NUPKG_PATH
$release | New-GitHubReleaseAsset -Path $CORE_PDB_PATH

Clear-GitHubAuthentication
}

exit 0

0 comments on commit 55234bf

Please sign in to comment.