【工具】自动打包工具GIT操作加入

dev_chengFeng
gaoxin 2021-06-01 10:41:03 +08:00
parent 3e12b64118
commit 70bc51f319
1 changed files with 40 additions and 14 deletions

View File

@ -3,6 +3,7 @@ using UnityEditor;
using System.IO;
using System;
using GameEditor.FrameTool;
using GameEditor.Util;
public class AutoPack : EditorWindow
{
@ -31,6 +32,8 @@ public class AutoPack : EditorWindow
static string ExportPackPath;
static string ScenePath;
static string ABPath;
static string APKPath;
static string PackTime;
// 判断是否要重新导出工程
static string[] ExportTypeList =
@ -178,15 +181,18 @@ public class AutoPack : EditorWindow
ExportAS(i);
ReplaceFromProject(i);
ReplaceConfigAndVersion(i);
CreateLogFile(i);
StartGradleBuild(i);
break;
case 1: // 只替换AB
ReplaceFromAB(i);
ReplaceConfigAndVersion(i);
CreateLogFile(i);
StartGradleBuild(i);
break;
case 2: // 只重新打包
ReplaceConfigAndVersion(i);
CreateLogFile(i);
StartGradleBuild(i);
break;
}
@ -194,6 +200,21 @@ public class AutoPack : EditorWindow
}
public static void CreateLogFile(int index)
{
APKPath = _MomPackPath + PackConfig[index][2] + "/APK/";
if (!Directory.Exists(APKPath))
{
Directory.CreateDirectory(APKPath);
}
PackTime = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
APKPath += PackTime;
if (!Directory.Exists(APKPath))
{
Directory.CreateDirectory(APKPath);
}
}
// 导出android 工程
public static void ExportAS(int index)
{
@ -333,29 +354,34 @@ public class AutoPack : EditorWindow
// 开始生成apk
private static void StartGradleBuild(int index)
{
EditorUtility.DisplayProgressBar("正在生成APK", "", 0.5f);
string apkPath = _MomPackPath + PackConfig[index][2] + "/APK/";
if (!Directory.Exists(apkPath))
{
Directory.CreateDirectory(apkPath);
}
string time = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
if (!Directory.Exists(apkPath + time))
{
Directory.CreateDirectory(apkPath + time);
}
GameEditor.Util.ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "gradlew assembleRelease>" + apkPath + time +"/_log.txt");
EditorUtility.DisplayProgressBar("正在生成APK", "", 0f);
GameEditor.Util.ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "gradlew assembleRelease>" + APKPath + "/_log.txt");
EditorUtility.DisplayProgressBar("正在导出APK", "", 0.5f);
EditorUtility.DisplayProgressBar("正在导出APK", "", 1f);
string apkFilePath = _MomPackPath + PackConfig[index][2] + "/build/outputs/apk/release/" + PackConfig[index][2] + "-release.apk";
if (File.Exists(apkFilePath))
{
File.Copy(apkFilePath, apkPath + time + "/" + PackConfig[index][2] + ".apk");
File.Copy(apkFilePath, APKPath + "/" + PackConfig[index][2] + ".apk");
}
Debug.Log(PackConfig[index][0] + ":打包完成");
EditorUtility.ClearProgressBar();
}
private static void GitUpdate(int index)
{
EditorUtility.DisplayProgressBar("正在更新母包", "", 0f);
ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "git pull>" + APKPath + "/_log.txt");
EditorUtility.ClearProgressBar();
}
private static void GitCommit(int index)
{
EditorUtility.DisplayProgressBar("正在提交修改", "", 0f);
ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "git add .>" + APKPath + "/_log.txt");
ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "git commit 'AutoPack"+ PackConfig[index][0]+" "+PackTime+"/"+ PackConfig[index][2] +".apk'");
EditorUtility.ClearProgressBar();
}
//private static void ExportXcode(string _sceneName)
//{
// PlayerSettings.productName = "太初行";