Skip to content

Commit

Permalink
chore: Release script (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda authored Nov 22, 2021
1 parent 55234bf commit 83477cd
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 50 deletions.
2 changes: 2 additions & 0 deletions Box.V2/Box.V2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<DefineConstants>TRACE;RELEASE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>BoxSDKKey.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.9.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
Expand Down
41 changes: 24 additions & 17 deletions build/bump_version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,40 @@ Param
[Alias('dr')]
[bool]$DryRun = $true,

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

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

[Alias('id')]
[bool]$InstallDependencies = $true
)

$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"
. $PSScriptRoot\variables.ps1

###########################################################################
# Parameters validation
###########################################################################

if($GithubToken -eq $null -Or $GithubToken -eq ''){
$GithubToken = $env:GithubToken
if($GithubToken -eq $null -Or $GithubToken -eq ''){
Write-Output "Github token not supplied. Aborting script."
exit 1
}
}

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

npm install -g standard-version
Install-Module -Name PowerShellForGitHub
if ($InstallDependencies){
npm install -g standard-version
Install-Module -Name PowerShellForGitHub -Scope CurrentUser -Force
}

###########################################################################
# Ensure git tree is clean
Expand All @@ -44,7 +51,7 @@ if ($LASTEXITCODE -ne 0) {
# Update changelog
###########################################################################

standard-version release --skip.commit --skip.tag
standard-version --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
Expand Down Expand Up @@ -79,9 +86,9 @@ if($DryRun){
$prParams = @{
OwnerName = $REPO_OWNER
RepositoryName = $REPO_NAME
Title = "chore: " + $NEXT_VERSION_TAG
Title = "chore: release " + $NEXT_VERSION_TAG
Head = $NEXT_VERSION_TAG
Base = 'main'
Base = $Branch
Body = "Bumping version files for the next release! " + $NEXT_VERSION_TAG
MaintainerCanModify = $true
}
Expand Down
61 changes: 52 additions & 9 deletions build/publish_core_package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,44 @@ Param
[Alias('dr')]
[bool]$DryRun = $true,

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

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

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

[Alias('bt')]
[bool]$BuildAndTest = $true
)

$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"
. $PSScriptRoot\variables.ps1

if($NextVersion -eq $null -Or $NextVersion -eq ''){
$NextVersion = $env:NextVersion
if($NextVersion -eq $null -Or $NextVersion -eq ''){
$NextVersion = (Select-String -Pattern [0-9]+\.[0-9]+\.[0-9]+ -Path $CHANGELOG_PATH | Select-Object -First 1).Matches.Value
}
}

$CORE_NUPKG_PATH="$CORE_PROJ_DIR" + "\bin\Release\" + "$CORE_ASSEMBLY_NAME" + "." + "$NextVersion" + ".nupkg"

###########################################################################
# Parameters validation
###########################################################################

if($NugetKey -eq $null -Or $NugetKey -eq ''){
$NugetKey = $env:NugetKey
if($NugetKey -eq $null -Or $NugetKey -eq ''){
Write-Output "Nuget key not supplied. Aborting script."
exit 1
}
}

###########################################################################
# Ensure git tree is clean
###########################################################################
Expand All @@ -33,18 +50,44 @@ if ($LASTEXITCODE -ne 0) {
exit 1
}

###########################################################################
# Build and Test
###########################################################################

if($BuildAndTest){
dotnet build $CORE_PROJ_DIR
if ($LASTEXITCODE -ne 0) {
Write-Output "Compilation failed. Aborting script."
exit 1
}
dotnet test -f $NET_CORE_VER
if ($LASTEXITCODE -ne 0) {
Write-Output "Some of the unit test failed. Aborting script."
exit 1
}
dotnet clean $CORE_PROJ_DIR
if (test-path ("$CORE_PROJ_DIR" + "\bin")) { Remove-Item ("$CORE_PROJ_DIR" + "\bin") -r }
if (test-path ("$CORE_PROJ_DIR" + "\obj")) { Remove-Item ("$CORE_PROJ_DIR" + "\obj") -r }
}else{
Write-Output "Skipping build and test step."
}

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

dotnet pack $CORE_PROJ_DIR -c Release
if ($LASTEXITCODE -ne 0) {
Write-Output "Package creation failed. Aborting script."
exit 1
}

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

if ($DryRun) {
Write-Output "Dry run. Package will not be published"
Write-Output "Dry run. Package will not be published."
}else{
dotnet nuget push $CORE_NUPKG_PATH -k $NugetKey -s $NUGET_URL
}
Expand Down
112 changes: 102 additions & 10 deletions build/publish_framework_package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,68 @@ Param
[Alias('dr')]
[bool]$DryRun = $true,

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

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

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

[Alias('cf')]
[string]$PfxAsBase64,

[Alias('pw')]
[string]$PfxPassword,

[Alias('bt')]
[bool]$BuildAndTest = $true,

[Alias('id')]
[bool]$InstallDependencies = $true
)

$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"
. $PSScriptRoot\variables.ps1

if($NextVersion -eq $null -Or $NextVersion -eq ''){
$NextVersion = $env:NextVersion
if($NextVersion -eq $null -Or $NextVersion -eq ''){
$NextVersion = (Select-String -Pattern [0-9]+\.[0-9]+\.[0-9]+ -Path $CHANGELOG_PATH | Select-Object -First 1).Matches.Value
}
}

$FRAMEWORK_NUPKG_PATH="$ROOT_DIR" + "\" + "$FRAMEWORK_ASSEMBLY_NAME" + "." + "$NextVersion" + ".nupkg"

###########################################################################
# Parameters validation
###########################################################################

if($NugetKey -eq $null -Or $NugetKey -eq ''){
$NugetKey = $env:NugetKey
if($NugetKey -eq $null -Or $NugetKey -eq ''){
Write-Output "Nuget key not supplied. Aborting script."
exit 1
}
}

if($PfxAsBase64 -eq $null -Or $PfxAsBase64 -eq ''){
$PfxAsBase64 = $env:PfxAsBase64
if($PfxAsBase64 -eq $null -Or $PfxAsBase64 -eq ''){
Write-Output "Pfx certifcate as base64 not supplied. Aborting script."
exit 1
}
}

if($PfxPassword -eq $null -Or $PfxPassword -eq ''){
$PfxPassword = $env:PfxPassword
if($PfxPassword -eq $null -Or $PfxPassword -eq ''){
Write-Output "Pfx certificate password not supplied. Aborting script."
exit 1
}
}

###########################################################################
# Ensure git tree is clean
Expand All @@ -34,10 +76,54 @@ if ($LASTEXITCODE -ne 0) {
}

###########################################################################
# Pack Framework
# Install dependencies
###########################################################################

if ($InstallDependencies){
Invoke-WebRequest https://github.com/honzajscz/SnInstallPfx/releases/download/0.1.2-beta/SnInstallPfx.exe -SkipCertificateCheck -OutFile SnInstallPfx.exe
}

###########################################################################
# Setup Pfx
###########################################################################

$Bytes = [Convert]::FromBase64String($PfxAsBase64)
[IO.File]::WriteAllBytes($PFX_PATH, $Bytes)
.\SnInstallPfx.exe $PFX_PATH $PfxPassword
Remove-Item $PFX_PATH

###########################################################################
# Build and Test
###########################################################################

if($BuildAndTest){
msbuild $FRAMEWORK_PROJ_DIR /property:Configuration=Release
if ($LASTEXITCODE -ne 0) {
Write-Output "Compilation failed. Aborting script."
exit 1
}
dotnet test -f $NET_FRAMEWORK_VER --verbosity normal
if ($LASTEXITCODE -ne 0) {
Write-Output "Some of the unit test failed. Aborting script."
exit 1
}
dotnet clean $FRAMEWORK_PROJ_DIR
if (test-path ("$FRAMEWORK_PROJ_DIR" + "\bin")) { Remove-Item ("$FRAMEWORK_PROJ_DIR" + "\bin") -r }
if (test-path ("$FRAMEWORK_PROJ_DIR" + "\obj")) { Remove-Item ("$FRAMEWORK_PROJ_DIR" + "\obj") -r }
}else{
Write-Output "Skipping build and test step."
}

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

nuget restore $SLN_PATH
nuget pack $FRAMEWORK_PROJ_DIR -Build -Prop Configuration=Release
if ($LASTEXITCODE -ne 0) {
Write-Output "Package creation failed. Aborting script."
exit 1
}

###########################################################################
# Publish Framework to the Nuget
Expand All @@ -49,4 +135,10 @@ if ($DryRun) {
dotnet nuget push $FRAMEWORK_NUPKG_PATH -k $NugetKey -s $NUGET_URL
}

###########################################################################
# Clean all VS_KEY_* containers
###########################################################################

certutil -csp "Microsoft Strong Cryptographic Provider" -key | Select-String -Pattern "VS_KEY" | ForEach-Object{ $_.ToString().Trim()} | ForEach-Object{ certutil -delkey -csp "Microsoft Strong Cryptographic Provider" $_}

exit 0
Loading

0 comments on commit 83477cd

Please sign in to comment.