Beispiel #1
0
        /// <summary>
        /// Performs the command line build by using the passed command line arguments.
        /// </summary>
        private static void Build()
        {
            string publishPath, buildNumber, buildVersion, buildReporter, buildTarget, androidTextureCompression;

            Dictionary <string, string> commandToValueDictionary = GetCommandLineArguments();

            // Extract our arguments from dictionary
            commandToValueDictionary.TryGetValue(PublishPathCommand, out publishPath);
            commandToValueDictionary.TryGetValue(BuildNumberCommand, out buildNumber);
            commandToValueDictionary.TryGetValue(BuildVersionCommand, out buildVersion);
            commandToValueDictionary.TryGetValue(BuildReporterCommand, out buildReporter);
            commandToValueDictionary.TryGetValue(BuildTargetCommand, out buildTarget);
            commandToValueDictionary.TryGetValue(AndroidTextureCompressionCommand, out androidTextureCompression);


            if (!string.IsNullOrEmpty(buildReporter))
            {
                BuildReporter.Current = BuildReporter.CreateReporterByName(buildReporter);
            }

            try
            {
                if (!string.IsNullOrEmpty(buildNumber))
                {
                    BundleVersionResolver.BuildNumber = int.Parse(buildNumber);
                }
                if (!string.IsNullOrEmpty(buildVersion))
                {
                    BundleVersionResolver.PrettyVersion = buildVersion;
                }

                if (string.IsNullOrEmpty(buildTarget))
                {
                    BuildReporter.Current.Log("No target was specified for this build.", BuildReporter.MessageSeverity.Error);
                }
                else
                {
                    BuildTarget            parsedBuildTarget      = (BuildTarget)Enum.Parse(typeof(BuildTarget), buildTarget);
                    MobileTextureSubtarget?parsedTextureSubtarget = null;
                    if (!string.IsNullOrEmpty(androidTextureCompression))
                    {
                        parsedTextureSubtarget = (MobileTextureSubtarget)Enum.Parse(typeof(MobileTextureSubtarget), androidTextureCompression);
                    }

                    BundleVersionResolver.Setup(parsedBuildTarget);

                    Builder.Build(parsedBuildTarget, publishPath, parsedTextureSubtarget);
                }
            }
            catch (Exception e)
            {
                BuildReporter.Current.Log(e.Message, BuildReporter.MessageSeverity.Error);
            }
        }
Beispiel #2
0
        public static BuildTargetResult CommitChanges(BuildTargetContext c)
        {
            Cmd("git", "add", ".")
            .Execute()
            .EnsureSuccessful();

            string userName = s_config.UserName;
            string email    = s_config.Email;

            Cmd("git", "commit", "-m", PullRequestTitle, "--author", $"{userName} <{email}>")
            .EnvironmentVariable("GIT_COMMITTER_NAME", userName)
            .EnvironmentVariable("GIT_COMMITTER_EMAIL", email)
            .Execute()
            .EnsureSuccessful();

            string remoteUrl        = $"github.com/{s_config.GitHubOriginOwner}/{s_config.GitHubProject}.git";
            string remoteBranchName = $"UpdateDependencies{DateTime.UtcNow.ToString("yyyyMMddhhmmss")}";
            string refSpec          = $"HEAD:refs/heads/{remoteBranchName}";

            string logMessage = $"git push https://{remoteUrl} {refSpec}";

            BuildReporter.BeginSection("EXEC", logMessage);

            CommandResult pushResult =
                Cmd("git", "push", $"https://{userName}:{s_config.Password}@{remoteUrl}", refSpec)
                .QuietBuildReporter() // we don't want secrets showing up in our logs
                .CaptureStdErr()      // git push will write to StdErr upon success, disable that
                .CaptureStdOut()
                .Execute();

            var message = logMessage + $" exited with {pushResult.ExitCode}";

            if (pushResult.ExitCode == 0)
            {
                BuildReporter.EndSection("EXEC", message.Green(), success: true);
            }
            else
            {
                BuildReporter.EndSection("EXEC", message.Red().Bold(), success: false);
            }

            pushResult.EnsureSuccessful(suppressOutput: true);

            c.SetRemoteBranchName(remoteBranchName);

            return(c.Success());
        }
Beispiel #3
0
        public static BuildTargetResult CommitChanges(BuildTargetContext c)
        {
            CommandResult statusResult = Cmd("git", "status", "--porcelain")
                                         .CaptureStdOut()
                                         .Execute();

            statusResult.EnsureSuccessful();

            bool hasModifiedFiles       = !string.IsNullOrWhiteSpace(statusResult.StdOut);
            bool hasUpdatedDependencies = c.GetDependencyInfos().Where(d => d.IsUpdated).Any();

            if (hasModifiedFiles != hasUpdatedDependencies)
            {
                return(c.Failed($"'git status' does not match DependencyInfo information. Git has modified files: {hasModifiedFiles}. DependencyInfo is updated: {hasUpdatedDependencies}."));
            }

            if (!hasUpdatedDependencies)
            {
                c.Warn("Dependencies are currently up to date");
                return(c.Success());
            }

            string userName = s_config.UserName;
            string email    = s_config.Email;

            string commitMessage = GetCommitMessage(c);

            Cmd("git", "commit", "-a", "-m", commitMessage, "--author", $"{userName} <{email}>")
            .EnvironmentVariable("GIT_COMMITTER_NAME", userName)
            .EnvironmentVariable("GIT_COMMITTER_EMAIL", email)
            .Execute()
            .EnsureSuccessful();

            string remoteUrl        = $"github.com/{s_config.GitHubOriginOwner}/{s_config.GitHubProject}.git";
            string remoteBranchName = $"UpdateDependencies{DateTime.UtcNow.ToString("yyyyMMddhhmmss")}";
            string refSpec          = $"HEAD:refs/heads/{remoteBranchName}";

            string logMessage = $"git push https://{remoteUrl} {refSpec}";

            BuildReporter.BeginSection("EXEC", logMessage);

            CommandResult pushResult =
                Cmd("git", "push", $"https://{userName}:{s_config.Password}@{remoteUrl}", refSpec)
                .QuietBuildReporter() // we don't want secrets showing up in our logs
                .CaptureStdErr()      // git push will write to StdErr upon success, disable that
                .CaptureStdOut()
                .Execute();

            var message = logMessage + $" exited with {pushResult.ExitCode}";

            if (pushResult.ExitCode == 0)
            {
                BuildReporter.EndSection("EXEC", message.Green(), success: true);
            }
            else
            {
                BuildReporter.EndSection("EXEC", message.Red().Bold(), success: false);
            }

            pushResult.EnsureSuccessful(suppressOutput: true);

            c.SetRemoteBranchName(remoteBranchName);

            return(c.Success());
        }