From 04742eab0d8c3b22513680cb44a0e5263722d388 Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Thu, 14 May 2020 15:34:00 -0500 Subject: [PATCH] Add deployment script to auto-publish prerelease packages --- ShopifySharp.sln | 1 + appveyor.yml | 2 ++ scripts/deploy.ps1 | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 scripts/deploy.ps1 diff --git a/ShopifySharp.sln b/ShopifySharp.sln index 87f9c37a..b943eb5b 100755 --- a/ShopifySharp.sln +++ b/ShopifySharp.sln @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution readme.md = readme.md scripts\build.ps1 = scripts\build.ps1 scripts\test.ps1 = scripts\test.ps1 + scripts\deploy.ps1 = scripts\deploy.ps1 EndProjectSection EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ShopifySharp.Experimental", "ShopifySharp.Experimental\ShopifySharp.Experimental.fsproj", "{DE7BB881-2191-489D-B9AA-F5F910EF55D8}" diff --git a/appveyor.yml b/appveyor.yml index bec72ec3..ba8a6361 100755 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,8 @@ environment: secure: Lt70HrGBrQwKIFWE13zFZRGGwRoPKi1VKjtqBzuR3rdz3w6zD1YXXXe/Zb7xaqX+ SHOPIFYSHARP_MY_SHOPIFY_URL: secure: aWjxVhXImxXX98GcYDmAbGVDxZk9kRaMKGnhm0CLuJ0aFYs0OMNaJOqyT8S4sh9P + NUGET_API_KEY: + secure: uUJ91Fu+H69EdZ8RTYIa7G7UufCgCw1UXfZ2jAOEWJfKi8KNwDTFYaEDQCJS9xOc build_script: - ps: ./scripts/build.ps1 test_script: diff --git a/scripts/deploy.ps1 b/scripts/deploy.ps1 new file mode 100644 index 00000000..cb9765ce --- /dev/null +++ b/scripts/deploy.ps1 @@ -0,0 +1,40 @@ +#! /bin/pwsh + +<# +.SYNOPSIS + This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode + to see if an error occcured. If an error is detected then an exception is thrown. + This function allows you to run command-line programs without having to + explicitly check the $lastexitcode variable. +.EXAMPLE + exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed" +.SOURCE + https://github.com/another-guy/Mirror/blob/9034cd0d6ee6ec072469f6c0f07bdb16b4b5764e/Build.ps1 +#> +function Exec +{ + [CmdletBinding()] + param( + [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, + [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd) + ) + & $cmd + if ($lastexitcode -ne 0) { + throw ("Exec: " + $errorMessage) + } +} + +write-host "============================ DEPLOYING PRERELEASE PACKAGES TO NUGET ===========================" +# Appveyor pushes a $artifacts variable which contains all artifacts pushed from the build script. +# Prerelease artifacts are named like "ShopifySharp.1.2.3.b456789.npukg" or "ShopifySharp.Experimental.1.2.3.b456789.nupkg" +# Only publish those prerelease packages, and require manualy publishing for full releases. +foreach ($artifactName in $artifacts.keys) { + $artifact = $artifacts[$artifactName] + $artifactPath = $artifact.path + + if ($artifactName -like "ShopifySharp.*.*.*.b*.nupkg" -or $artifactName -like "ShopifySharp.Experimental.*.*.*.b*.nupkg") { + # TODO: publish package to nuget using dotnet publish + exec { & dotnet nuget push -k "$env:NUGET_API_KEY" -s "https://nuget.org" "$artifactPath" } + write-host "Pushed $($_.Name) artifact." + } +}