Code Monkey home page Code Monkey logo

lftp-mirror-action's Introduction

lftp-mirror-action

🚀 GitHub action to mirror files via SFTP.

Table of Contents

Usage

name: Deploy via SFTP
on:
  push:
    branches:
      - main
jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    if: github.event_name == 'push'
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Deploy files via SFTP
        uses: pressidium/lftp-mirror-action@v1
        with:
          # SFTP credentials
          host: ${{ secrets.SFTP_HOST }}
          port: ${{ secrets.SFTP_PORT }}
          user: ${{ secrets.SFTP_USER }}
          pass: ${{ secrets.SFTP_PASS }}
          # lftp settings
          onlyNewer: true
          settings: 'sftp:auto-confirm=yes'
          # Mirror command options
          localDir: '.'
          remoteDir: '/var/www/html/example.com/public'
          reverse: true
          ignoreFile: '.lftp_ignore'
          options: '--verbose'

Inputs

Parameter Description Required Default
host The hostname of the SFTP server Yes N/A
port The port of the SFTP server No '22'
user The username to use for authentication Yes N/A
pass The password to use for authentication Yes N/A
forceSSL Refuse to send password in clear when server does not support SSL No 'true'
verifyCertificate Verify server’s certificate to be signed by a known Certificate Authority No 'true'
fingerprint Key fingerprint of the host we want to connect to No ''
onlyNewer Only transfer files that are newer than the ones on the remote server No 'true'
restoreMTime Restore the modification time of the files No 'true'
parallel Number of parallel transfers No '1'
settings Any additional lftp settings to configure No ''
localDir The local directory to copy from (assuming reverse is set to true) No '.'
remoteDir The remote directory to copy to (assuming reverse is set to true) No '/var/www/html/'
reverse Whether to copy from the remote to the local or the other way around No 'true'
ignoreFile The name of the file to use as the ignore list No '.lftp_ignore'
options Any additional mirror command options to configure No ''

Fingerprint

Omitting the fingerprint input, defaults to accepting any fingerprint (i.e. automatically adding the host/port to the known_hosts file)

Restoring modification times

⚠️ Read this section if lftp-mirror-action uploads all files every time it runs.

Git does not preserve the original modification time of committed files. When repositories are cloned, branches are checked out, etc., the modification time of the files is updated to the current time. This means that the modification time of the files on the GitHub runner will always be newer than the files on the SFTP server, which will result in the mirror command always uploading all files (since lftp determines whether a file has changed based on its file size and timestamp).

To prevent this, if onlyNewer is set to true, we restore the modification time of the files based on the date of the most recent commit that modified them. You can disable this behavior by setting restoreMTime to false (useful if you've already run an action like git-restore-mtime-action in your GitHub Actions workflow).

If you're using actions/checkoutv2 you must set fetch-depth to 0 in order to fetch the entire Git history.

Bugs & Features

If you've spotted any bugs, or would like to request additional features from this GitHub Action, please open an issue.

License

The MIT License, check the LICENSE file.

lftp-mirror-action's People

Contributors

over-engineer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

leek

lftp-mirror-action's Issues

lftp-mirror-action uploads all files every time it runs despite setting "onlyNewer: true"

Hi everyone,

I read the section https://github.com/pressidium/lftp-mirror-action#restoring-modification-times, but I'm not sure I understand it correctly. Since I still encounter the issue that all my files are being uploaded every time, even after adding "onlyNewer: true". I'm also not sure if I need to add "fetch-depth: 0" and if this is connected to the issue. It added it and still same issue with uploading all files instead of only newer files.

Please see my main.yaml below. Do you have any suggstions what I am missing?

on: push
name: Publish to IONOS
jobs:
  web-deploy:
    name: HN MVP Deploy
    runs-on: ubuntu-latest
    steps:
    - name: Get latest code
      uses: actions/checkout@v3

    - name: Sync files
      uses: pressidium/lftp-mirror-action@v1
      with:
        host: ${{ secrets.FTP_SERVER }}
        port: 22
        user: ${{ secrets.FTP_USERNAME }}
        pass: ${{ secrets.FTP_PASSWORD }}
        # lftp settings
        onlyNewer: true
        # Mirror command options
        localDir: '.'
        remoteDir: './HN'
        reverse: true

Thank you in advance!

onlyDifferent input parameter?

I have a suggestion. Is it possible to add an input parameter similar to onlyNewer but instead of uploading files with a more recent modification date upload files if the modification date has simply changed?

In my case, I'm using this in a workflow to deploy theme files to WordPress. By default or setting onlyNewer to true speeds up the workflow run time, but the issue I have is if someone was to go into the WordPress theme file editor and directly make changes to a file, that file would now have a more recent modification date to the file in the source repository. This means when running the workflow and deploying, that file won't upload, the changes to that file will persist and will never be in sync until a new commit modifies that source file and makes it 'newer'.

To ensure the theme files on WordPress are always 100% in sync with the source repository, I could set onlyNewer to false but that would increase the workflow run time as now every file has to be uploaded again regardless of whether it has changed or not.

I guess just the possibility of deployed files not actually being deployed in this scenario made me think of this. Maybe it's a bit of an edge case though, so just using onlyNewer false even if it takes longer would be best to avoid the possibility? Just a suggestion anyway.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.