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

Advertisements

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

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".

Leave a ReplyCancel reply