Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

github actions/checkout@v3 will delete unwatched file on the server

I’m using github action to auto deploy to unbuntu digitalocean server.

my yaml file

name: Continuous Deployment

on:
    push:
        branches:
            - main

jobs:
    deployment:
        runs-on: self-hosted
        steps:
            - name: Checkout main branch
              uses: actions/checkout@v3

            - name: Setup Node.js
              uses: actions/setup-node@v3
              with:
                  node-version: '16.x'

            - name: Install dependencies
              run: npm ci

            - name: Restart server
              run: npm run restart

the folder structure on my server

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

index.ts
someMiddleware.ts
.env

my local folder structure

index.ts
someMiddleware.ts
.env

My gitignore

.env

So the problem is, my .env on the server got deleted everytime the github action runs. I had to manually add the .env to server but it keeps getting delete by the github actions/checkout@v3

My question is, how to config github action so it won’t delete unwatched files like the .env in this case ?

>Solution :

The action performs git clean -ffdx by default. This is what’s removing the file. Using the following prevents that:

- name: Checkout main branch
  uses: actions/checkout@v3
  with:
    clean: false

This is documented as "Whether to execute git clean -ffdx && git reset --hard HEAD before fetching".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading