@@ -20,25 +20,17 @@ func NewManager(configFilePath string) *Manager {
2020// LoadConfig is the only method that the caller of Manager needs to be concerned with, and this method returns a *Config finally.
2121// The main workflow of this method is:
2222// 1. Get the original config from the config file specified by ConfigFilePath;
23- // 2. Parsing tools from the apps, and merge that tools to Config.Tools;
24- // 3. Validation.
23+ // 2. Validation.
2524func (m * Manager ) LoadConfig () (* Config , error ) {
26- // step 1
25+ // step 1: get config
2726 c , err := m .getConfigFromFileWithGlobalVars ()
2827 if err != nil {
2928 return nil , err
3029 }
31-
32- // step 2
33- appTools , err := c .getToolsFromApps ()
34- if err != nil {
35- return nil , err
36- }
37-
38- c .Tools = append (c .Tools , appTools ... )
30+ // set instanceID in options
3931 c .renderInstanceIDtoOptions ()
4032
41- // step 3
33+ // step 2: check config is valid
4234 if err = c .validate (); err != nil {
4335 return nil , err
4436 }
@@ -50,50 +42,50 @@ func (m *Manager) LoadConfig() (*Config, error) {
5042// 1. render the global variables to Config.Tools and Config.Apps
5143// 2. transfer the PipelineTemplates to Config.pipelineTemplateMap, it's map[string]string type.
5244// We can't render the original config file to Config.PipelineTemplates directly for the:
53- // 1. variables rendered must be before the yaml.Unmarshal() called for the [[ foo ]] will be treated as a two-dimensional array by the yaml parser;
54- // 2. the variables used([[ foo ]]) in the Config.PipelineTemplates can be defined in the Config.Apps or Config.Vars;
55- // 3. pipeline templates are used in apps, so it would be more appropriate to refer to pipeline templates when dealing with apps
45+ // 1. variables rendered must be before the yaml.Unmarshal() called for the [[ foo ]] will be treated as a two-dimensional array by the yaml parser;
46+ // 2. the variables used([[ foo ]]) in the Config.PipelineTemplates can be defined in the Config.Apps or Config.Vars;
5647func (m * Manager ) getConfigFromFileWithGlobalVars () (* Config , error ) {
5748 configBytes , err := os .ReadFile (m .ConfigFilePath )
5849 if err != nil {
5950 return nil , err
6051 }
6152
62- // global variables
63- vars , err := getVarsFromConfigFile (configBytes )
53+ // extract top raw config struct from config text
54+ r , err := newRawConfigFromConfigBytes (configBytes )
55+ if err != nil {
56+ return nil , err
57+ }
58+ // 1. get global variables
59+ vars , err := r .getVars ()
6460 if err != nil {
6561 return nil , fmt .Errorf ("failed to get variables from config file. Error: %w" , err )
6662 }
6763
68- // tools with global variables rendered
69- tools , err := getToolsFromConfigFileWithVarsRendered ( configBytes , vars )
64+ // 2. tools with global variables rendered
65+ tools , err := r . getToolsWithVars ( vars )
7066 if err != nil {
7167 return nil , fmt .Errorf ("failed to get tools from config file. Error: %w" , err )
7268 }
7369
74- // apps with global variables rendered
75- apps , err := getAppsFromConfigFileWithVarsRendered ( configBytes , vars )
70+ // 3. apps tools with global variables rendered
71+ appTools , err := r . getAppToolsWithVars ( vars )
7672 if err != nil {
7773 return nil , fmt .Errorf ("failed to get apps from config file. Error: %w" , err )
7874 }
75+ // all tools from apps should depend on the original tools,
76+ // because dtm will execute all original tools first, then execute all tools from apps
77+ appTools .updateToolDepends (tools )
78+ tools = append (tools , appTools ... )
7979
80- // pipelineTemplateMap transfer from PipelineTemplates
81- pipelineTemplateMap , err := getPipelineTemplatesMapFromConfigFile (configBytes )
82- if err != nil {
83- return nil , fmt .Errorf ("failed to get pipelineTemplatesMap from config file. Error: %w" , err )
84- }
85-
86- // coreConfig without any changes
87- coreConfig , err := getCoreConfigFromConfigFile (configBytes )
80+ // 4. coreConfig without any changes
81+ coreConfig , err := r .getConfig ()
8882 if err != nil {
8983 return nil , fmt .Errorf ("failed to get coreConfig from config file. Error: %w" , err )
9084 }
9185
9286 return & Config {
93- Config : * coreConfig ,
94- Vars : vars ,
95- Tools : tools ,
96- Apps : apps ,
97- pipelineTemplateMap : pipelineTemplateMap ,
87+ Config : * coreConfig ,
88+ Vars : vars ,
89+ Tools : tools ,
9890 }, nil
9991}
0 commit comments