예제 #1
0
 internal static void UpdateChangeLog(string ChangeLogFilePath, Options options, GitClient gitClient)
 {
     using (new WorkingDirectoryScope(gitClient.RepositoryPath))
     {
         if (File.Exists(ChangeLogFilePath))
         {
             Logger.Info("Updating {0}...", ChangeLogFilePath);
             var changelog      = File.ReadAllLines(ChangeLogFilePath).ToList();
             var releaseHeading = string.Format(ChangeLogReleaseHeadingTemplate, options.Version,
                                                DateTime.Now);
             var releaseIndex = changelog.FindIndex(line => IsMarkdownHeading(line, 2, $"[`{options.Version}`] - "));
             // If we already have a changelog entry for this release, replace it.
             if (releaseIndex != -1)
             {
                 changelog[releaseIndex] = releaseHeading;
             }
             else
             {
                 // Add the new release heading under the "## Unreleased" one.
                 // Assuming that this is the first heading.
                 var unreleasedIndex = changelog.FindIndex(line => IsMarkdownHeading(line, 2));
                 changelog.InsertRange(unreleasedIndex + 1, new[]
                 {
                     string.Empty,
                     releaseHeading
                 });
             }
             File.WriteAllLines(ChangeLogFilePath, changelog);
             gitClient.StageFile(ChangeLogFilePath);
         }
     }
 }
예제 #2
0
        public static bool UpdateVersionFile(GitClient gitClient, string fileContents, string versionFileRelativePath, NLog.Logger logger)
        {
            using (new WorkingDirectoryScope(gitClient.RepositoryPath))
            {
                logger.Info("Updating contents of version file '{0}' to '{1}'...", versionFileRelativePath, fileContents);

                if (!File.Exists(versionFileRelativePath))
                {
                    throw new InvalidOperationException("Could not update the version file as the file " +
                                                        $"'{versionFileRelativePath}' does not exist.");
                }

                if (File.ReadAllText(versionFileRelativePath) == fileContents)
                {
                    logger.Info("Contents of '{0}' are already up-to-date ('{1}').", versionFileRelativePath, fileContents);
                    return(false);
                }

                File.WriteAllText(versionFileRelativePath, $"{fileContents}");

                gitClient.StageFile(versionFileRelativePath);
            }

            return(true);
        }
예제 #3
0
        private static void UpdateUnrealEngineVersionFile(List <string> versions, GitClient client)
        {
            const string unrealEngineVersionFile = "ci/unreal-engine.version";

            using (new WorkingDirectoryScope(client.RepositoryPath))
            {
                File.WriteAllLines(unrealEngineVersionFile, versions);
                client.StageFile(unrealEngineVersionFile);
            }
        }
예제 #4
0
        private static void UpdateVersionFile(GitClient gitClient, string fileContents, string relativeFilePath)
        {
            using (new WorkingDirectoryScope(gitClient.RepositoryPath))
            {
                Logger.Info("Updating contents of version file '{0}' to '{1}'...", relativeFilePath, fileContents);

                if (!File.Exists(relativeFilePath))
                {
                    throw new InvalidOperationException("Could not update the version file as the file " +
                                                        $"'{relativeFilePath}' does not exist.");
                }

                File.WriteAllText(relativeFilePath, $"{fileContents}");

                gitClient.StageFile(relativeFilePath);
            }
        }
예제 #5
0
        private static void UpdateGdkVersion(GitClient gitClient, string newPinnedVersion)
        {
            const string gdkPinnedFilename = "gdk.pinned";

            Logger.Info("Updating pinned gdk version to {0}...", newPinnedVersion);

            if (!File.Exists(gdkPinnedFilename))
            {
                throw new InvalidOperationException("Could not upgrade gdk version as the file, " +
                                                    $"{gdkPinnedFilename}, does not exist");
            }

            // Pin is always to develop in this case.
            File.WriteAllText(gdkPinnedFilename, $"{Common.DevelopBranch} {newPinnedVersion}");

            gitClient.StageFile(gdkPinnedFilename);
        }
예제 #6
0
        public static bool UpdatePluginFile(GitClient gitClient, string version, string pluginFileName, NLog.Logger Logger)
        {
            using (new WorkingDirectoryScope(gitClient.RepositoryPath))
            {
                var pluginFilePath = Directory.GetFiles(".", pluginFileName, SearchOption.AllDirectories).First();
                if (File.Exists(pluginFilePath))
                {
                    Logger.Info("Updating {0}...", pluginFilePath);
                    var originalContents = File.ReadAllText(pluginFilePath);

                    JObject jsonObject;
                    using (var streamReader = new StreamReader(pluginFilePath))
                    {
                        jsonObject = JObject.Parse(streamReader.ReadToEnd());

                        if (!jsonObject.ContainsKey(Common.VersionKey) || !jsonObject.ContainsKey(VersionNameKey))
                        {
                            throw new InvalidOperationException($"Could not update the plugin file at '{pluginFilePath}', " + $"because at least one of the two expected keys '{Common.VersionKey}' and '{Common.VersionNameKey}' " + $"could not be found.");
                        }

                        var oldVersion = (string)jsonObject[VersionNameKey];
                        if (ShouldIncrementPluginVersion(oldVersion, version))
                        {
                            jsonObject[VersionKey] = ((int)jsonObject[VersionKey] + 1);
                        }

                        // Update the version name to the new one
                        jsonObject[VersionNameKey] = version;
                    }

                    File.WriteAllText(pluginFilePath, jsonObject.ToString());

                    // If nothing has changed, return false, so we can react to it from the caller.
                    if (File.ReadAllText(pluginFilePath) == originalContents)
                    {
                        return(false);
                    }

                    gitClient.StageFile(pluginFilePath);
                    return(true);
                }

                throw new Exception($"Failed to update the plugin file. Argument: " + $"pluginFilePath: {pluginFilePath}.");
            }
        }
예제 #7
0
        public static bool UpdateChangeLog(GitClient gitClient, string version)
        {
            using (new WorkingDirectoryScope(gitClient.RepositoryPath))
            {
                if (File.Exists(ChangeLogFilename))
                {
                    var originalContents = File.ReadAllText(ChangeLogFilename);
                    var changelog        = File.ReadAllLines(ChangeLogFilename).ToList();
                    var releaseHeading   = string.Format(ChangeLogReleaseHeadingTemplate, version,
                                                         DateTime.Now);
                    var releaseIndex = changelog.FindIndex(line => IsMarkdownHeading(line, 2, $"[`{version}`] - "));
                    // If we already have a changelog entry for this release, replace it.
                    if (releaseIndex != -1)
                    {
                        changelog[releaseIndex] = releaseHeading;
                    }
                    else
                    {
                        // Add the new release heading under the "## Unreleased" one.
                        // Assuming that this is the first heading.
                        var unreleasedIndex = changelog.FindIndex(line => IsMarkdownHeading(line, 2));
                        changelog.InsertRange(unreleasedIndex + 1, new[]
                        {
                            string.Empty,
                            releaseHeading
                        });
                    }
                    File.WriteAllLines(ChangeLogFilename, changelog);

                    // If nothing has changed, return false, so we can react to it from the caller.
                    if (File.ReadAllText(ChangeLogFilename) == originalContents)
                    {
                        return(false);
                    }

                    gitClient.StageFile(ChangeLogFilename);
                    return(true);
                }
            }

            throw new Exception($"Failed to update the changelog. Arguments: " +
                                $"ChangeLogFilePath: {ChangeLogFilename}, Version: {version}, Heading template: {ChangeLogReleaseHeadingTemplate}.");
        }
예제 #8
0
        private void UpdatePackageJson(string packageFile, GitClient gitClient)
        {
            Logger.Info("Updating {0}...", packageFile);

            JObject jsonObject;

            using (var streamReader = new StreamReader(packageFile))
            {
                jsonObject = JObject.Parse(streamReader.ReadToEnd());

                if (jsonObject.ContainsKey(PackageJsonNameKey))
                {
                    var name = (string)jsonObject[PackageJsonNameKey];

                    if (name.StartsWith(PackageJsonDependenciesPrefix) &&
                        jsonObject.ContainsKey(PackageJsonVersionString))
                    {
                        jsonObject[PackageJsonVersionString] = options.Version;
                    }
                }

                if (jsonObject.ContainsKey(PackageJsonDependenciesString))
                {
                    var dependencies = (JObject)jsonObject[PackageJsonDependenciesString];

                    foreach (var property in dependencies.Properties())
                    // If it's an Improbable package and it's not a "file:" reference.
                    {
                        if (property.Name.StartsWith(PackageJsonDependenciesPrefix) &&
                            !((string)property.Value).StartsWith("file:"))
                        {
                            dependencies[property.Name] = options.Version;
                        }
                    }
                }
            }

            File.WriteAllText(packageFile, jsonObject.ToString());

            gitClient.StageFile(packageFile);
        }
예제 #9
0
        public static bool UpdateUnrealEngineVersionFile(GitClient client, List <string> versions)
        {
            using (new WorkingDirectoryScope(client.RepositoryPath))
            {
                if (!File.Exists(UnrealEngineVersionFile))
                {
                    throw new InvalidOperationException("Could not update the unreal engine file as the file " +
                                                        $"'{UnrealEngineVersionFile}' does not exist.");
                }
                var originalContents = File.ReadAllText(UnrealEngineVersionFile);
                File.WriteAllLines(UnrealEngineVersionFile, versions);

                // If nothing has changed, return false, so we can react to it from the caller.
                if (File.ReadAllText(UnrealEngineVersionFile) == originalContents)
                {
                    return(false);
                }

                client.StageFile(UnrealEngineVersionFile);
                return(true);
            }
        }
예제 #10
0
        private void UpdatePluginFile(string pluginFileName, GitClient gitClient)
        {
            using (new WorkingDirectoryScope(gitClient.RepositoryPath))
            {
                var pluginFilePath = Directory.GetFiles(".", pluginFileName, SearchOption.AllDirectories).First();

                Logger.Info("Updating {0}...", pluginFilePath);

                JObject jsonObject;
                using (var streamReader = new StreamReader(pluginFilePath))
                {
                    jsonObject = JObject.Parse(streamReader.ReadToEnd());

                    if (jsonObject.ContainsKey(VersionKey) && jsonObject.ContainsKey(VersionNameKey))
                    {
                        var oldVersion = (string)jsonObject[VersionNameKey];
                        if (ShouldIncrementPluginVersion(oldVersion, options.Version))
                        {
                            jsonObject[VersionKey] = ((int)jsonObject[VersionKey] + 1);
                        }

                        // Update the version name to the new one
                        jsonObject[VersionNameKey] = options.Version;
                    }
                    else
                    {
                        throw new InvalidOperationException($"Could not update the plugin file at '{pluginFilePath}', " +
                                                            $"because at least one of the two expected keys '{VersionKey}' and '{VersionNameKey}' " +
                                                            $"could not be found.");
                    }
                }

                File.WriteAllText(pluginFilePath, jsonObject.ToString());

                gitClient.StageFile(pluginFilePath);
            }
        }