Esempio n. 1
0
        /// <summary>
        /// 2. 获取远程git的地址
        /// </summary>
        /// <returns></returns>
        private async Task <string> GetGitRemotePath()
        {
            var condition  = new TaskCondition();
            var remotePath = "";

            getProcessProxy.Input("git remote -v", (msgs) =>
            {
//                complete = true;
                condition.Value = true;
                // 格式:"origin	https://github.com/Chino66/UPM-Tool-Develop.git (fetch)"
                // 格式:"origin	[email protected]:Chino66/UPM-Tool-Develop.git  (fetch)"
                var ret = msgs.Dequeue();

                Match match = Regex.Match(ret, Pattern);
                if (match.Success)
                {
                    remotePath = match.Value;
                }
                else
                {
                    remotePath = "";
                    Debug.LogError($"远程仓库路径为空! {ret}");
                }
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            _gitInfo.RemotePath = remotePath;
            OutputLine($"2.远程仓库地址:{remotePath}\n");

            return(remotePath);
        }
Esempio n. 2
0
 /// <summary>
 /// 等待直到条件成立
 /// </summary>
 /// <param name="condition"></param>
 /// <returns></returns>
 public static async Task WaitUntilConditionSet(TaskCondition condition, int millisecondsDelay = 100)
 {
     while (condition.Value == false)
     {
         await Task.Delay(millisecondsDelay);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 3. 获取远程仓库所有tag标签
        /// </summary>
        /// <returns></returns>
        private async Task <string[]> GetGitTags(string remotePath)
        {
            var           condition = new TaskCondition();
            List <string> tagList   = new List <string>();

            getProcessProxy.Input($"git ls-remote {remotePath}", (msgs) =>
            {
                condition.Value = true;

                var content = "";

                while (msgs.Count > 0)
                {
                    var line = msgs.Dequeue();
                    tagList.Add(line);
                }
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            var tags = tagList.ToArray();

            _gitInfo.SetTags(tags);

            OutputLine($"3.版本标签:\n", true, true);

            for (int i = 0; i < _gitInfo.Versions.Count; i++)
            {
                OutputLine($"->tag:{_gitInfo.Versions[i]}\n", true, true);
            }

            return(tagList.ToArray());
        }
Esempio n. 4
0
        /// <summary>
        /// 4. 执行 git push origin upm --tags
        /// 推送标签
        /// </summary>
        /// <returns></returns>
        private async Task GitPushOrigin()
        {
            var condition = new TaskCondition();

            ShowTip($"执行:\"git push origin upm --tags\"...");

            getProcessProxy.Input("git push origin upm --tags",
                                  (msgs) => { condition.Value = true; }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            ShowTip($"执行:\"git push origin upm --tags\"完成");
        }
Esempio n. 5
0
        /// <summary>
        /// 1.1. 执行 git rev-parse --show-cdup 和 git rev-parse --show-prefix
        /// 检查当前路径(Unity项目根目录)和Git仓库根目录的深度和相对路径
        /// 如果是同一目录,则是空,否则有多少级就返回多少个"../"相对路径则是"xx/xx/xxx"
        /// </summary>
        /// <returns></returns>
        private async Task GitCheckCdupAndPrefixPath()
        {
            var condition = new TaskCondition(false);

            // 1. 检查深度
            var cmd = "git rev-parse --show-cdup";

            ShowTip($"执行:\"{cmd}\"...");
            var cdupPath = "";

            getProcessProxy.Input(cmd,
                                  (msgs) =>
            {
                condition.Value = true;
                cdupPath        = GetContent(msgs);
                cdupPath        = cdupPath.Replace("\n", "");
                cdupPath        = cdupPath.Replace("\t", "");
                _cdupPath       = cdupPath;
                Debug.Log($"Unity项目根目录和Git仓库根目录深度:{cdupPath}");
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            ShowTip($"执行:\"{cmd}\"完成");

            // 2. 检查相对路径
            condition.Value = false;
            cmd             = "git rev-parse --show-prefix";
            ShowTip($"执行:\"{cmd}\"...");
            var prefixPath = "";

            getProcessProxy.Input(cmd,
                                  (msgs) =>
            {
                condition.Value = true;
                prefixPath      = GetContent(msgs);
                prefixPath      = prefixPath.Replace("\n", "");
                prefixPath      = prefixPath.Replace("\t", "");
                _prefixPath     = prefixPath;
                Debug.Log($"Unity项目根目录和Git仓库根目录相对路径:{prefixPath}");
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            ShowTip($"执行:\"{cmd}\"完成");
        }
Esempio n. 6
0
        /// <summary>
        /// 3. 执行 git tag x.x.x upm
        /// 创建tag
        /// </summary>
        /// <returns></returns>
        private async Task GitCreateTagByVersion(string version)
        {
            var condition = new TaskCondition(false);

            ShowTip($"执行:\"git tag {version} upm\"...");

            getProcessProxy.Input($"git tag {version} upm",
                                  (msgs) =>
            {
                condition.Value = true;

                Debug.Log(GetContent(msgs));
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            ShowTip($"执行:\"git tag {version} upm\"完成");
        }
Esempio n. 7
0
        /// <summary>
        /// 2. 执行 git push
        /// 把git subtree split --rejoin...的merge推送到远端
        /// </summary>
        /// <returns></returns>
        private async Task GitPush()
        {
            var condition = new TaskCondition(false);

            var cmd = $"git push";

            ShowTip($"执行:\"{cmd}\"...");

            getProcessProxy.Input(cmd, (msgs) =>
            {
                condition.Value = true;
                Debug.Log(GetContent(msgs));
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            ShowTip($"执行:\"{cmd}\"完成");
        }
Esempio n. 8
0
        /// <summary>
        /// 1.2. 执行 cd levelPath
        /// 将cmd当前目录指向git仓库根目录
        /// </summary>
        /// <returns></returns>
        private async Task SetCmdPath(string levelPath)
        {
            var condition = new TaskCondition(false);

            if (levelPath.Contains("/") == false)
            {
                return;
            }

            var cmd = $"cd {levelPath}";

            ShowTip($"执行:\"{cmd}\"...");

            getProcessProxy.Input(cmd, (msgs) => { condition.Value = true; }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            ShowTip($"执行:\"{cmd}\"完成");
        }
Esempio n. 9
0
        /// <summary>
        /// package.json是否有修改,有修改且没有提交和推送,则不能进行发布
        /// </summary>
        private async Task <bool> CheckPackageJsonModify()
        {
            BoxReleasePanel.SetEnabled(false);

            var modify    = false;
            var condition = new TaskCondition(false);

            var cmd = $"git diff {_prefixPath}Assets/_package_/package.json";

            getProcessProxy.Input(cmd, (msgs) =>
            {
                condition.Value = true;

                var content = msgs.Dequeue();

                // 没有修改可能返回"\n"换行符
                if (content.Equals("\n"))
                {
                    modify = false;
                }
                // 有修改则返回:"diff --git a/Assets/_package_/package.json b/Assets/_package_/package.json"以及修改详情
                else
                {
                    modify = true;
                }
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            if (modify)
            {
//                Debug.Log("package.json有修改但没有提交和推送,完成后才能发布");
                ShowVersionCheckResult("package.json有修改且没有提交和推送,完成后才能发布", Color.red);
            }
            else
            {
//                Debug.Log("package.json已经提交了");
                ShowVersionCheckResult("package.json没有修改,可以发布了", Color.blue);
                BoxReleasePanel.SetEnabled(true);
            }

            return(!modify);
        }
Esempio n. 10
0
        /// <summary>
        /// 1. 执行 git subtree split --rejoin --prefix=Assets/_package_ --branch upm
        /// 分割目录,只对Assets/_package_下的内容加入分支
        /// </summary>
        /// <returns></returns>
        private async Task GitSubtreeSplit()
        {
            var condition = new TaskCondition(false);

            var cmd = $"git subtree split --rejoin --prefix={_prefixPath}Assets/_package_ --branch upm";

            ShowTip($"执行:\"{cmd}\"...");

            getProcessProxy.Input(cmd, (msgs) =>
            {
                condition.Value = true;

                // 执行成功则返回:一串哈希码
                Debug.Log(GetContent(msgs));
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            ShowTip($"执行:\"{cmd}\"完成");
        }
Esempio n. 11
0
        /// <summary>
        /// 1. 检测当前项目是否有git仓库(远程仓库),没有则需要自行创建并推送远程
        /// </summary>
        private async Task <string> GitPathCheck()
        {
            var path      = "";
            var condition = new TaskCondition(false);

            getProcessProxy.Input("git rev-parse --show-toplevel", (msgs) =>
            {
                condition.Value = true;
                var content     = "";
                while (msgs.Count > 0)
                {
                    var line = msgs.Dequeue();
                    if (!line.Contains(ProcessProxy.CommandReturnFlag))
                    {
                        content += line;
                    }
                }

                path = content.Equals(NotGitRepositoryMsg) ? "" : content;
            }, false);

            await TimeUtil.WaitUntilConditionSet(condition);

            // 是否有项目路径
            if (string.IsNullOrEmpty(path) == false)
            {
                // 有git仓库
                _gitInfo.Path = path;
                OutputLine($"1.项目路径:{path}\n");
            }
            else
            {
                // 没有git仓库,需要创建
                OutputLine("1.这个项目没有git仓库,请先给这个项目创建git仓库,再推送到远程仓库,然后在使用次工具\n");
            }

            return(path);
        }