public void CanSetNextVersion() { ILog log = new NullLog(); IFileSystem fileSystem = new TestFileSystem(); IConsole testConsole = new TestConsole("3", "2.0.0", "0"); var serviceCollections = new ServiceCollection(); serviceCollections.AddModule(new GitVersionInitModule()); serviceCollections.AddSingleton(log); serviceCollections.AddSingleton(fileSystem); serviceCollections.AddSingleton(testConsole); var serviceProvider = serviceCollections.BuildServiceProvider(); var stepFactory = new ConfigInitStepFactory(serviceProvider); var configInitWizard = new ConfigInitWizard(testConsole, stepFactory); var configFileLocator = new DefaultConfigFileLocator(fileSystem, log); var workingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\proj" : "/proj"; var gitPreparer = new GitPreparer(log, new TestEnvironment(), Options.Create(new Arguments { TargetPath = workingDirectory })); var configurationProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard); configurationProvider.Init(workingDirectory); fileSystem.ReadAllText(Path.Combine(workingDirectory, "GitVersion.yml")).ShouldMatchApproved(); }
private void RepositoryScope(ILog log, Action <EmptyRepositoryFixture, VersionVariables> fixtureAction = null) { // Make sure GitVersion doesn't trigger build server mode when we are running the tests environment.SetEnvironmentVariable(AppVeyor.EnvironmentVariableName, null); environment.SetEnvironmentVariable(TravisCi.EnvironmentVariableName, null); environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, null); using var fixture = new EmptyRepositoryFixture(); var arguments = new Arguments { TargetPath = fixture.RepositoryPath }; var options = Options.Create(arguments); var gitPreparer = new GitPreparer(log, environment, options); var stepFactory = new ConfigInitStepFactory(); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard); var baseVersionCalculator = new BaseVersionCalculator(this.log, null); var mainlineVersionCalculator = new MainlineVersionCalculator(this.log, metaDataCalculator); var nextVersionCalculator = new NextVersionCalculator(this.log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator); var variableProvider = new VariableProvider(nextVersionCalculator, new TestEnvironment()); var gitVersionCalculator = new GitVersionCalculator(fileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options); fixture.Repository.MakeACommit(); var vv = gitVersionCalculator.CalculateVersionVariables(); vv.AssemblySemVer.ShouldBe("0.1.0.0"); vv.FileName.ShouldNotBeNullOrEmpty(); fixtureAction?.Invoke(fixture, vv); }
private GitVersionCalculator GetGitVersionCalculator(Arguments arguments) { var options = Options.Create(arguments); var gitPreparer = new GitPreparer(log, environment, options); var stepFactory = new ConfigInitStepFactory(); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard); var baseVersionCalculator = new BaseVersionCalculator(log, null); var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator); var nextVersionCalculator = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator); var variableProvider = new VariableProvider(nextVersionCalculator, new TestEnvironment()); var gitVersionCalculator = new GitVersionCalculator(fileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options); return(gitVersionCalculator); }
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer) { var root = Path.Combine(workDirectory, name); var dynamicDirectory = Path.Combine(root, "D"); // dynamic, keeping directory as short as possible var workingDirectory = Path.Combine(root, "W"); // working, keeping directory as short as possible var arguments = new Arguments { TargetUrl = url, DynamicRepositoryLocation = dynamicDirectory, TargetBranch = targetBranch, NoFetch = false, TargetPath = workingDirectory, CommitId = commitId }; var options = Options.Create(arguments); Directory.CreateDirectory(dynamicDirectory); Directory.CreateDirectory(workingDirectory); var testFileSystem = new TestFileSystem(); var log = new NullLog(); var configFileLocator = new DefaultConfigFileLocator(testFileSystem, log); var gitVersionCache = new GitVersionCache(testFileSystem, log); var buildServerResolver = new BuildServerResolver(null, log); var metadataCalculator = new MetaDataCalculator(); var baseVersionCalculator = new TestBaseVersionStrategiesCalculator(log); var mainlineVersionCalculator = new MainlineVersionCalculator(log, metadataCalculator); var nextVersionCalculator = new NextVersionCalculator(log, metadataCalculator, baseVersionCalculator, mainlineVersionCalculator); var gitVersionFinder = new GitVersionFinder(log, nextVersionCalculator); var gitPreparer = new GitPreparer(log, new TestEnvironment(), options); var stepFactory = new ConfigInitStepFactory(); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(testFileSystem, log, configFileLocator, gitPreparer, configInitWizard); var variableProvider = new VariableProvider(nextVersionCalculator, new TestEnvironment()); var gitVersionCalculator = new GitVersionCalculator(testFileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options); var versionVariables = gitVersionCalculator.CalculateVersionVariables(); Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer); }
public static void Init(string workingDirectory, IFileSystem fileSystem, IConsole console, ConfigFileLocator configFileLocator) { var configFilePath = configFileLocator.GetConfigFilePath(workingDirectory, fileSystem); var currentConfiguration = Provide(workingDirectory, fileSystem, applyDefaults: false, configFileLocator: configFileLocator); var config = new ConfigInitWizard(console, fileSystem).Run(currentConfiguration, workingDirectory); if (config == null) { return; } using (var stream = fileSystem.OpenWrite(configFilePath)) using (var writer = new StreamWriter(stream)) { Logger.WriteInfo("Saving config file"); ConfigSerialiser.Write(config, writer); stream.Flush(); } }
public void NoWarnOnGitVersionYmlFile() { SetupConfigFileContent(string.Empty); var output = WithDefaultConfigFileLocator(configFileLocator => { var log = new NullLog(); var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log); var gitPreparer = new GitPreparer(log, new TestEnvironment(), Options.Create(new Arguments { TargetPath = repoPath })); var stepFactory = new ConfigInitStepFactory(); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer, configInitWizard); configurationProvider.Provide(repoPath); }); output.Length.ShouldBe(0); }
public void NoWarnOnCustomYmlFileOutsideRepoPath() { SetupConfigFileContent(string.Empty, path: @"c:\\Unrelated\\path"); var stringLogger = string.Empty; void Action(string info) => stringLogger = info; var logAppender = new TestLogAppender(Action); log = new Log(logAppender); configFileLocator = new NamedConfigFileLocator(fileSystem, log, options); var gitPreparer = new GitPreparer(log, new TestEnvironment(), Options.Create(new Arguments { TargetPath = repoPath })); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard); configurationProvider.Provide(repoPath); stringLogger.Length.ShouldBe(0); }
public static void Init(string workingDirectory, IFileSystem fileSystem, IConsole console) { var configFilePath = GetConfigFilePath(workingDirectory, fileSystem); var currentConfiguration = Provide(workingDirectory, fileSystem, applyDefaults: false); var config = new ConfigInitWizard(console, fileSystem).Run(currentConfiguration, workingDirectory); if (config == null) return; using (var stream = fileSystem.OpenWrite(configFilePath)) using (var writer = new StreamWriter(stream)) { Logger.WriteInfo("Saving config file"); ConfigSerialiser.Write(config, writer); stream.Flush(); } }