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

Time:12-23

I´m tring to config a GitHub Action to deploy my application to SFTP file.

My application has 6700 files and I would like to upload only changed/commited files.

How can I remove unchanged and/or uncommited files before upload to SFTP?

This way, my one file modification deploy would be so faster than upload 6k files.

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/[email protected]
        with:
          username: 'deploy_user'
          server: 'server_ip'
          ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
          local_path: './www/*'
          remote_path: '/www'
          args: '-o ConnectTimeout=10'

CodePudding user response:

To list down all the files that are updated/commited in the given commit, you can use this command :

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

Then you can use this to delete all the files that are not on this list. This needs some bash digging. One hack I can think of is to make tmp dir to copy updated files and only upload these files.

  • Related