自动部署到云服务器 #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic workflow to help you get started with Actions | |
name: Deploy My Server | |
on: | |
push: | |
branches: [ master ] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v2 | |
- name: use Node.js | |
# 使用action库 actions/setup-node安装node | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 16.x | |
# 安装依赖 | |
- name: npm install | |
run: npm install | |
# 打包 | |
- name: npm build | |
run: npm run build | |
# 部署到服务器 | |
- name: deploy | |
uses: easingthemes/ssh-deploy@v2.1.1 | |
env: | |
# 本地.ssh文件下的私钥id_rsa,存在secrets的PRIVATE_KEY中 | |
SSH_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | |
# 复制操作的参数。"-avzr --delete"意味部署时清空服务器目标目录下的文件 | |
ARGS: "-avzr --delete" | |
# 源目录,相对于$GITHUB_WORKSPACE根目录的路径 | |
SOURCE: "./public" | |
# 服务器域名/IP | |
REMOTE_HOST: ${{ secrets.HOST }} | |
# 服务器默认用户名为root | |
REMOTE_USER: "root" | |
# 目标目录 | |
TARGET: '/usr/local/www/whyta/dist' | |
# 排除目录 | |
EXCLUDE: "/node_modules/" | |