This repository was archived by the owner on Nov 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathStartUp.cs
More file actions
146 lines (115 loc) · 4.19 KB
/
StartUp.cs
File metadata and controls
146 lines (115 loc) · 4.19 KB
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
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Text;
using System.Linq;
using ADB.CMD;
using ADB.Config;
using ADB.Util;
using CoreFramework.Config;
namespace ADB
{
public class StartUp
{
private CmdOption CmdOption { get; set; }
private Configuration Config { get; set; } = new Configuration();
public StartUp(CmdOption cmdOption)
{
CmdOption = cmdOption;
}
public void Start()
{
Contract.Requires(CmdOption != null);
Log.Info($"Current directory is '{Directory.GetCurrentDirectory()}'");
if (CmdOption.ConfigGenerationPath != null)
{
Log.Info("MODE: Write JSON Config");
ReadCMDConfig();
FillSampleData();
WriteJsonConfig();
return;
}
Log.Info("MODE: Normal start");
if (CmdOption.ConfigPath != null)
ReadJsonConfig();
ReadCMDConfig();
ReadEnvConfig();
DoStart();
}
protected void FillSampleData()
{
if (string.IsNullOrWhiteSpace(Config.DestinationDirPattern))
Config.DestinationDirPattern = "bin/{BuildConfiguration}/net8.0/{RID}/publish";
if (Config.GitHubConfig.ProjectConfigs.Count == 0)
Config.GitHubConfig.ProjectConfigs.Add(new ADB.Config.Github.GitHubProjectConfig()
{
Owner = "ghost",
Repo = "YOUR_REPO_HERE"
});
}
protected void WriteJsonConfig()
{
Log.Info("Writing json config");
if (!string.IsNullOrWhiteSpace(CmdOption.ConfigGenerationPath))
Config.Config.SavePath = CmdOption.ConfigGenerationPath;
Log.Info($"Saving '{Config.Config.SavePath}'");
Config.Save();
Log.Info($"Saving: success");
}
protected void ReadJsonConfig()
{
Log.Info("Reading json config");
if (!string.IsNullOrWhiteSpace(CmdOption.ConfigPath))
Config.Config.SavePath = CmdOption.ConfigPath;
Log.Info($"Loading '{Config.Config.SavePath}'");
Config.Load(LoadFileNotFoundAction.THROW_EX);
Log.Info($"Loading: success");
}
protected void ReadCMDConfig()
{
Log.Info("Doing config over commandline-args");
if (!string.IsNullOrWhiteSpace(CmdOption.GITHUB_TOKEN))
{
Log.Info($"SetInp: {nameof(Config.GitHubConfig.GitHubToken)}='****'[SHA={HashUtil.GenerateSHA2(Config.GitHubConfig.GitHubToken)}]");
Config.GitHubConfig.GitHubToken = CmdOption.GITHUB_TOKEN;
}
if (!string.IsNullOrWhiteSpace(CmdOption.DestinationDirPattern))
{
Log.Info($"SetInp: {nameof(Config.DestinationDirPattern)}='{CmdOption.DestinationDirPattern}'");
Config.DestinationDirPattern = CmdOption.DestinationDirPattern;
}
if (!string.IsNullOrWhiteSpace(CmdOption.DestinationDir))
{
Log.Info($"SetInp: {nameof(Config.DestinationDir)}='{CmdOption.DestinationDir}'");
Config.DestinationDir = CmdOption.DestinationDir;
}
if (!string.IsNullOrWhiteSpace(CmdOption.BuildConfiguration))
{
Log.Info($"SetInp: {nameof(Config.BuildConfiguration)}='{CmdOption.BuildConfiguration}'");
Config.BuildConfiguration = CmdOption.BuildConfiguration;
}
if (!string.IsNullOrWhiteSpace(CmdOption.RID))
{
Log.Info($"SetInp: {nameof(Config.RID)}='{CmdOption.RID}'");
Config.RID = CmdOption.RID;
}
}
protected void ReadEnvConfig()
{
Log.Info("Reading environment config");
var envGithubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
if (!string.IsNullOrWhiteSpace(envGithubToken))
{
Log.Info($"SetInp: {nameof(Config.GitHubConfig.GitHubToken)}='****'[SHA={HashUtil.GenerateSHA2(envGithubToken)}]");
Config.GitHubConfig.GitHubToken = envGithubToken;
}
}
protected void DoStart()
{
Log.Info("Starting");
new Runner(Config).Run();
Log.Info("Done");
}
}
}