-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
614 lines (490 loc) · 21.9 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/alecthomas/kingpin"
foundation "github.com/estafette/estafette-foundation"
"github.com/rs/zerolog/log"
)
var (
appgroup string
app string
version string
branch string
revision string
buildDate string
goVersion = runtime.Version()
)
var (
// flags
action = kingpin.Flag("action", "Any of the following actions: restore, build, test, unit-test, integration-test, publish, pack, push-nuget").Envar("ESTAFETTE_EXTENSION_ACTION").String()
configuration = kingpin.Flag("configuration", "The build configuration.").Envar("ESTAFETTE_EXTENSION_CONFIGURATION").Default("Release").String()
buildVersion = kingpin.Flag("buildVersion", "The build version.").Envar("ESTAFETTE_EXTENSION_BUILD_VERSION").String()
project = kingpin.Flag("project", "The path to the project for which the tests/build should be run.").Envar("ESTAFETTE_EXTENSION_PROJECT").String()
runtimeID = kingpin.Flag("runtimeId", "The publish runtime.").Envar("ESTAFETTE_EXTENSION_RUNTIME_ID").Default("linux-x64").String()
forceRestore = kingpin.Flag("forceRestore", "Execute the restore on every action.").Envar("ESTAFETTE_EXTENSION_FORCE_RESTORE").Default("false").Bool()
forceBuild = kingpin.Flag("forceBuild", "Execute the build on every action.").Envar("ESTAFETTE_EXTENSION_FORCE_BUILD").Default("false").Bool()
outputFolder = kingpin.Flag("outputFolder", "The folder into which the publish output is generated.").Envar("ESTAFETTE_EXTENSION_OUTPUT_FOLDER").String()
packagesFolder = kingpin.Flag("packagesFolder", "The folder in which the NuGet packages to be published will be searched.").Envar("ESTAFETTE_EXTENSION_PACKAGES_FOLDER").String()
nugetSources = kingpin.Flag("nugetSources", "String array of nuget sources to restore from.").Envar("ESTAFETTE_EXTENSION_SOURCES").String()
nugetServerURL = kingpin.Flag("nugetServerUrl", "The URL of the NuGet server.").Envar("ESTAFETTE_EXTENSION_NUGET_SERVER_URL").String()
nugetServerAPIKey = kingpin.Flag("nugetServerApiKey", "The API key of the NuGet server.").Envar("ESTAFETTE_EXTENSION_NUGET_SERVER_API_KEY").String()
nugetServerCredentialsJSONPath = kingpin.Flag("nugetServerCredentials-path", "Path to file with NuGet Server credentials configured at server level, passed in to this trusted extension.").Default("/credentials/nuget_server.json").String()
nugetServerName = kingpin.Flag("nugetServerName", "The name of the preferred NuGet server from the preconfigured credentials.").Envar("ESTAFETTE_EXTENSION_NUGET_SERVER_NAME").Default("github-nuget").String()
nugetSkipDuplicate = kingpin.Flag("nugetSkipDuplicate", "Treat 409 Conflict response as a warning.").Envar("ESTAFETTE_EXTENSION_NUGET_SKIP_DUPLICATE").Default("false").Bool()
publishReadyToRun = kingpin.Flag("publishReadyToRun", "Sets PublishReadyToRun parameter for the publish action when true.").Envar("ESTAFETTE_EXTENSION_PUBLISH_READY_TO_RUN").Default("false").Bool()
publishSingleFile = kingpin.Flag("publishSingleFile", "Sets PublishSingleFile parameter for the publish action when true.").Envar("ESTAFETTE_EXTENSION_PUBLISH_SINGLE_FILE").Default("false").Bool()
publishTrimmed = kingpin.Flag("publishTrimmed", "Sets PublishTrimmed parameter for the publish action when true.").Envar("ESTAFETTE_EXTENSION_PUBLISH_TRIMMED").Default("false").Bool()
sonarQubeServerURL = kingpin.Flag("sonarQubeServerUrl", "The URL of the SonarQube Server to which we send analysis reports.").Envar("ESTAFETTE_EXTENSION_SONARQUBE_SERVER_URL").String()
sonarQubeToken = kingpin.Flag("sonarQubeToken", "The token for the SonarQube Server.").Envar("ESTAFETTE_EXTENSION_SONARQUBE_TOKEN").String()
sonarQubeServerCredentialsJSONPath = kingpin.Flag("sonarQubeServerCredentials-path", "Path to file with SonarQube Server credentials configured at server level, passed in to this trusted extension.").Default("/credentials/sonarqube_server.json").String()
sonarQubeServerName = kingpin.Flag("sonarQubeServerName", "The name of the preferred SonarQube server from the preconfigured credentials.").Envar("ESTAFETTE_EXTENSION_SONARQUBE_SERVER_NAME").String()
sonarQubeCoverageExclusions = kingpin.Flag("sonarQubeCoverageExclusions", "The path for the code to be excluded on SonarQube Scan.").Envar("ESTAFETTE_EXTENSION_SONARQUBE_COVERAGE_EXCLUSIONS").String()
)
func main() {
// parse command line parameters
kingpin.Parse()
// init log format from envvar ESTAFETTE_LOG_FORMAT
foundation.InitLoggingFromEnv(foundation.NewApplicationInfo(appgroup, app, version, branch, revision, buildDate))
// create context to cancel commands on sigterm
ctx := foundation.InitCancellationContext(context.Background())
workingDir, err := os.Getwd()
if err != nil {
log.Fatal().Err(err).Msg("Couldn't determine current working directory.")
}
// set defaults
builtInBuildVersion := os.Getenv("ESTAFETTE_BUILD_VERSION")
if *buildVersion == "" {
*buildVersion = builtInBuildVersion
}
solutionName, _ := getSolutionName()
if solutionName == "" {
log.Printf("Unknown solution")
} else {
log.Printf("Solution name: %s", solutionName)
}
switch *action {
case "restore": // Restore package dependencies with dotnet restore.
// Minimal example with defaults.
// image: extensions/dotnet:stable
// action: restore
// Determine the NuGet server credentials for restoring
// 1. If there is a NuGet.config file in the repository, we use that.
// 2. If nugetServerURL and nugetServerAPIKey are explicitly specified, we generate a NuGet.config file using those.
// 2. If we have the default credentials from the server level, and nugetServerName is explicitly specified, we look for the credential with the specified name.
// 3. If we have the default credentials from the server level, and nugetServerName is not specified, we take the first credential. (This is the sensible default if we're using only one NuGet server.)
configFileName := "nuget.config"
actualFileName := findActualNugetFileName(configFileName)
if foundation.FileExists(actualFileName) {
log.Fatal().Err(err).Msgf("The NuGet.config file was found in the repository and should be deleted. So then the common default sources are used. ")
}
if *nugetServerURL == "" || *nugetServerAPIKey == "" {
//nolint:errcheck
// use mounted credential file if present instead of relying on an envvar
if runtime.GOOS == "windows" {
*nugetServerCredentialsJSONPath = "C:" + *nugetServerCredentialsJSONPath
}
if foundation.FileExists(*nugetServerCredentialsJSONPath) {
*nugetServerURL, *nugetServerAPIKey = getNugetServerCredentialsFromFile(*nugetServerCredentialsJSONPath, *nugetServerName)
}
}
if *nugetServerURL != "" && *nugetServerAPIKey != "" {
log.Printf("Adding the NuGet source.\n")
log.Printf("> dotnet nuget add source --username travix-tooling-bot --password %v --store-password-in-clear-text --name travix %v\n", "********", *nugetServerURL)
foundation.RunCommandWithArgsWithoutLog(ctx, "dotnet", []string{"nuget", "add", "source", "--username", "travix-tooling-bot", "--password", *nugetServerAPIKey, "--store-password-in-clear-text", "--name", "travix", *nugetServerURL})
} else {
log.Printf("No custom NuGet credentials were found.\n")
}
// build docker image
log.Printf("Restoring packages...\n")
args := []string{
"restore",
"--packages",
".nuget/packages", // This is needed so the packages are restored into the working directory, so they're not lost between the stages.
}
if *nugetSources != "" {
nugetSourcesArray := strings.Split(*nugetSources, ",")
for _, source := range nugetSourcesArray {
args = append(args, "--source", source)
}
}
foundation.RunCommandWithArgs(ctx, "dotnet", args)
case "build": // Build the solution.
// Minimal example with defaults.
// image: extensions/dotnet:stable
// action: build
// Customizations.
// image: extensions/dotnet:stable
// action: build
// configuration: Debug
// versionSuffix: 5
log.Printf("Building the solution...\n")
args := []string{
"build",
"--configuration",
*configuration,
"/p:IncludeSourceRevisionInInformationalVersion=false",
}
if *buildVersion != "" {
args = append(args, fmt.Sprintf("/p:Version=%s", *buildVersion))
}
if !*forceRestore {
args = append(args, "--no-restore")
}
foundation.RunCommandWithArgs(ctx, "dotnet", args)
case "test": // Run the tests for the whole solution.
log.Printf("Running tests for every project in the ./test folder...\n")
runTests(ctx, "")
case "unit-test": // Run the unit tests.
log.Printf("Running tests for projects ending with UnitTests in the ./test folder...\n")
runTests(ctx, "UnitTests")
case "integration-test": // Run the integration tests.
log.Printf("Running tests for projects ending with IntegrationTests in the ./test folder...\n")
runTests(ctx, "IntegrationTests")
case "analyze-sonarqube": // Run the SonarQube analysis.
// Minimal example with defaults.
// image: extensions/dotnet:stable
// action: analyze-sonarqube
// Customizations.
// image: extensions/dotnet:stable
// action: analyze-sonarqube
// sonarQubeServerUrl: https://my-sonar-server.example.com
// sonarQubeCoverageExclusions: **Tests.cs
log.Printf("Running the SonarQube analysis...\n")
// Determine the SonarQube server credentials
// 1. If sonarQubeServerURL is explicitly specified, we use that.
// 2. If we have the default credentials from the server level, and sonarQubeServerName is explicitly specified, we look for the credential with the specified name.
// 3. If we have the default credentials from the server level, and sonarQubeServerName is not specified, we take the first credential. (This is the sensible default if we're using only one SonarQube server.)
if *sonarQubeServerURL == "" {
//nolint:errcheck
if runtime.GOOS == "windows" {
*sonarQubeServerCredentialsJSONPath = "C:" + *sonarQubeServerCredentialsJSONPath
}
if foundation.FileExists(*sonarQubeServerCredentialsJSONPath) {
log.Printf("Unmarshalling credentials...")
log.Info().Msgf("Reading credentials from file at path %v...", *sonarQubeServerCredentialsJSONPath)
credentialsFileContent, err := os.ReadFile(*sonarQubeServerCredentialsJSONPath)
if err != nil {
log.Fatal().Msgf("Failed reading credential file at path %v.", *sonarQubeServerCredentialsJSONPath)
}
var credentials []SonarQubeServerCredentials
err = json.Unmarshal(credentialsFileContent, &credentials)
if err != nil {
log.Fatal().Err(err).Msg("Failed unmarshalling credentials")
}
if len(credentials) == 0 {
log.Fatal().Msg("There were no credentials specified.")
}
if *sonarQubeServerName != "" {
credential := GetSonarQubeServerCredentialsByName(credentials, *sonarQubeServerName)
if credential == nil {
log.Fatal().Msgf("The NuGet Server credential with the name %v does not exist.", *sonarQubeServerName)
}
*sonarQubeServerURL = credential.AdditionalProperties.APIURL
*sonarQubeToken = credential.AdditionalProperties.Token
} else {
// Just pick the first
credential := credentials[0]
*sonarQubeServerURL = credential.AdditionalProperties.APIURL
*sonarQubeToken = credential.AdditionalProperties.Token
}
} else {
log.Fatal().Msg("The SonarQube server URL has to be specified to run the analysis.")
}
}
if *sonarQubeCoverageExclusions == "" {
*sonarQubeCoverageExclusions = "**Tests.cs"
}
// dotnet sonarscanner begin /k:"Travix.Core.ShoppingCart" /d:sonar.host.url=https://sonarqube.travix.com /d:sonar.cs.opencover.reportsPaths="**\coverage.opencover.xml" /d:sonar.coverage.exclusions="**Tests.cs"
args := []string{
"sonarscanner",
"begin",
fmt.Sprintf("/key:%s", solutionName),
fmt.Sprintf("/d:sonar.host.url=%s", *sonarQubeServerURL),
fmt.Sprintf("/d:sonar.login=%s", *sonarQubeToken),
"/d:sonar.cs.opencover.reportsPaths=\"**\\coverage.opencover.xml\"",
fmt.Sprintf("/d:sonar.coverage.exclusions=\"%s\"", *sonarQubeCoverageExclusions),
}
if *buildVersion != "" {
args = append(args, fmt.Sprintf("/version:%s", *buildVersion))
}
foundation.RunCommandWithArgs(ctx, "dotnet", args)
// dotnet build
args = []string{"build"}
if *buildVersion != "" {
args = append(args, fmt.Sprintf("/p:Version=%s", *buildVersion))
}
if !*forceRestore {
args = append(args, "--no-restore")
}
foundation.RunCommandWithArgs(ctx, "dotnet", args)
// Run unit tests with the extra arguments for coverage.
*forceBuild = true
runTests(ctx, "UnitTests", "/p:CollectCoverage=true", "/p:CoverletOutputFormat=opencover", "/p:CopyLocalLockFileAssemblies=true")
// dotnet sonarscanner end
args = []string{
"sonarscanner",
"end",
fmt.Sprintf("/d:sonar.login=%s", *sonarQubeToken),
}
foundation.RunCommandWithArgs(ctx, "dotnet", args)
case "publish": // Publish the final binaries.
// Minimal example with defaults.
// image: extensions/dotnet:stable
// action: publish
// Customizations.
// image: extensions/dotnet:stable
// action: publish
// project: src/CustomProject
// configuration: Debug
// runtimteId: windows10-x64
// outputFolder: ./binaries
// buildVersion: 1.5.0
// forceRestore: true
log.Printf("Publishing the binaries...\n")
// The solution is called Acme.FooApi, then we by default look for a project called Acme.FooApi.WebService, and if that doesn't exist, we fall back to simply Acme.FooApi
if *project == "" {
*project = fmt.Sprintf("src/%s.WebService", solutionName)
if _, err := os.Stat(*project); os.IsNotExist(err) {
*project = fmt.Sprintf("src/%s", solutionName)
if _, err := os.Stat(*project); os.IsNotExist(err) {
log.Fatal().Err(err).Msg("The project to be published can not be found. Please specify it with the 'project' label.")
}
}
}
if *outputFolder == "" {
// A default sensible choice is to put the publishing output directly under the working folder in a folder called "publish", so that its relative path doesn't depend on the project name.
// This makes it easier to use in a generic way in followup steps of the build.
*outputFolder = filepath.Join(workingDir, "publish")
}
args := []string{
"publish",
"--configuration",
*configuration,
"--runtime",
*runtimeID,
"--self-contained",
"true",
"--output",
*outputFolder,
*project,
"/p:IncludeSourceRevisionInInformationalVersion=false",
}
if *buildVersion != "" {
args = append(args, fmt.Sprintf("/p:Version=%s", *buildVersion))
}
if *publishReadyToRun {
args = append(args, "/p:PublishReadyToRun=true", "/p:PublishReadyToRunShowWarnings=true")
}
if *publishSingleFile {
args = append(args, "/p:PublishSingleFile=true")
}
if *publishTrimmed {
args = append(args, "/p:PublishTrimmed=true")
}
if !*forceRestore {
args = append(args, "--no-restore")
}
foundation.RunCommandWithArgs(ctx, "dotnet", args)
case "pack": // Pack the NuGet package.
// Minimal example with defaults.
// image: extensions/dotnet:stable
// action: pack
// Customizations.
// image: extensions/dotnet:stable
// action: pack
// force-restore: true
// force-build: true
// configuration: Debug
// versionSuffix: 5
log.Printf("Packing the nuget package(s)...\n")
args := []string{
"pack",
"--configuration",
*configuration,
}
if *buildVersion != "" {
args = append(args, fmt.Sprintf("/p:Version=%s", *buildVersion))
}
if !*forceRestore {
args = append(args, "--no-restore")
}
if !*forceBuild {
args = append(args, "--no-build")
}
foundation.RunCommandWithArgs(ctx, "dotnet", args)
case "push-nuget": // Pushes the package(s) to NuGet.
// Minimal example with defaults.
// image: extensions/dotnet:stable
// action: push-nuget
// Customizations.
// image: extensions/dotnet:stable
// action: push-nuget
// packagesFolder: MyProject/BuildOutput
// nugetServerUrl: https://nuget.mycompany.com
// nugetServerApikey: 3a4cdeca-3d5b-41a2-ac59-ae4b5c5eaece
// nugetSkipDuplicate: true
log.Printf("Publishing the nuget package(s)...\n")
type nugetCredentials struct {
url string
key string
}
var nugetPushCredentials []nugetCredentials
// Determine the NuGet server credentials
// If nugetServerURL and nugetServerAPIKey are explicitly specified, we use those.
// Otherwise, we automatically push to GitHub.
if *nugetServerURL == "" || *nugetServerAPIKey == "" {
// use mounted credential file if present instead of relying on an envvar
//nolint:errorcheck
if runtime.GOOS == "windows" {
*nugetServerCredentialsJSONPath = "C:" + *nugetServerCredentialsJSONPath
}
if foundation.FileExists(*nugetServerCredentialsJSONPath) {
url, key := getNugetServerCredentialsFromFile(*nugetServerCredentialsJSONPath, "github-nuget")
nugetPushCredentials = append(nugetPushCredentials, nugetCredentials{url: url, key: key})
} else {
log.Fatal().Msg("The NuGet server URL and API key have to be specified to push a package.")
}
} else {
nugetPushCredentials = append(nugetPushCredentials, nugetCredentials{url: *nugetServerURL, key: *nugetServerAPIKey})
}
packagesBasePath := *packagesFolder
if packagesBasePath == "" {
packagesBasePath = filepath.Join(workingDir, "src")
}
var files []string
err := filepath.Walk(packagesBasePath, func(path string, f os.FileInfo, _ error) error {
if !f.IsDir() {
if filepath.Ext(path) == ".nupkg" {
files = append(files, path)
}
}
return nil
})
if err != nil {
log.Fatal().Err(err).Msg("An error occurred while searching for .nupkg files.")
}
if len(files) == 0 {
log.Fatal().Msg("No .nupkg files were found.")
}
args1 := []string{
"nuget",
"push",
}
if *nugetSkipDuplicate {
args1 = append(args1, "--skip-duplicate")
}
for i := 0; i < len(files); i++ {
var argsForPackage []string
argsForPackage = append(argsForPackage, args1...)
argsForPackage = append(argsForPackage, files[i])
for _, cred := range nugetPushCredentials {
var argsForServer []string
argsForServer = append(argsForServer, argsForPackage...)
argsForServer = append(argsForServer, "--source", cred.url, "--api-key", cred.key)
// log the command for dotnet with argsForServer
flagsString := strings.Join(argsForServer, " ")
log.Printf("dotnet %v", flagsString)
foundation.RunCommandWithArgsWithoutLog(ctx, "dotnet", argsForServer)
}
}
default:
log.Fatal().Msg("Set `action: <action>` on this step to restore, build, test, unit-test, integration-test or publish.")
}
}
func getNugetServerCredentialsFromFile(credentialsFilePath string, serverName string) (serverURL string, APIKey string) {
log.Printf("Unmarshalling credentials...")
log.Info().Msgf("Reading credentials from file at path %v...", credentialsFilePath)
credentialsFileContent, err := os.ReadFile(credentialsFilePath)
if err != nil {
log.Fatal().Msgf("Failed reading credential file at path %v.", credentialsFilePath)
}
var credentials []NugetServerCredentials
err = json.Unmarshal(credentialsFileContent, &credentials)
if err != nil {
log.Fatal().Err(err).Msg("Failed unmarshalling credentials")
}
if len(credentials) == 0 {
log.Fatal().Msg("There are no credentials specified.")
}
if serverName != "" {
credential := GetNugetServerCredentialsByName(credentials, serverName)
if credential == nil {
log.Fatal().Msgf("The NuGet Server credential with the name %v does not exist.", serverName)
}
serverURL = credential.AdditionalProperties.APIURL
APIKey = credential.AdditionalProperties.APIKey
} else {
// Just pick the first
credential := credentials[0]
serverURL = credential.AdditionalProperties.APIURL
APIKey = credential.AdditionalProperties.APIKey
}
return
}
// Returns the name of the .NET Core solution in this repository, based on the name of the solution file. If it cannot find a solution file, it returns an empty string.
func getSolutionName() (string, error) {
files, err := os.ReadDir(".")
if err == nil {
for _, f := range files {
if strings.HasSuffix(f.Name(), ".sln") {
return strings.TrimSuffix(f.Name(), ".sln"), nil
}
}
return "", nil
}
return "", err
}
// Runs the unit tests for all projects in the ./test folder which have the passed in suffix in their name.
func runTests(ctx context.Context, projectSuffix string, extraArgs ...string) {
// Minimal example with defaults.
// image: extensions/dotnet:stable
// action: build
// Customizations.
// image: extensions/dotnet:stable
// action: build
// configuration: Debug
// versionSuffix: 5
args := []string{
"test",
"--configuration",
*configuration,
}
if !*forceRestore {
args = append(args, "--no-restore")
}
if !*forceBuild {
args = append(args, "--no-build")
}
args = append(args, extraArgs...)
files, err := os.ReadDir("./test")
if err == nil {
for _, f := range files {
if f.IsDir() && strings.HasSuffix(f.Name(), projectSuffix) {
log.Printf("Running tests for ./test/%s...\n", f.Name())
argsForProject := make([]string, len(args)+1)
copy(argsForProject, args)
argsForProject = append(argsForProject, fmt.Sprintf("./test/%s", f.Name()))
foundation.RunCommandWithArgs(ctx, "dotnet", argsForProject)
}
}
} else if !os.IsNotExist(err) { // If we got an error just because the "test" folder doesn't exist, that's fine, we can ignore. We only fail with an error if it was something else.
log.Fatal().Err(err).Msg("Failed to read subdirectories under ./test.")
}
}
func findActualNugetFileName(fileName string) string {
files, err := os.ReadDir(".")
if err == nil {
for _, f := range files {
if strings.EqualFold(f.Name(), fileName) {
return f.Name()
}
}
}
return ""
}