wpengine / github-action-wpe-site-deploy

A GitHub Action to deploy code directly to WP Engine.
MIT License
173 stars 36 forks source link

Files not deleted from remote server when deleted in repo #108

Open ravewebdev opened 1 month ago

ravewebdev commented 1 month ago

Describe the bug The workflow does not delete files/folders from the server when they're deleted in the repo. This has caused builds to fail when a folder containing PHP classes was replaced with a renamed folder in the repo, with the error "PHP Fatal error: Cannot declare class..." as it detected duplicate classes, despite the fact that in the repo the classes were actually unique. To fix the issue, we had to SFTP into the server and manually delete the old files. This should not be necessary.

To reproduce

  1. Add new file, commit and push to remote.
  2. Delete that file, commit and push to remote.

The file will be deleted from the repo but not from the server.

deploy workflow for reference:

name: Develop

on:
  push:
    branches:
      - develop

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: |
          git fetch --prune --unshallow

    - name: GitHub Action for WP Engine Git Deployment
      uses: wpengine/github-action-wpe-site-deploy@v3
      env:
        WPE_ENV: '<dev-install>'
        WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPENGINE_SSH_KEY_PRIVATE }}

Expected behavior

Files deleted from the repo should be deleted from the server as well.

Version information

apmatthews commented 1 month ago

Hi @ravewebdev 👋🏻

Correct, the action defaults to a non-destructive deploy. This is the intended behavior. If you'd like to make your deploy destructive, please check out the FLAGS deploy option for information on using the --delete rsync flag.

groenroos commented 1 month ago

Please take care to note that the --delete flag will destroy everything relative to REMOTE_PATH, not just files related to your GitHub repo. It will not take .gitignore or WP Engine's built-in exclusions into account.

So for instance, you do not want to use this in a situation where your repo is structured to represent the WP root (rather than a specific plugin or theme folder):

- name: GitHub Action Deploy to WP Engine
  uses: wpengine/github-action-wpe-site-deploy@v3
  with:
    WPE_SSHG_KEY_PRIVATE: ${{ secrets.WPE_SSHG_KEY_PRIVATE }}
    WPE_ENV: <your_install_name_here>
    SRC_PATH: "dist/"
    REMOTE_PATH: "/"
    FLAGS: -azvr --inplace --delete

The above configuration will delete all of WordPress from your remote, including user uploads.

ravewebdev commented 1 month ago

@groenroos thanks for noting that. We discovered that already when testing (which is why we intentionally spun up a new testing site to avoid breaking anything active), so it's good to know that wasn't a bug/error on our part.

@apmatthews given that the --delete flag wipes out the entire root directory, not just the files deleted via git, what are our options? Is there a way to configure the workflow to only delete files we indicate should be deleted? Or do we really have to SFTP into the site every time we want to delete a file?