name: Release

on:
  push:
    branches:
      - main

jobs:
  Build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v2
        with:
          version: 8
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: pnpm
      - uses: szenius/set-timezone@v1.0
        with:
          timezoneLinux: Asia/Shanghai
      - name: Build
        run: |
          pnpm i
          pnpm build
          now=$(date +%c)
          sed -i "1a\\<!-- build time ${now} -->" dist/index.html
      - name: Release
        uses: appleboy/scp-action@v0.1.4
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}
          port: ${{ secrets.PORT }}
          source: dist
          target: ${{ secrets.SCPTARGET }}
          strip_components: 1
          rm: true

环境变量

HOST #服务器 IP

PORT #服务器 ssh 端口

USERNAME #ssh 登入用户名

OASSWORD #ssh 密码

也可使用私钥登录

- name: copy file via ssh key
  uses: appleboy/scp-action@v0.1.7
  with:
    host: ${{ secrets.HOST }}
    username: ${{ secrets.USERNAME }}
    port: ${{ secrets.PORT }}
    key: ${{ secrets.KEY }}
    source: dist
    target: ${{ secrets.SCPTARGET }}
    strip_components: 1
    rm: true

appleboy/scp-action: GitHub Action that copy files and artifacts via SSH.