zoukankan      html  css  js  c++  java
  • PHP打包配置界面

    总目录:Mac + Apache + PHP+打包脚本 = Mac自动化打包

    PHP主要分为两个文件:展示界面(.html)和逻辑处理(.php),二者可以单独出现

    这里需要HTML文件供测试选择配置,PHP文件执行操作

    其中:1.根据界面选择的是否git拉取代码;2:输入的用户名密码进行简单的验证(防止恶意打包,导致电脑压力过大);
    3.根勾选的是否编译unity,是需要debug包还是release包还是都需要,4,是否是内网包
    因为有不同渠道的包,所以不同渠道不同配置,根据这里的勾选和填写,在php文件里动态生成配置文件

    现附上网站目录结构,php里面很多文件路劲需要根据目录结构调整
    ![image.png](https://upload-images.jianshu.io/upload_images/8623295-23ff9e88351d457a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    其中:Apache文件夹是网站根目录,对外可见
    basketball是打包支持目录,对外不可见

    php详解:

    #一.文件操作

    $RootDir = $_SERVER['DOCUMENT_ROOT'];//当前目录
    $gitfileDir = $RootDir.'../../basketball/baketbuild.command';//文件路径(../代表向上一个层级)
    $gitfp = fopen($gitfileDir, "w") or die("Unable to open file!");//打开文件(注意权限)
    
    $txt = "文件内容\n";//一定要换行符
    fwrite($gitfp, $txt);//写入
    fclose($gitfp);//关闭命令文件

    #二.执行指令

    passthru("指令");
    system("指令");
    两者都可以


    下面是PHP打包设置界面主要进行的任务
    ##1.是否git拉取代码,拉取的话生成Git指令

    $timenow = date('Y-m-d-H-i-s');
    $needgit = trim($_POST['needgit']);
    if($needgit == "yes"){
    $branchname = trim($_POST['branchname']);
    //生成git命令
    $txt = "cd /Users/admin/BasketBallMaster\n";//打开需要进行Git操作的git库,git项目目录
    fwrite($gitfp, $txt);
    $txt = "git checkout --track origin/";//根据分支名拉取远程分支,....如果本地有,会拉取失败,但会切至目标分支
    fwrite($gitfp, $txt);
    $txt = $branchname;
    fwrite($gitfp, $txt);
    $txt = " >> /Users/admin/Sites/Apache/log/";
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);//将拉取输入到一个文件>> 后面跟输出路径名
    $txt = "git checkout . && git clean -fd >> /Users/admin/Sites/Apache/log/";//丢弃本地改动
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);
    $txt = "git pull >> /Users/admin/Sites/Apache/log/";//拉取最新代码
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);
    }


    ##2.根据当前时间获取个唯一字符串,动态生成指令使打包日志生成到指定文件

    //生成调用打包命令
    $txt = "cd /Users/admin/Sites/basketball\n";//打开打包脚本路径
    fwrite($gitfp, $txt);
    $txt = "python ./autobuild.py >> /Users/admin/Sites/Apache/log/";//执行打包脚本,并输出日志到文件
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);

    上面2步完成后,生成的文件内容如下
    ![image.png](https://upload-images.jianshu.io/upload_images/8623295-60c4922f4e45f54c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


    打包的脚本里面是根据配置文件进行打包的,所以原题同上,动态写文件内容,生成配置文件如图
    ![image.png](https://upload-images.jianshu.io/upload_images/8623295-60273e67fa8669b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

    ##3.查看日志
    因为开始打包后,需要给打包人员查看打包进度,所以跳转至一个日志的界面,就一个php
    同时将刚才设置的日志文件名字发过去,
    log.php主要功能就是一定时间加载下对应的日志文件

    //开始打包
    echo "已经开始打包!";
    passthru("open ../basketball/baketbuild.command");//执行动态生成的指令文件
    header('location:log.php?logname='.$timenow);//跳转至显示日志界面


    下面贴上三个文件的详细代码
    HTML具体代码如下

    <form action="BasketPack.php" method="post">
    <fieldset>
    <legend>UserInfo</legend>
    <ul>
    <li>
    <label>userName:</label>
    <input type="text" name="username">
    </li>
    <li>
    <label>passWord:</label>
    <input type="password" name="password">
    </li>
    </ul>
    </fieldset>
    <fieldset>
    <legend>Code</legend>
    <ul>
    <li>
    <label>need pull new code from git?</label>
    <input type="checkbox" name="needgit" value="yes">
    </li>
    <li>
    <label>if need pull,input git Branch Name:</label>
    <input type="text" name="branchname" value="master">
    </li>
    </ul>
    </fieldset>
    <fieldset>
    <legend>PackInfo_Basketball</legend>
    <legend>China_Appstore</legend>
    <ul>
    <li>
    <label>compile unity:</label>
    <input type="checkbox" name="appstore_unity" value="yes">
    </li>
    <li>
    <label>debug:</label>
    <input type="checkbox" name="appstore_debug" value="yes">
    </li>
    <li>
    <label>release:</label>
    <input type="checkbox" name="appstore_realse" value="yes">
    </li>
    <li>
    <label>versions:</label>
    <input type="text" name="appstore_versions" value="0.0.1">
    </li>
    <li>
    <label>inNet:</label>
    <input type="checkbox" name="appstore_innet" value="yes">
    </li>
    </ul>
    
    <legend>China_Preplay</legend>
    <ul>
    <li>
    <label>compile unity:</label>
    <input type="checkbox" name="preplay_unity" value="yes">
    </li>
    <li>
    <label>debug:</label>
    <input type="checkbox" name="preplay_debug" value="yes">
    </li>
    <li>
    <label>release:</label>
    <input type="checkbox" name="preplay_realse" value="yes">
    </li>
    <li>
    <label>versions:</label>
    <input type="text" name="preplay_versions" value="0.0.1">
    </li>
    </ul>
    <legend>Pack</legend>
    <ul>
    <li>
    <label></label>
    <input type="submit" name="BasketPack" value="BeginPack" style="200px;background-color: #7ED321;color: #0000FF;">
    </li>
    </ul>
    </fieldset>
    </form>

    php代码如下

    <?php
    header('Content-type:text/html; charset=utf-8');
    //验证用户信息
    if (isset($_POST['BasketPack'])) {
    # 接收用户的登录信息
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    // 判断提交的登录信息
    if (($username == '') || ($password == '')) {
    // 若为空,视为未填写,提示错误,并3秒后返回登录界面
    echo "用户名或密码不能为空,请重新填写登录信息!";
    } elseif (($username != '用户名') || ($password != '密码')) {
    # 用户名或密码错误,同空的处理方式
    echo "用户名或密码错误,请重新填写登录信息!";
    } elseif (($username = '用户名') && ($password = '密码')) {
    # 用户名和密码都正确,
    echo "用户名密码正确!\n";
    $timenow = date('Y-m-d-H-i-s');
    
    $RootDir = $_SERVER['DOCUMENT_ROOT'];
    $gitfileDir = $RootDir.'../../basketball/baketbuild.command';
    $gitfp = fopen($gitfileDir, "w") or die("Unable to open file!");
    
    $txt = "#!/bin/sh\nbasepath=$(cd `dirname $0`; pwd)\necho $basepath\ncd $basepath\npwd\n";
    fwrite($gitfp, $txt);
    
    $needgit = trim($_POST['needgit']);
    if($needgit == "yes"){
    $branchname = trim($_POST['branchname']);
    //生成git命令
    $txt = "cd /Users/admin/BasketBallMaster\n";
    fwrite($gitfp, $txt);
    $txt = "git checkout --track origin/";
    fwrite($gitfp, $txt);
    $txt = $branchname;
    fwrite($gitfp, $txt);
    $txt = " >> /Users/admin/Sites/Apache/log/";
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);
    $txt = "git checkout . && git clean -fd >> /Users/admin/Sites/Apache/log/";
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);
    $txt = "git pull >> /Users/admin/Sites/Apache/log/";
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);
    }
    
    //生成调用打包命令
    $txt = "cd /Users/admin/Sites/basketball\n";
    fwrite($gitfp, $txt);
    $txt = "python ./autobuild.py >> /Users/admin/Sites/Apache/log/";
    fwrite($gitfp, $txt);
    $txt = $timenow;
    fwrite($gitfp, $txt);
    $txt = ".txt\n";
    fwrite($gitfp, $txt);
    
    fclose($gitfp);//关闭命令文件
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    //更新配置文件
    $fileDir = $RootDir.'../../basketball/Untitled.conf';
    $fp = fopen($fileDir, "w") or die("Unable to open file!");
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    //国内官网(内网)
    $txt = "[china_appstore]\n";
    fwrite($fp, $txt);
    $appstore_unity = trim($_POST['appstore_unity']);
    if($appstore_unity == "yes"){
    $txt = "need_compile = true\n";
    }else{
    $txt = "need_compile = false\n";
    }
    fwrite($fp, $txt);
    $appstore_debug = trim($_POST['appstore_debug']);
    $appstore_realse = trim($_POST['appstore_realse']);
    if($appstore_debug == "yes" || $appstore_realse == "yes"){
    $txt = "need_export = true\n";
    fwrite($fp, $txt);
    if($appstore_debug == "yes" && $appstore_realse == "yes"){
    $txt = "configuration = both\n";
    }else if($appstore_debug == "yes"){
    $txt = "configuration = debug\n";
    }else{
    $txt = "configuration = release\n";
    }
    fwrite($fp, $txt);
    }else{
    $txt = "need_export = false\n";
    fwrite($fp, $txt);
    $txt = "configuration = debug\n";
    fwrite($fp, $txt);
    }
    $appstore_versions = trim($_POST['appstore_versions']);
    $txt = "game_version =";
    fwrite($fp, $txt);
    $txt = $appstore_versions;
    fwrite($fp, $txt);
    $txt = "\nbuild_version =";
    fwrite($fp, $txt);
    $txt = $appstore_versions;
    fwrite($fp, $txt);
    $appstore_innet = trim($_POST['appstore_innet']);
    if($appstore_innet == "yes"){//内网
    $txt = "\nsave_dir =内网测试\n";
    fwrite($fp, $txt);
    $txt = "\ninnet =true\n";
    fwrite($fp, $txt);
    }else{
    $txt = "\nsave_dir =release\n";
    fwrite($fp, $txt);
    $txt = "\ninnet =false\n";
    fwrite($fp, $txt);
    }
    $txt = "\npro_dir =/iOSBuild/Basketball/proj_appstore\nsign_dev =iPhone Developer: Xiaodong Jia (4W6N9AXUN8)\nprofile_dev =/iOSBuild/key/china/dev.mobileprovision\nsign_dis =iPhone Distribution: Gala Sports Technology Limited (GBXM95E8Y2)\nprofile_dis =/iOSBuild/key/china/basketballMaster_dis.mobileprovision\n";
    fwrite($fp, $txt);
    $txt = "###################################################################################################\n";
    fwrite($fp, $txt);
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    //先锋服
    $txt = "[china_preplay]\n";
    fwrite($fp, $txt);
    $preplay_unity = trim($_POST['preplay_unity']);
    if($preplay_unity == "yes"){
    $txt = "need_compile = true\n";
    }else{
    $txt = "need_compile = false\n";
    }
    fwrite($fp, $txt);
    $preplay_debug = trim($_POST['preplay_debug']);
    $preplay_realse = trim($_POST['preplay_realse']);
    if($preplay_debug == "yes" || $preplay_realse == "yes"){
    $txt = "need_export = true\n";
    fwrite($fp, $txt);
    if($preplay_debug == "yes" && $preplay_realse == "yes"){
    $txt = "configuration = both\n";
    }else if($preplay_debug == "yes"){
    $txt = "configuration = debug\n";
    }else{
    $txt = "configuration = release\n";
    }
    fwrite($fp, $txt);
    }else{
    $txt = "need_export = false\n";
    fwrite($fp, $txt);
    $txt = "configuration = debug\n";
    fwrite($fp, $txt);
    }
    $preplay_versions = trim($_POST['preplay_versions']);
    $txt = "game_version =";
    fwrite($fp, $txt);
    $txt = $preplay_versions;
    fwrite($fp, $txt);
    $txt = "\nbuild_version =";
    fwrite($fp, $txt);
    $txt = $preplay_versions;
    fwrite($fp, $txt);
    $txt = "\nsave_dir =先锋服\n";
    fwrite($fp, $txt);
    $txt = "\ninnet =false\n";
    fwrite($fp, $txt);
    
    $txt = "###################################################################################################\n";
    fwrite($fp, $txt);
    //配置文件写入成功
    fclose($fp);//关闭文件
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    //开始打包
    echo "已经开始打包!";
    passthru("open ../basketball/baketbuild.command");
    header('location:log.php?logname='.$timenow);
    }
    }
    ?>
    ```
    loh.php,加载展示对应的日志文件
    ```
    <?php
    header('Content-type:text/html; charset=utf-8');
    echo "正在打包.....<br>";
    $logname = trim($_GET['logname']);
    if ($logname == '') {
    // 若为空,视为未填写,提示错误,并3秒后返回登录界面
    exit;
    }else{
    $file_path = 'log/'.$logname.'.txt';
    if(file_exists($file_path)){
    $welcomefile=file($file_path); //返回数组的内容
    foreach($welcomefile as $v){
    echo $v.'<br>';
    }
    }
    
    //刷新页面
    echo ("<script type=\"text/javascript\">");
    echo ("function fresh_page()");
    echo ("{");
    echo ("window.scrollTo(0,document.body.scrollHeight);window.location.reload();");//重新加载界面
    echo ("}");
    echo ("setTimeout('fresh_page()',30000);");
    echo ("function move_fresh_page()");
    echo ("{");
    echo ("window.scrollTo(0,document.body.scrollHeight);");//自动化动到底
    echo ("}");
    echo ("setTimeout('move_fresh_page()',1000);");
    echo ("</script>");
    }
    ?>

    如有疑问,联系作者

    博客园:这个我不知道诶


     

     
  • 相关阅读:
    java之md5加密算法
    springboot之快速创建项目
    java之idea打jar包
    java只http改成https访问
    springboot之读取配置文件
    springboot之项目打包
    Git之fatal: remote origin already exists
    WebStorm ES6 语法支持设置和ES6语法的JS文件编译为ES5语法文件
    转 JavaScript里的数组转化新方法Array.From
    网页特殊符号HTML代码大全
  • 原文地址:https://www.cnblogs.com/Yongersblog/p/12454258.html
Copyright © 2011-2022 走看看