• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / RepoAutomation / 3895898324

pending completion
3895898324

push

github

GitHub
Merge pull request #212 from samsmithnz/FixToLanguageTest

333 of 474 branches covered (70.25%)

Branch coverage included in aggregate %.

795 of 893 relevant lines covered (89.03%)

6.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.04
/src/RepoAutomation.Core/Helpers/GitHubActions.cs
1
using GitHubActionsDotNet.Helpers;
2
using GitHubActionsDotNet.Models;
3
using GitHubActionsDotNet.Serialization;
4
using System.Text;
5

6
namespace RepoAutomation.Core.Helpers
7
{
8
    public static class GitHubActions
9
    {
10
        public static string SetupAction(string workingDirectory, string projectName,
11
            string projectTypes)
12
        {
2✔
13
            StringBuilder log = new();
2✔
14

15
            //Create and Serialize to YAML
16
            string yaml = CreateActionYaml(projectName, projectTypes);
2✔
17

18
            //Save the YAML to a file
19
            if (!Directory.Exists(workingDirectory))
2!
20
            {
×
21
                log.Append("Create directory " + workingDirectory);
×
22
                Directory.CreateDirectory(workingDirectory);
×
23
            }
×
24
            if (!Directory.Exists(workingDirectory + "\\.github"))
2!
25
            {
×
26
                log.Append("Create directory " + workingDirectory + "\\.github");
×
27
                Directory.CreateDirectory(workingDirectory + "\\.github");
×
28
            }
×
29
            if (!Directory.Exists(workingDirectory + "\\.github\\workflows"))
2!
30
            {
×
31
                log.Append("Create directory " + workingDirectory + "\\.github\\workflows");
×
32
                Directory.CreateDirectory(workingDirectory + "\\.github\\workflows");
×
33
            }
×
34
            log.Append("Writing workflow to file: " + workingDirectory + "\\.github\\workflows\\workflow.yml");
2✔
35
            File.WriteAllText(workingDirectory + "\\.github\\workflows\\workflow.yml", yaml);
2✔
36

37
            return log.ToString();
2✔
38
        }
2✔
39

40
        public static string CreateActionYaml(string projectName, string projectTypes)
41
        {
4✔
42
            //Split out the project types
43
            Dictionary<string, string> projectsToCreate = DotNet.CreateProjectTypeArray(projectTypes);
4✔
44

45
            JobHelper jobHelper = new();
4✔
46
            GitHubActionsRoot root = new();
4✔
47
            root.name = "CI/CD";
4✔
48
            root.on = TriggerHelper.AddStandardPushAndPullTrigger("main");
4✔
49

50
            string displayBuildGitVersionScript = @"
4✔
51
echo ""Version: ${{ steps.gitversion.outputs.SemVer }}""
4✔
52
echo ""CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}""";
4✔
53

54
            List<Step> steps = new()
4✔
55
            {
4✔
56
                CommonStepHelper.AddCheckoutStep(null, null, "0"),
4✔
57
                GitVersionStepHelper.AddGitVersionSetupStep(),
4✔
58
                GitVersionStepHelper.AddGitVersionDetermineVersionStep(),
4✔
59
                CommonStepHelper.AddScriptStep("Display GitVersion outputs", displayBuildGitVersionScript),
4✔
60
                DotNetStepHelper.AddDotNetSetupStep("Setup .NET", "7.0.x")
4✔
61
            };
4✔
62
            //Add all of the project types
63
            foreach (KeyValuePair<string, string> item in projectsToCreate)
18✔
64
            {
3✔
65
                if (item.Value == ".Tests")
3✔
66
                {
1✔
67
                    steps.Add(DotNetStepHelper.AddDotNetTestStep(".NET test", "src/" + projectName + item.Value + "/" + projectName + ".Tests.csproj", "Release", null, true));
1✔
68
                }
1✔
69
                else if (item.Value == "") //Console or library
2✔
70
                {
1✔
71
                    steps.Add(DotNetStepHelper.AddDotNetPublishStep(".NET publish", "src/" + projectName + "/" + projectName + item.Value + ".csproj", "Release", null, "-p:Version='${{ steps.gitversion.outputs.SemVer }}'", true));
1✔
72
                    steps.Add(CommonStepHelper.AddUploadArtifactStep("Upload package back to GitHub", "drop", "src/" + projectName + item.Value + "/bin/Release"));
1✔
73
                }
1✔
74
                else if (item.Value == ".Web") //Website
1!
75
                {
1✔
76
                    steps.Add(DotNetStepHelper.AddDotNetPublishStep(".NET publish", "src/" + projectName + item.Value + "/" + projectName + item.Value + ".csproj", "Release", null, "-p:Version='${{ steps.gitversion.outputs.SemVer }}'", true));
1✔
77
                    steps.Add(CommonStepHelper.AddUploadArtifactStep("Upload package back to GitHub", "web", "src/" + projectName + item.Value + "/bin/Release"));
1✔
78
                }
1✔
79
                else if (item.Value == ".Service") //Service
×
80
                {
×
81
                    steps.Add(DotNetStepHelper.AddDotNetPublishStep(".NET publish", "src/" + projectName + item.Value + "/" + projectName + item.Value + ".csproj", "Release", null, "-p:Version='${{ steps.gitversion.outputs.SemVer }}'", true));
×
82
                    steps.Add(CommonStepHelper.AddUploadArtifactStep("Upload package back to GitHub", "service", "src/" + projectName + item.Value + "/bin/Release"));
×
83
                }
×
84
                else if (item.Value == ".WPF") //WPF
×
85
                {
×
86
                    steps.Add(DotNetStepHelper.AddDotNetPublishStep(".NET publish", "src/" + projectName + "/" + projectName + item.Value + ".csproj", "Release", null, "-p:Version='${{ steps.gitversion.outputs.SemVer }}'", true));
×
87
                    steps.Add(CommonStepHelper.AddUploadArtifactStep("Upload package back to GitHub", "wpf", "src/" + projectName + item.Value + "/bin/Release"));
×
88
                }
×
89
                else if (item.Value == ".Winforms") //Winforms
×
90
                {
×
91
                    steps.Add(DotNetStepHelper.AddDotNetPublishStep(".NET publish", "src/" + projectName + "/" + projectName + item.Value + ".csproj", "Release", null, "-p:Version='${{ steps.gitversion.outputs.SemVer }}'", true));
×
92
                    steps.Add(CommonStepHelper.AddUploadArtifactStep("Upload package back to GitHub", "winforms", "src/" + projectName + item.Value + "/bin/Release"));
×
93
                }
×
94
            }
3✔
95
            Step[] buildSteps = steps.ToArray();
4✔
96

97
            root.jobs = new();
4✔
98
            Job buildJob = jobHelper.AddJob(
4✔
99
                "Build job",
4✔
100
                "windows-latest",
4✔
101
                buildSteps);
4✔
102
            buildJob.outputs = new()
4✔
103
            {
4✔
104
                { "Version", "${{ steps.gitversion.outputs.SemVer }}" },
4✔
105
                { "CommitsSinceVersionSource", "${{ steps.gitversion.outputs.CommitsSinceVersionSource }}" }
4✔
106
            };
4✔
107
            root.jobs.Add("build", buildJob);
4✔
108
            string yaml = GitHubActionsSerialization.Serialize(root);
4✔
109
            return yaml;
4✔
110
        }
4✔
111

112
    }
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc