Skip to content

Commit 380033e

Browse files
committed
Addin integration test for authenticated GitHub Packages feed
1 parent 451b81f commit 380033e

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

tests/integration/Cake.NuGet/InProcessInstaller.cake

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,65 @@ Task("Cake.NuGet.InProcessInstaller.VersionPinRange.Wildcard")
133133
});
134134
});
135135

136+
Task("Cake.NuGet.InProcessInstaller.DotNetTool.AuthenticatedFeed")
137+
.IsDependentOn("Cake.NuGet.InProcessInstaller.Setup")
138+
.WithCriteria(() => BuildSystem.GitHubActions.IsRunningOnGitHubActions || Argument<string>("target", "Default") == "Cake.NuGet.InProcessInstaller.DotNetTool.AuthenticatedFeed")
139+
.Does(()=>
140+
{
141+
var scriptPath = Paths.Temp.Combine("./Cake.NuGet.InProcessInstaller/").CombineWithFilePath("build.cake");
142+
var scriptToolsPath = Paths.Temp.Combine("./Cake.NuGet.InProcessInstaller/tools");
143+
var nugetConfigPath = Paths.Temp.Combine("./Cake.NuGet.InProcessInstaller/").CombineWithFilePath("nuget.config");
144+
145+
// Create NuGet.config without credentials
146+
var githubToken = EnvironmentVariable("GITHUB_TOKEN");
147+
148+
var nugetConfig =
149+
"""
150+
<?xml version="1.0" encoding="utf-8"?>
151+
<configuration>
152+
<packageSources>
153+
<clear />
154+
<add key="github" value="https://nuget.pkg.github.com/devlead/index.json" />
155+
</packageSources>
156+
</configuration>
157+
""";
158+
System.IO.File.WriteAllText(nugetConfigPath.FullPath, nugetConfig);
159+
160+
// If githubToken is provided, update the source with credentials using DotNetNuGetUpdateSource
161+
if (!string.IsNullOrEmpty(githubToken))
162+
{
163+
var sourceSettings = new DotNetNuGetSourceSettings
164+
{
165+
Source = "https://nuget.pkg.github.com/devlead/index.json",
166+
UserName = GitHubActions.Environment.Workflow.RepositoryOwner,
167+
Password = githubToken,
168+
StorePasswordInClearText = true,
169+
ConfigFile = nugetConfigPath
170+
};
171+
DotNetNuGetUpdateSource("github", sourceSettings);
172+
}
173+
174+
var script = @"#addin nuget:https://nuget.pkg.github.com/devlead/index.json?package=litjson&version=0.19.0-alpha0044&prerelease
175+
var result = LitJson.JsonMapper.ToJson(new { Name = ""John"", Age = 30 });
176+
";
177+
178+
System.IO.File.WriteAllText(scriptPath.FullPath, script);
179+
180+
CakeExecuteScript(scriptPath,
181+
new CakeSettings
182+
{
183+
EnvironmentVariables = {
184+
{ "CAKE_PATHS_TOOLS", scriptToolsPath.FullPath },
185+
{ "CAKE_PATHS_ADDINS", scriptToolsPath.Combine("Addins").FullPath },
186+
{ "CAKE_PATHS_MODULES", scriptToolsPath.Combine("Modules").FullPath }
187+
}
188+
});
189+
});
190+
136191
Task("Cake.NuGet.InProcessInstaller")
137192
.IsDependentOn("Cake.NuGet.InProcessInstaller.Setup")
138193
.IsDependentOn("Cake.NuGet.InProcessInstaller.VersionPinExact")
139194
.IsDependentOn("Cake.NuGet.InProcessInstaller.VersionPinRange.InclusiveExclusive")
140195
.IsDependentOn("Cake.NuGet.InProcessInstaller.VersionPinRange.InclusiveInclusive")
141-
.IsDependentOn("Cake.NuGet.InProcessInstaller.VersionPinRange.Wildcard");
196+
.IsDependentOn("Cake.NuGet.InProcessInstaller.VersionPinRange.Wildcard")
197+
.IsDependentOn("Cake.NuGet.InProcessInstaller.DotNetTool.AuthenticatedFeed");

0 commit comments

Comments
 (0)