public static bool TryParse(string versionString, out SemanticVersion semanticVersion) { var parts = versionString.Split('-'); if (parts.Length > 2) { semanticVersion = null; return false; } var stableParts = parts.First().Split('.'); if (stableParts.Length > 3) { semanticVersion = null; return false; } int major; int minor = 0; int patch = 0; if (!int.TryParse(stableParts[0], out major)) { semanticVersion = null; return false; } if (stableParts.Length > 1) { if (!int.TryParse(stableParts[1], out minor)) { semanticVersion = null; return false; } } if (stableParts.Length > 2) { if (!int.TryParse(stableParts[2], out patch)) { semanticVersion = null; return false; } } if (parts.Length > 1) { //TODO Pre } semanticVersion = new SemanticVersion(major, minor, patch); return true; }
public SemanticVersion GetNextVersion(SemanticVersion taggedVersion) { var filePath = Path.Combine(_workingDirectory, "NextVersion.txt"); if (!File.Exists(filePath)) { File.WriteAllText(filePath, taggedVersion.ToString()); } var version = File.ReadAllText(filePath); SemanticVersion semanticVersion; if (!SemanticVersionParser.TryParse(version, out semanticVersion)) throw new ArgumentException("Make sure you have a valid semantic version in NextVersion.txt"); return semanticVersion; }
public Dictionary<string, string> GetVariables(SemanticVersion nextBuildNumber) { string numOfCommitsSinceRelease = nextBuildNumber.BuildMetaData == null ? "<unknown>" : nextBuildNumber.BuildMetaData.ToString(); return new Dictionary<string, string> { {"GitHubFlowVersion_FullSemVer", nextBuildNumber.ToString()}, {"GitHubFlowVersion_SemVer", nextBuildNumber.WithBuildMetaData(null).ToString()}, {"GitHubFlowVersion_AssemblySemVer", nextBuildNumber.WithSuffix(null).WithBuildMetaData(null)+".0"}, {"GitHubFlowVersion_FourPartVersion", nextBuildNumber.ToVersion().ToString()}, {"GitHubFlowVersion_Major", nextBuildNumber.Major.ToString() }, {"GitHubFlowVersion_Minor", nextBuildNumber.Minor.ToString() }, {"GitHubFlowVersion_Patch", nextBuildNumber.Patch.ToString() }, {"GitHubFlowVersion_NumCommitsSinceRelease", numOfCommitsSinceRelease}, {"GitHubFlowVersion_Tag", nextBuildNumber.Suffix} }; }
private static void WriteResults(GitHubFlowArguments arguments, SemanticVersion nextBuildNumber, IBuildServer currentBuildServer) { var variableProvider = new VariableProvider(); var variables = variableProvider.GetVariables(nextBuildNumber); var outputStrategies = new IOutputStrategy[] { new BuildServerOutputStrategy(currentBuildServer), new JsonFileOutputStrategy(), new EnvironmentalVariablesOutputStrategy() }; foreach (var outputStrategy in outputStrategies) { outputStrategy.Write(arguments, variables, nextBuildNumber); } }
public int CompareTo(SemanticVersion value) { if (value == null) { return 1; } if (value.Equals(this)) { return 0; } if (Major != value.Major) { if (Major > value.Major) { return 1; } return -1; } if (Minor != value.Minor) { if (Minor > value.Minor) { return 1; } return -1; } if (Patch != value.Patch) { if (Patch > value.Patch) { return 1; } return -1; } return -1; }
protected bool Equals(SemanticVersion other) { return Major == other.Major && Minor == other.Minor && Patch == other.Patch && string.Equals(Suffix, other.Suffix); }
public VersionTaggedCommit(Commit commit, SemanticVersion semVer) { _commit = commit; _semVer = semVer; }