hu hao 5 лет назад
Родитель
Сommit
e4029bbf8a
4 измененных файлов с 66 добавлено и 29 удалено
  1. 5 5
      .gitlab-ci.yml
  2. 15 22
      ci/executeCommand.sh
  3. 19 2
      ci/judgePush.sh
  4. 27 0
      resources/scripts/git-hooks/pre-push

+ 5 - 5
.gitlab-ci.yml

@@ -25,6 +25,8 @@ test:
     - testwas
   script:
     - echo "run test....."
+    - path=`pwd`
+#    - sudo bash ci/judgePush.sh $path
 #    - vendor/bin/phpunit --testsuite=Unit
 
 deploy:
@@ -32,10 +34,8 @@ deploy:
   tags:
     - testwas
   script:
-#    - echo "deploy ...."
-    - path=`pwd`
-#    - sudo bash ci/judgePush.sh $path
-    - cd /var/www/testwas && git pull
-    - sudo bash ci/executeCommand.sh $path
+    - echo "deploy ...."
+#    - cd /var/www/testwas && git pull
+#    - sudo bash ci/executeCommand.sh $path
 #  only:
 #    - master

+ 15 - 22
ci/executeCommand.sh

@@ -1,32 +1,25 @@
 #!/bin/bash
 
-#project_path=/var/www/testwas
-#update_path=/var/www/update
+
+update_path=/var/www/update
 #重启队列
 #sudo bash runServes.sh
-#进入项目目录
-#cd $1
-#将项目文件中3分钟之前改动的文件存到update文件
-#find -mmin -3 |xargs -I {} cp {} -u -t $update_path
 
-#for file in `ls $update_path`
-#    do
-#        if test -f $file
-#        then
-#            echo "file:  $file"
-#        elif test -d $file
-#        then
-#            echo "path: $file"
-#        fi
-#    done
 
-for file in `ls /var/www/update`
-    do
-        if [ "Haozi"!="$file" ]; then
-            echo "$file haozi"
-        elif [ "index"==$file ]; then
-            echo "$file"
+
+# shellcheck disable=SC2045
+# shellcheck disable=SC2006
+for file in `ls $update_path`
+     do
+        if [ "composer.json" = "$file" ]; then
+            sudo composer install
+        elif [ "package.json" == "$file" ]; then
+            sudo yarn install
+        elif [ "resources" == "$file" ]; then
+            sudo yarn run prod
             else
                 echo "11"
         fi
     done
+
+

+ 19 - 2
ci/judgePush.sh

@@ -1,4 +1,21 @@
 #!/bin/bash
 
-echo $1
-cd $1
+#push 变动文件
+update_path=/var/www/update
+#git 文件路径
+path=$1
+# shellcheck disable=SC2164
+cd "$path"
+#将项目文件中3分钟之前改动的文件存到update文件
+# shellcheck disable=SC2038
+# shellcheck disable=SC2185
+find -mmin -3 |xargs -I {} cp {} -u -t $update_path
+
+# shellcheck disable=SC2045
+# shellcheck disable=SC2006
+for file in `ls $update_path`
+     do
+        if [ "composer.json" = "$file" ]; then
+            sudo composer install
+        fi
+    done

+ 27 - 0
resources/scripts/git-hooks/pre-push

@@ -0,0 +1,27 @@
+#!/usr/bin/php
+
+<?php
+
+// 获取应用名称
+$projectName = basename(getcwd());
+
+echo PHP_EOL;
+echo '开始执行单元测试...'.PHP_EOL;
+exec('vendor/bin/phpunit --exclude-group online --stop-on-failure', $output, $returnCode);
+
+printf("测试结果: ", $projectName);
+echo PHP_EOL;
+
+if ($returnCode !== 0) {
+    printf(" ( %s ) %s%2\$s", end($output), PHP_EOL);
+    printf(" x 测试不通过,Git Push 已终止!\n");
+
+    // 停止 Git
+    exit(1);
+}
+
+echo ' √ 测试通过!'.PHP_EOL;
+echo PHP_EOL;
+
+// 继续执行 Git
+exit(0);