Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web-deploy keeps deleting manually created files and folders #15

Open
sammyskills opened this issue Sep 14, 2023 · 3 comments
Open

Web-deploy keeps deleting manually created files and folders #15

sammyskills opened this issue Sep 14, 2023 · 3 comments

Comments

@sammyskills
Copy link

Bug Description
Whenever I run the web-deploy action in my server, all files and folders that does not exist in the git repo are automatically deleted from the server.

For example, I have a file .env and this file is not included in the github repo, but whenever I run the deploy script, it is automatically deleted from the server. Same goes for folders which are created manually in the server.

My Action Config

on:
    push:
        branches:
            - production
name: 🚀 Deploy files to the production server on push to production branch
jobs:
    deploy:
        name: 🎉 Deploy files
        runs-on: ubuntu-latest
        steps:
            - name: 🚚 Get latest code
              uses: actions/checkout@v4

            - name: Setup PHP 🐘
              uses: shivammathur/setup-php@v2
              with:
                php-version: 8.2

            - name: Cache Composer Packages 📦
              id: composer-cache
              uses: actions/cache@v3
              with:
                path: vendor
                key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
                restore-keys: |
                    ${{ runner.os }}-php-

            - name: Install Dependencies 👨‍👩‍👧‍👦
              run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader

            - name: 📂 Sync files
              uses: SamKirkland/web-deploy@v1
              with:
                target-server: example.com
                remote-user: ${{ secrets.do_sftp_username }}
                private-ssh-key: ${{ secrets.do_application_ssh_key }}
                destination-path: ~/public_html/
                source-path: ./
                ssh-port: 22
                rsync-options: --archive --verbose --compress --delete-after --human-readable --exclude=.git* --exclude=.git/ --exclude=README.md --exclude=readme.md --exclude=.gitignore --exclude "misc/" --exclude "src/" --exclude "*.txt"

What could be the problem?

@AryaSvitkona
Copy link

AryaSvitkona commented Oct 6, 2023

Looks like the rsync-option: ... --delete-after is doing that.
That will delete every file, which is not part of the Repository like the .env file.
I'm not sure how rsync handles that if you still use --delete-after with the --exclude=.env, but I'm pretty sure you should give it a try without the --delete-after parameter.

See https://man7.org/linux/man-pages/man1/rsync.1.html ( Search: "--delete-after")

Update:
I just did a test with the "vendor" folder (since it's common in PHP projects), which shouldn't be deleted after rsync (just for that case).
If I add the --exclude=vendor parameter to the existing parameter list (based on your example), the folder still persist after sync.

@sammyskills
Copy link
Author

Thanks @AryaSvitkona.

If I add the --exclude=vendor parameter to the existing parameter list (based on your example), the folder still persist after sync.

Did you include the --delete-after option?

@AryaSvitkona
Copy link

Yes, exactly. See an example below which works for us.

`jobs:
web-deploy:
name: 🎉 Deploy website
runs-on: ubuntu-latest
# to change
if: github.ref == 'refs/heads/main'
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v3

- name: 📂 Sync Files
  uses: SamKirkland/web-deploy@v1
  with:
    target-server: ...
    remote-user: ...
    private-ssh-key: ...
    source-path: ./
    destination-path: ~/www/foobar/foobar/wp-content/plugins/pluginname/
    rsync-options:  --archive --verbose --compress --human-readable --progress --delete-after --exclude=vendor`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants