@@ -462,12 +462,15 @@ NuSpecDependency[] ResolveDependenciesForPackage(string id) {
462462
463463// CI related environment
464464// * dev / beta / master versioning and publishing
465- var ciBranch = GetGlobalEnvironmentVariable ( "ci.activebranch" ) ?? "dev " ;
465+ var ciBranch = GetGlobalEnvironmentVariable ( "ci.activebranch" ) ?? "local " ;
466466
467467// override under CI run
468468var ciBranchOverride = GetGlobalEnvironmentVariable ( "APPVEYOR_REPO_BRANCH" ) ;
469469if ( ! String . IsNullOrEmpty ( ciBranchOverride ) )
470+ {
471+ Information ( String . Format ( "Detected APPVEYOR build. Reverting to APPVEYOR_REPO_BRANCH varibale:[{0}]" , ciBranchOverride ) ) ;
470472 ciBranch = ciBranchOverride ;
473+ }
471474
472475var ciNuGetSource = GetGlobalEnvironmentVariable ( "ci.nuget.source" ) ?? String . Empty ;
473476var ciNuGetKey = GetGlobalEnvironmentVariable ( "ci.nuget.key" ) ?? String . Empty ;
@@ -601,22 +604,49 @@ var defaultActionAPINuGetPackaging =Task("Action-API-NuGet-Packaging")
601604 }
602605} ) ;
603606
607+ bool ShouldPublishAPINuGet ( string branch ) {
608+
609+ // always publish dev branch
610+ // the rest comes from 'ciNuGetShouldPublish' -> 'ci.nuget.shouldpublish' environment variable
611+ if ( branch == "dev" )
612+ return true ;
613+
614+ return ciNuGetShouldPublish ;
615+ }
616+
604617var defaultActionAPINuGetPublishing = Task ( "Action-API-NuGet-Publishing" )
605618 // all packaged should be compiled by NuGet-Packaging task into 'defaultNuGetPackagesDirectory' folder
606619 . Does ( ( ) =>
607620{
608- if ( ! ciNuGetShouldPublish ) {
609- Information ( "Skipping NuGet publishing as ciNuGetShouldPublish is false." ) ;
621+ Information ( String . Format ( "API NuGet publishing enabled? branch:[{0}]" , ciBranch ) ) ;
622+ var shouldPublish = ShouldPublishAPINuGet ( ciBranch ) ;
623+
624+ var nugetSource = String . Empty ;
625+ var nugetKey = String . Empty ;
626+
627+ if ( ! shouldPublish ) {
628+ Information ( "Skipping NuGet publishing." ) ;
610629 return ;
630+ } else {
631+ Information ( "Fetching NuGet feed creds." ) ;
632+
633+ var feedSourceVariableName = String . Format ( "ci.nuget.{0}-source" , ciBranch ) ;
634+ var feedKeyVariableName = String . Format ( "ci.nuget.{0}-key" , ciBranch ) ;
635+
636+ var feedSourceValue = GetGlobalEnvironmentVariable ( feedSourceVariableName ) ;
637+ var feedKeyValue = GetGlobalEnvironmentVariable ( feedKeyVariableName ) ;
638+
639+ if ( String . IsNullOrEmpty ( feedSourceValue ) )
640+ throw new Exception ( String . Format ( "environment variable is null or empty:[{0}]" , feedSourceVariableName ) ) ;
641+
642+ if ( String . IsNullOrEmpty ( feedKeyValue ) )
643+ throw new Exception ( String . Format ( "environment variable is null or empty:[{0}]" , feedKeyVariableName ) ) ;
611644 }
612645
613646 Information ( "Publishing NuGet packages to repository: [{0}]" , new [ ] {
614- ciNuGetSource
647+ nugetSource
615648 } ) ;
616649
617- var nugetSource = ciNuGetSource ;
618- var nugetKey = ciNuGetKey ;
619-
620650 var nuGetPackages = System . IO . Directory . GetFiles ( defaultNuGetPackagesDirectory , "*.nupkg" ) ;
621651
622652 foreach ( var packageFilePath in nuGetPackages )
@@ -968,4 +998,8 @@ var taskDefaultCI = Task("Default-CI")
968998 . IsDependentOn ( "Action-API-NuGet-Packaging" )
969999 . IsDependentOn ( "Action-CLI-Zip-Packaging" )
9701000 . IsDependentOn ( "Action-CLI-Chocolatey-Packaging" )
1001+ // always 'push'
1002+ // the action checks if the current branch has to be published (dev always, the rest goes via 'ci.nuget.shouldpublish')
1003+ . IsDependentOn ( "Action-API-NuGet-Publishing" )
1004+
9711005 . IsDependentOn ( "Action-Docs-Merge" ) ;
0 commit comments