Skip to content

Commit 7326504

Browse files
authored
Merge pull request #4540 from devlead/feature/gh-4539
GH4539: Add Woodpecker CI Support
2 parents 7f89aaf + 188ee18 commit 7326504

29 files changed

+3223
-79
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Cake.Common.Build.WoodpeckerCI.Commands;
6+
using Cake.Common.Build.WoodpeckerCI.Data;
7+
using Cake.Core;
8+
using Cake.Core.IO;
9+
using Cake.Testing;
10+
11+
namespace Cake.Common.Tests.Fixtures.Build
12+
{
13+
internal sealed class WoodpeckerCICommandsFixture
14+
{
15+
public ICakeEnvironment Environment { get; set; }
16+
public IFileSystem FileSystem { get; set; }
17+
public WoodpeckerCIEnvironmentInfo WoodpeckerEnvironment { get; set; }
18+
19+
public WoodpeckerCICommandsFixture()
20+
{
21+
Environment = FakeEnvironment.CreateUnixEnvironment();
22+
FileSystem = new FakeFileSystem(Environment);
23+
24+
// Set up the WoodpeckerCI environment variables
25+
((FakeEnvironment)Environment).SetEnvironmentVariable("CI", "woodpecker");
26+
((FakeEnvironment)Environment).SetEnvironmentVariable("CI_WORKSPACE", "/woodpecker/src/git.example.com/john-doe/my-repo");
27+
28+
WoodpeckerEnvironment = new WoodpeckerCIEnvironmentInfo(Environment);
29+
30+
// Create the .woodpecker/env file for testing
31+
var envFile = WoodpeckerEnvironment.Workspace?.CombineWithFilePath(".woodpecker/env");
32+
if (envFile != null)
33+
{
34+
// Create the directory structure first
35+
var directory = envFile.GetDirectory();
36+
((FakeFileSystem)FileSystem).CreateDirectory(directory);
37+
((FakeFileSystem)FileSystem).CreateFile(envFile);
38+
}
39+
}
40+
41+
public WoodpeckerCICommands CreateWoodpeckerCICommands()
42+
{
43+
return new WoodpeckerCICommands(Environment, FileSystem, WoodpeckerEnvironment);
44+
}
45+
46+
public WoodpeckerCICommandsFixture WithNoWoodpeckerEnv()
47+
{
48+
var envFile = Environment.WorkingDirectory.CombineWithFilePath(".woodpecker/env");
49+
if (FileSystem.Exist(envFile))
50+
{
51+
FileSystem.GetFile(envFile).Delete();
52+
}
53+
return this;
54+
}
55+
}
56+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Cake.Common.Build.WoodpeckerCI.Data;
6+
using Cake.Core;
7+
using NSubstitute;
8+
9+
namespace Cake.Common.Tests.Fixtures.Build
10+
{
11+
public class WoodpeckerCIInfoFixture
12+
{
13+
public ICakeEnvironment Environment { get; set; }
14+
15+
public WoodpeckerCIInfoFixture()
16+
{
17+
Environment = Substitute.For<ICakeEnvironment>();
18+
19+
// WoodpeckerCI Environment
20+
Environment.GetEnvironmentVariable("CI").Returns("woodpecker");
21+
Environment.GetEnvironmentVariable("CI_WORKSPACE").Returns("/woodpecker/src/git.example.com/john-doe/my-repo");
22+
23+
// WoodpeckerCI RepositoryInfo
24+
Environment.GetEnvironmentVariable("CI_REPO").Returns("john-doe/my-repo");
25+
Environment.GetEnvironmentVariable("CI_REPO_OWNER").Returns("john-doe");
26+
Environment.GetEnvironmentVariable("CI_REPO_NAME").Returns("my-repo");
27+
Environment.GetEnvironmentVariable("CI_REPO_REMOTE_ID").Returns("82");
28+
Environment.GetEnvironmentVariable("CI_REPO_URL").Returns("https://git.example.com/john-doe/my-repo");
29+
Environment.GetEnvironmentVariable("CI_REPO_CLONE_URL").Returns("https://git.example.com/john-doe/my-repo.git");
30+
Environment.GetEnvironmentVariable("CI_REPO_CLONE_SSH_URL").Returns("[email protected]:john-doe/my-repo.git");
31+
Environment.GetEnvironmentVariable("CI_REPO_DEFAULT_BRANCH").Returns("main");
32+
Environment.GetEnvironmentVariable("CI_REPO_PRIVATE").Returns("true");
33+
Environment.GetEnvironmentVariable("CI_REPO_TRUSTED_NETWORK").Returns("false");
34+
Environment.GetEnvironmentVariable("CI_REPO_TRUSTED_VOLUMES").Returns("false");
35+
Environment.GetEnvironmentVariable("CI_REPO_TRUSTED_SECURITY").Returns("false");
36+
37+
// WoodpeckerCI CommitInfo
38+
Environment.GetEnvironmentVariable("CI_COMMIT_SHA").Returns("eba09b46064473a1d345da7abf28b477468e8dbd");
39+
Environment.GetEnvironmentVariable("CI_COMMIT_REF").Returns("refs/heads/main");
40+
Environment.GetEnvironmentVariable("CI_COMMIT_REFSPEC").Returns("issue-branch:main");
41+
Environment.GetEnvironmentVariable("CI_COMMIT_BRANCH").Returns("main");
42+
Environment.GetEnvironmentVariable("CI_COMMIT_SOURCE_BRANCH").Returns("issue-branch");
43+
Environment.GetEnvironmentVariable("CI_COMMIT_TARGET_BRANCH").Returns("main");
44+
Environment.GetEnvironmentVariable("CI_COMMIT_TAG").Returns("v1.10.3");
45+
Environment.GetEnvironmentVariable("CI_COMMIT_PULL_REQUEST").Returns("1");
46+
Environment.GetEnvironmentVariable("CI_COMMIT_PULL_REQUEST_LABELS").Returns("server");
47+
Environment.GetEnvironmentVariable("CI_COMMIT_MESSAGE").Returns("Initial commit");
48+
Environment.GetEnvironmentVariable("CI_COMMIT_AUTHOR").Returns("john-doe");
49+
Environment.GetEnvironmentVariable("CI_COMMIT_AUTHOR_EMAIL").Returns("[email protected]");
50+
Environment.GetEnvironmentVariable("CI_COMMIT_PRERELEASE").Returns("false");
51+
52+
// WoodpeckerCI PipelineInfo
53+
Environment.GetEnvironmentVariable("CI_PIPELINE_NUMBER").Returns("8");
54+
Environment.GetEnvironmentVariable("CI_PIPELINE_PARENT").Returns("0");
55+
Environment.GetEnvironmentVariable("CI_PIPELINE_EVENT").Returns("push");
56+
Environment.GetEnvironmentVariable("CI_PIPELINE_URL").Returns("https://ci.example.com/repos/john-doe/my-repo/pipeline/123");
57+
Environment.GetEnvironmentVariable("CI_PIPELINE_FORGE_URL").Returns("https://git.example.com/john-doe/my-repo/commit/abc123");
58+
Environment.GetEnvironmentVariable("CI_PIPELINE_DEPLOY_TARGET").Returns("production");
59+
Environment.GetEnvironmentVariable("CI_PIPELINE_DEPLOY_TASK").Returns("migration");
60+
Environment.GetEnvironmentVariable("CI_PIPELINE_CREATED").Returns("1722617519");
61+
Environment.GetEnvironmentVariable("CI_PIPELINE_STARTED").Returns("1722617519");
62+
Environment.GetEnvironmentVariable("CI_PIPELINE_FILES").Returns("[\".woodpecker.yml\",\"README.md\"]");
63+
Environment.GetEnvironmentVariable("CI_PIPELINE_AUTHOR").Returns("octocat");
64+
Environment.GetEnvironmentVariable("CI_PIPELINE_AVATAR").Returns("https://git.example.com/avatars/john-doe");
65+
66+
// WoodpeckerCI WorkflowInfo
67+
Environment.GetEnvironmentVariable("CI_WORKFLOW_NAME").Returns("release");
68+
69+
// WoodpeckerCI StepInfo
70+
Environment.GetEnvironmentVariable("CI_STEP_NAME").Returns("build package");
71+
Environment.GetEnvironmentVariable("CI_STEP_NUMBER").Returns("0");
72+
Environment.GetEnvironmentVariable("CI_STEP_STARTED").Returns("1722617519");
73+
Environment.GetEnvironmentVariable("CI_STEP_URL").Returns("https://ci.example.com/repos/7/pipeline/8");
74+
75+
// WoodpeckerCI SystemInfo
76+
Environment.GetEnvironmentVariable("CI_SYSTEM_NAME").Returns("woodpecker");
77+
Environment.GetEnvironmentVariable("CI_SYSTEM_URL").Returns("https://ci.example.com");
78+
Environment.GetEnvironmentVariable("CI_SYSTEM_HOST").Returns("ci.example.com");
79+
Environment.GetEnvironmentVariable("CI_SYSTEM_VERSION").Returns("2.7.0");
80+
81+
// WoodpeckerCI ForgeInfo
82+
Environment.GetEnvironmentVariable("CI_FORGE_TYPE").Returns("github");
83+
Environment.GetEnvironmentVariable("CI_FORGE_URL").Returns("https://git.example.com");
84+
}
85+
86+
public WoodpeckerCIEnvironmentInfo CreateEnvironmentInfo()
87+
{
88+
return new WoodpeckerCIEnvironmentInfo(Environment);
89+
}
90+
91+
public WoodpeckerCIRepositoryInfo CreateRepositoryInfo()
92+
{
93+
return new WoodpeckerCIRepositoryInfo(Environment);
94+
}
95+
96+
public WoodpeckerCICommitInfo CreateCommitInfo()
97+
{
98+
return new WoodpeckerCICommitInfo(Environment);
99+
}
100+
101+
public WoodpeckerCIPipelineInfo CreatePipelineInfo()
102+
{
103+
return new WoodpeckerCIPipelineInfo(Environment);
104+
}
105+
106+
public WoodpeckerCIWorkflowInfo CreateWorkflowInfo()
107+
{
108+
return new WoodpeckerCIWorkflowInfo(Environment);
109+
}
110+
111+
public WoodpeckerCIStepInfo CreateStepInfo()
112+
{
113+
return new WoodpeckerCIStepInfo(Environment);
114+
}
115+
116+
public WoodpeckerCISystemInfo CreateSystemInfo()
117+
{
118+
return new WoodpeckerCISystemInfo(Environment);
119+
}
120+
121+
public WoodpeckerCIForgeInfo CreateForgeInfo()
122+
{
123+
return new WoodpeckerCIForgeInfo(Environment);
124+
}
125+
126+
public WoodpeckerCIInfoFixture SetEnvironmentVariable(string name, string value)
127+
{
128+
Environment.GetEnvironmentVariable(name).Returns(value);
129+
return this;
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)