コード例 #1
0
        public async Task Execute(object options)
        {
            var dependenciesOptions = (GetDependenciesOptions)options;

            var currentGitBranch = GitHelper.GetCurrentBranchName(_fileSystem.GetWorkingDirectory());
            var configFile       = $"{currentGitBranch}.config";

            if (string.IsNullOrWhiteSpace(currentGitBranch))
            {
                Log.Error("Current git branch is not found. Likely git is not initialized. Exiting the program");
                return;
            }

            _configFullPath = dependenciesOptions.Force
                ? Path.Combine(GetTccDirectory(), configFile)
                : GetConfigFullPath(dependenciesOptions, configFile);

            Log.Info("Using '{0}' as dependency config", _configFullPath);

            _dependencyConfig = LoadConfigFile(dependenciesOptions, configFile);

            DependencyConfig dependencyConfig =
                await ResolveDependencies(_dependencyConfig.BuildConfigId, dependenciesOptions.Tag);

            Log.Info("Finished resolving dependencies");

            var buildConfig = await _client.BuildConfigs.GetByConfigurationId(_dependencyConfig.BuildConfigId);

            _majorVersion = buildConfig.Parameters[ParameterName.MajorVersion]?.Value;
            _minorVersion = buildConfig.Parameters[ParameterName.MinorVersion]?.Value;

            if (!String.IsNullOrEmpty(_majorVersion) || !String.IsNullOrEmpty(_minorVersion))
            {
                UpdateAssemblyVersion();
                UpdateBuildVersion();
                UpdateVersionIncVersion();
            }

            Log.Info("Finished updating versions");

            //only writes the file if changes were made to the config.
            if (_dependencyConfig.Equals(dependencyConfig) == false || dependenciesOptions.Force)
            {
                Log.Info("Updating config file...");
                string json = JsonConvert.SerializeObject(dependencyConfig, Formatting.Indented);
                _fileSystem.EnsureDirectoryExists(_configFullPath);
                _fileSystem.WriteAllTextToFile(_configFullPath, json);
                Log.Info("Done updating config file");
            }

            Log.Info("================ Get Dependencies: done ================");
        }