Skip to content

Commit

Permalink
Add deployment script to auto-publish prerelease packages
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed May 14, 2020
1 parent 20fdd00 commit 04742ea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions ShopifySharp.sln
Expand Up @@ -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}"
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions 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."
}
}

0 comments on commit 04742ea

Please sign in to comment.