前端项目样例代码

~/.github/workflows/build.yml

name: Build

on:
  push:
    branches:
      # 只在master上push触发部署
      - master  
    # 下列文件的变更不触发部署,可以自行添加
    paths-ignore:   
      - README.md

jobs:
  build-production:
    name: Build
    # 使用ubuntu系统镜像运行自动化脚本
    runs-on: ubuntu-latest   
    strategy:
      matrix:
        node-version: [12.x] # 配置所需node版本

    # 自动化步骤
    steps:
    # 检出仓库副本
    - uses: actions/checkout@v2   
    
    # 规定node.js版本(可不配置)
    - name: Use Node.js ${{ matrix.node-version }} 
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}

    # 安装依赖
    - name: Install dependencies  
      run: npm install

    # 打包代码
    - name: Build                 
      run: npm run build

    # 将文件内容递归复制到远端
    - name: Copy folder content recursively to remote   
      uses: garygrossgarten/github-action-scp@release
      with:
        local: dist
        # remote: test 实为 ~/test 即 /root/test 地址在userhome下的test目录
        remote: test
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USER }}
        password: ${{ secrets.PASSWORD }}

    # 在远端执行命令
    # - name: Restart server   
    #   uses: appleboy/ssh-action@master
    #   with:
    #     host: ${{ secrets.HOST }}
    #     username: ${{ secrets.USER }}
    #     key: ${{ secrets.KEY }}
    #     # 远端执行脚本
    #     script: |
    #       cd /www
    #       cd /www

相关文档

GitHub Actions guides
GitHub Actions 入门教程

Last modification:March 30, 2021
If you think my article is useful to you, please feel free to appreciate