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

samsmithnz / GitHubActionsDotNet / 7900757945

14 Feb 2024 11:53AM CUT coverage: 76.33%. Remained the same
7900757945

Pull #133

github

web-flow
Merge 652e32ffc into 5ca82b379
Pull Request #133: Bump the core group in /src/GitHubActionsDotNet with 1 update

144 of 222 branches covered (64.86%)

Branch coverage included in aggregate %.

559 of 699 relevant lines covered (79.97%)

13.88 hits per line

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

90.42
/src/GitHubActionsDotNet/Helpers/DotNetStepHelper.cs
1
using GitHubActionsDotNet.Models;
2
using System.Collections.Generic;
3
using System.Text;
4

5
namespace GitHubActionsDotNet.Helpers
6
{
7
    public static class DotNetStepHelper
8
    {
9
        public static Step AddDotNetSetupStep(string name = null,
10
            string dotnetVersion = "7.x",
11
            string _if = null,
12
            Dictionary<string, string> env = null)
13
        {
14
            if (name == null)
5✔
15
            {
16
                name = "Setup .NET SDK";
1✔
17
            }
18
            Step step = BaseStep.AddBaseStep(name, _if, env);
5✔
19
            step.uses = "actions/setup-dotnet@v3";
5✔
20
            step.with = new Dictionary<string, string>();
5✔
21
            step.with.Add("dotnet-version", dotnetVersion);
5✔
22
            return step;
5✔
23
        }
24

25
        public static Step AddDotNetRestoreStep(string name = null,
26
            string project = null,
27
            string otherArguments = null,
28
            //bool useShortParameters = false //Included for inclusivity reasons
29
            string _if = null,
30
            Dictionary<string, string> env = null)
31
        {
32
            if (name == null)
3✔
33
            {
34
                name = ".NET restore";
1✔
35
            }
36
            Step step = BaseStep.AddBaseStep(name, _if, env);
3✔
37
            StringBuilder sb = new StringBuilder();
3✔
38
            sb.Append("dotnet restore ");
3✔
39
            if (project != null)
3✔
40
            {
41
                sb.Append(project);
3✔
42
                sb.Append(" ");
3✔
43
            }
44
            if (otherArguments != null)
3!
45
            {
46
                sb.Append(otherArguments);
×
47
                sb.Append(" ");
×
48
            }
49
            step.run = sb.ToString();
3✔
50
            return step;
3✔
51
        }
52

53
        public static Step AddDotNetBuildStep(string name = null,
54
            string project = null,
55
            string configuration = null,
56
            string otherArguments = null,
57
            bool useShortParameters = false, //Included for inclusivity reasons
58
            string _if = null,
59
            Dictionary<string, string> env = null)
60
        {
61
            if (name == null)
4!
62
            {
63
                name = ".NET build";
×
64
            }
65
            Step step = BaseStep.AddBaseStep(name, _if, env);
4✔
66
            StringBuilder sb = new StringBuilder();
4✔
67
            sb.Append("dotnet build ");
4✔
68
            if (project != null)
4✔
69
            {
70
                sb.Append(project);
4✔
71
                sb.Append(" ");
4✔
72
            }
73
            if (configuration != null)
4✔
74
            {
75
                sb.Append(ProcessAlternativeParameters(configuration, "c", "configuration", useShortParameters));
4✔
76
            }
77
            if (otherArguments != null)
4✔
78
            {
79
                sb.Append(otherArguments);
2✔
80
                sb.Append(" ");
2✔
81
            }
82
            step.run = sb.ToString();
4✔
83
            return step;
4✔
84
        }
85

86
        public static Step AddDotNetTestStep(string name = null,
87
            string project = null,
88
            string configuration = null,
89
            string otherArguments = null,
90
            bool useShortParameters = false, //Included for inclusivity reasons)
91
            string _if = null,
92
            Dictionary<string, string> env = null)
93
        {
94
            if (name == null)
3!
95
            {
96
                name = ".NET test";
×
97
            }
98
            Step step = BaseStep.AddBaseStep(name, _if, env);
3✔
99
            StringBuilder sb = new StringBuilder();
3✔
100
            sb.Append("dotnet test ");
3✔
101
            if (project != null)
3✔
102
            {
103
                sb.Append(project);
1✔
104
                sb.Append(" ");
1✔
105
            }
106
            if (configuration != null)
3✔
107
            {
108
                sb.Append(ProcessAlternativeParameters(configuration, "c", "configuration", useShortParameters));
1✔
109
            }
110
            if (otherArguments != null)
3!
111
            {
112
                sb.Append(otherArguments);
×
113
                sb.Append(" ");
×
114
            }
115
            step.run = sb.ToString();
3✔
116
            return step;
3✔
117
        }
118

119
        public static Step AddDotNetNuGetPushStep(string name = null,
120
            string nupkgFile = null,
121
            string source = null,
122
            string otherArguments = null,
123
            bool useShortParameters = false, //Included for inclusivity reasons
124
            string _if = null,
125
            Dictionary<string, string> env = null)
126
        {
127
            if (name == null)
2✔
128
            {
129
                name = "Push NuGet package";
1✔
130
            }
131
            Step step = BaseStep.AddBaseStep(name, _if, env);
2✔
132
            StringBuilder sb = new StringBuilder();
2✔
133
            sb.Append("dotnet nuget push ");
2✔
134
            if (nupkgFile != null)
2✔
135
            {
136
                sb.Append(nupkgFile);
2✔
137
                sb.Append(" ");
2✔
138
            }
139
            if (source != null)
2✔
140
            {
141
                sb.Append(ProcessAlternativeParameters(source, "s", "source", useShortParameters));
2✔
142
            }
143
            if (otherArguments != null)
2✔
144
            {
145
                sb.Append(otherArguments);
1✔
146
                sb.Append(" ");
1✔
147
            }
148
            step.run = sb.ToString();
2✔
149
            return step;
2✔
150
        }
151

152
        public static Step AddDotNetPackStep(string name = null,
153
            string project = null,
154
            string configuration = null,
155
            string output = null,
156
            string otherArguments = null,
157
            bool useShortParameters = false, //Included for inclusivity reasons
158
            string _if = null,
159
            Dictionary<string, string> env = null)
160
        {
161
            if (name == null)
2!
162
            {
163
                name = ".NET NuGet pack";
×
164
            }
165
            Step step = BaseStep.AddBaseStep(name, _if, env);
2✔
166
            StringBuilder sb = new StringBuilder();
2✔
167
            sb.Append("dotnet pack ");
2✔
168
            if (project != null)
2✔
169
            {
170
                sb.Append(project);
2✔
171
                sb.Append(" ");
2✔
172
            }
173
            if (configuration != null)
2✔
174
            {
175
                sb.Append(ProcessAlternativeParameters(configuration, "c", "configuration", useShortParameters));
1✔
176
            }
177
            if (output != null)
2!
178
            {
179
                sb.Append(ProcessAlternativeParameters(output, "o", "output", useShortParameters));
×
180
            }
181
            if (otherArguments != null)
2✔
182
            {
183
                sb.Append(otherArguments);
1✔
184
                sb.Append(" ");
1✔
185
            }
186
            step.run = sb.ToString();
2✔
187
            return step;
2✔
188
        }
189

190
        public static Step AddDotNetPublishStep(string name = null,
191
            string project = null,
192
            string configuration = null,
193
            string output = null,
194
            string otherArguments = null,
195
            bool useShortParameters = false, //Included for inclusivity reasons
196
            string _if = null,
197
            Dictionary<string, string> env = null)
198
        {
199
            if (name == null)
3!
200
            {
201
                name = ".NET publish";
×
202
            }
203
            Step step = BaseStep.AddBaseStep(name, _if, env);
3✔
204
            StringBuilder sb = new StringBuilder();
3✔
205
            sb.Append("dotnet publish ");
3✔
206
            if (project != null)
3✔
207
            {
208
                sb.Append(project);
3✔
209
                sb.Append(" ");
3✔
210
            }
211
            if (configuration != null)
3✔
212
            {
213
                sb.Append(ProcessAlternativeParameters(configuration, "c", "configuration", useShortParameters));
3✔
214
            }
215
            if (output != null)
3✔
216
            {
217
                sb.Append(ProcessAlternativeParameters(output, "o", "output", useShortParameters));
3✔
218
            }
219
            if (otherArguments != null)
3✔
220
            {
221
                sb.Append(otherArguments);
2✔
222
                sb.Append(" ");
2✔
223
            }
224
            step.run = sb.ToString();
3✔
225
            return step;
3✔
226
        }
227

228
        private static string ProcessAlternativeParameters(string commandText,
229
            string shortCommand,
230
            string longCommand,
231
            bool useShortParameters)
232
        {
233
            //Generates either -c Release or --command Release
234
            StringBuilder sb = new StringBuilder();
14✔
235
            if (commandText != null)
14✔
236
            {
237
                if (useShortParameters == true)
14✔
238
                {
239
                    //e.g. -c
240
                    sb.Append("-");
3✔
241
                    sb.Append(shortCommand);
3✔
242
                    sb.Append(" ");
3✔
243
                }
244
                else
245
                {
246
                    //e.g. --command
247
                    sb.Append("--");
11✔
248
                    sb.Append(longCommand);
11✔
249
                    sb.Append(" ");
11✔
250
                }
251
                //e.g. Release
252
                sb.Append(commandText);
14✔
253
                sb.Append(" ");
14✔
254
            }
255
            return sb.ToString();
14✔
256
        }
257
    }
258
}
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