切换到github ci
This commit is contained in:
47
.github/workflows/nodejs.yml
vendored
Normal file
47
.github/workflows/nodejs.yml
vendored
Normal file
@@ -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 }}
|
||||||
@@ -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"
|
|
||||||
|
|
||||||
40
build.sh
Normal file
40
build.sh
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user