GitHub Actions/checkout@v3 将在服务器上删除未被观看的文件。

huangapple go评论62阅读模式
英文:

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

问题

I'm using github action to auto deploy to Ubuntu DigitalOcean server.

my yaml file

name: 持续部署

on:
    push:
        branches:
            - main

jobs:
    部署:
        runs-on: self-hosted
        steps:
            - name: 检出主分支
              uses: actions/checkout@v3

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

            - name: 安装依赖项
              run: npm ci

            - name: 重新启动服务器
              run: npm run restart

服务器上的文件夹结构

index.ts
someMiddleware.ts
.env

我的本地文件夹结构

index.ts
someMiddleware.ts
.env

我的 .gitignore

.env

问题是,每次 GitHub Action 运行时,服务器上的 .env 文件都会被删除。我不得不手动将 .env 添加到服务器,但它总是被 GitHub Actions/checkout@v3 删除。我的问题是,如何配置 GitHub Action 以防止像这种情况下不受监视的文件(如 .env)被删除?

英文:

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 ?

答案1

得分: 2

默认情况下,此操作执行git clean -ffdx。这就是删除文件的原因。使用以下内容可以阻止这个行为:

- name: 检出主分支
  uses: actions/checkout@v3
  with:
    clean: false

这被记录为“是否在获取之前执行git clean -ffdx && git reset --hard HEAD”。

英文:

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

huangapple
  • 本文由 发表于 2023年4月17日 05:24:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定