File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,7 @@ jobs:
169
169
fail-fast : false
170
170
env :
171
171
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
172
+ GITHUB_USERNAME : ${{ secrets.GITHUB_USERNAME }}
172
173
NUGET_API_KEY : ${{ secrets.NUGET_API_KEY }}
173
174
NUGET_API_URL : ${{ secrets.NUGET_API_URL }}
174
175
CHOCOLATEY_API_KEY : ${{ secrets.CHOCOLATEY_API_KEY }}
Original file line number Diff line number Diff line change @@ -99,12 +99,39 @@ Task("Publish-NuGet-Internal")
99
99
{
100
100
if ( FileExists ( package . PackagePath ) )
101
101
{
102
- // Push the package.
103
- DotNetCoreNuGetPush ( package . PackagePath . FullPath , new DotNetCoreNuGetPushSettings
102
+ // Push the package to nuget.org
103
+ NuGetPush ( package . PackagePath , new NuGetPushSettings
104
104
{
105
105
ApiKey = apiKey ,
106
106
Source = apiUrl
107
107
} ) ;
108
+
109
+ // Push the package to GitHub Packages
110
+ if ( parameters . IsRunningOnGitHubActions ) {
111
+ var token = parameters . Credentials . GitHub . Token ;
112
+ if ( string . IsNullOrEmpty ( token ) ) {
113
+ throw new InvalidOperationException ( "Could not resolve Github token." ) ;
114
+ }
115
+ var userName = parameters . Credentials . GitHub . UserName ;
116
+ if ( string . IsNullOrEmpty ( userName ) ) {
117
+ throw new InvalidOperationException ( "Could not resolve Github userName." ) ;
118
+ }
119
+
120
+ var source = $ "https://nuget.pkg.github.com/{ BuildParameters . MainRepoOwner } /index.json";
121
+
122
+ var nugetSourceSettings = new NuGetSourcesSettings
123
+ {
124
+ UserName = parameters . Credentials . GitHub . UserName ,
125
+ Password = token
126
+ } ;
127
+
128
+ Information ( "Adding NuGet source with user/pass..." ) ;
129
+ NuGetAddSource ( "GitHub" , source , nugetSourceSettings ) ;
130
+ NuGetPush ( package . PackagePath , new NuGetPushSettings
131
+ {
132
+ Source = source
133
+ } ) ;
134
+ }
108
135
}
109
136
}
110
137
} )
Original file line number Diff line number Diff line change @@ -27,16 +27,19 @@ public class BuildCredentials
27
27
28
28
public class GitHubCredentials
29
29
{
30
+ public string UserName { get ; private set ; }
30
31
public string Token { get ; private set ; }
31
32
32
- public GitHubCredentials ( string token )
33
+ public GitHubCredentials ( string userName , string token )
33
34
{
34
35
Token = token ;
35
36
}
36
37
37
38
public static GitHubCredentials GetGitHubCredentials ( ICakeContext context )
38
39
{
39
- return new GitHubCredentials ( context . EnvironmentVariable ( "GITHUB_TOKEN" ) ) ;
40
+ return new GitHubCredentials (
41
+ context . EnvironmentVariable ( "GITHUB_USERNAME" ) ,
42
+ context . EnvironmentVariable ( "GITHUB_TOKEN" ) ) ;
40
43
}
41
44
}
42
45
You can’t perform that action at this time.
0 commit comments