From 102908a86400351146405eb9c690d35b502816ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B5=B7?= Date: Tue, 21 Apr 2020 21:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=B0github=20ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/nodejs.yml | 47 ++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 31 ------------------------ build.sh | 40 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/nodejs.yml delete mode 100644 .gitlab-ci.yml create mode 100644 build.sh diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..d54ec57 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,47 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install -g @angular/cli + - run: bash build.sh + + - name: SCP + uses: appleboy/scp-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + port: ${{ secrets.SSH_PORT }} + source: "admin.tar,index.tar" + target: "/www/wwwroot/celess.cn" + + - name: Run SSH command + uses: garygrossgarten/github-action-ssh@v0.5.0 + with: + command: cd /www/wwwroot/celess.cn && bash deploy.sh + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + port: ${{ secrets.SSH_PORT }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 26b7ed1..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,31 +0,0 @@ -image: node:latest - -cache: - paths: - - node_modules/ - -deploy: - script: - # build - - npm install -g @angular/cli - - cd index && npm install - - ng build --prod - - cd ./dist/index/ && tar -cf index.tar ./* - - cp index.tar ../../../ - # build - - cd ../../../admin && npm install - - ng build --prod - - cd ./dist/admin/ && sed '6s/\"\/\"/\"\/admin\/\"/g' index.html > index.txt && cp index.txt index.html - - cd .. && tar -cf admin.tar ./admin/ - - cp admin.tar ../../ && cd ../../ - # deploy - - eval $(ssh-agent -s) - - ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 --decode) - - mkdir -p ~/.ssh - - chmod 700 ~/.ssh - - ssh-keyscan celess.cn >> ~/.ssh/known_hosts - - chmod 644 ~/.ssh/known_hosts - - - scp index.tar admin.tar root@celess.cn:/www/wwwroot/celess.cn - - ssh root@celess.cn "cd /www/wwwroot/celess.cn && bash deploy.sh" - diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..5b1956f --- /dev/null +++ b/build.sh @@ -0,0 +1,40 @@ +#!/bin/sh +basePath=$(pwd) + +$(hash node 2>/dev/null) +if ! [ $? ]; then + echo -e "\t\t请先安装nodejs -------> https://nodejs.org/" + exit 1 +else + echo -e "\t\t nodejs\t\t $(node --version)" +fi + +$(hash npm 2>/dev/null) +if ! [ $? ]; then + echo -e "\t\t Can't find command npm" + exit 1 +else + echo -e "\t\t npm\t\t $(npm --version)" +fi + +$(hash ng 2>/dev/null) +if ! [ $? ]; then + echo -e "\t\tinstall angular cli to build the project" + npm install -g @angular/cli +else + echo -e "\t\t angular-cli\t\t $(ng --version)" +fi + +# index +echo -e "\t\tBuild for index page " +cd ./index && npm install && ng build --prod + +cd ./dist/index/ && tar -cf index.tar ./* && cp index.tar $basePath + +cd "$basePath" + +# admin +echo -e "\t\tBuild for admin page " +cd $basePath/admin && npm install && ng build --prod +cd ./dist/admin/ && sed '6s/\"\/\"/\"\/admin\/\"/g' index.html > index.txt && cp index.txt index.html + cd .. && tar -cf admin.tar ./admin/ && cp admin.tar $basePath