GitHub 操作 - 如何在上传到 SFTP 服务器之前清理 unchanged/uncommited 文件

GitHub Actions - How clean up unchanged/uncommited files before upload to SFTP Server

我正在尝试配置 GitHub 操作以将我的应用程序部署到 SFTP 文件。

我的应用程序有 6700 个文件,我只想上传 changed/commited 个文件。

如何在上传到 SFTP 之前删除未更改的 and/or 未提交的文件?

这样,我的一个文件修改部署比上传 6k 文件快得多。

name: CI

on:
  push:
    branches: [ main ]

  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy Job
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 2
          
      - name: Deploy files
        uses: wlixcc/SFTP-Deploy-Action@v1.0
        with:
          username: 'deploy_user'
          server: 'server_ip'
          ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
          local_path: './www/*'
          remote_path: '/www'
          args: '-o ConnectTimeout=10'

要列出给定提交中 updated/committed 的所有文件,您可以使用此命令:

$ git diff-tree --no-commit-id --name-only -r $GITHUB_SHA
index.html
src/application.js

然后您可以使用它来删除所有不在此列表中的文件。这需要一些 bash 挖掘。我能想到的一种技巧是创建一个临时目录来复制更新的文件并只上传这些文件。