这里主要介绍我在软件系统设计与分析使用的Github Actions部署。

  1. 为你的项目创建.github/workflows二级目录,就像这样。
    20240429164349
  2. 在目录下新建deploy.yml文件,内容如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    name: Frontend deploy
    on:
    push:
    branches:
    - main
    jobs:
    build:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - name: get env
    run: |
    cd NoBeiCi
    npm install
    npm run build
    - name: Deploy
    uses: cross-the-world/scp-pipeline@master
    with:
    host: ${{secrets.IP}}
    user: ${{secrets.USER}}
    pass: ${{secrets.PASSWORD}}
    connect_timeout: 10s
    local: "./NoBeiCi/dist/*"
    remote: "/data/frontend/"
  3. 在repo的setting中添加secrets,找到Secrets and variables中的Actions,新建配置中需要的secret如下。
    20240429164651
  4. 按照上面的配置就可以实现main分支修改后自动化部署,每次部署一般需要1-2分钟,Github Actions个人版每月免费200分钟,基本是够用的。