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

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

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

  1. name: 持续部署
  2. on:
  3. push:
  4. branches:
  5. - main
  6. jobs:
  7. 部署:
  8. runs-on: self-hosted
  9. steps:
  10. - name: 检出主分支
  11. uses: actions/checkout@v3
  12. - name: 设置 Node.js
  13. uses: actions/setup-node@v3
  14. with:
  15. node-version: '16.x'
  16. - name: 安装依赖项
  17. run: npm ci
  18. - name: 重新启动服务器
  19. run: npm run restart

服务器上的文件夹结构

  1. index.ts
  2. someMiddleware.ts
  3. .env

我的本地文件夹结构

  1. index.ts
  2. someMiddleware.ts
  3. .env

我的 .gitignore

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

  1. name: Continuous Deployment
  2. on:
  3. push:
  4. branches:
  5. - main
  6. jobs:
  7. deployment:
  8. runs-on: self-hosted
  9. steps:
  10. - name: Checkout main branch
  11. uses: actions/checkout@v3
  12. - name: Setup Node.js
  13. uses: actions/setup-node@v3
  14. with:
  15. node-version: '16.x'
  16. - name: Install dependencies
  17. run: npm ci
  18. - name: Restart server
  19. run: npm run restart

the folder structure on my server

  1. index.ts
  2. someMiddleware.ts
  3. .env

my local folder structure

  1. index.ts
  2. someMiddleware.ts
  3. .env

My gitignore

  1. .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。这就是删除文件的原因。使用以下内容可以阻止这个行为:

  1. - name: 检出主分支
  2. uses: actions/checkout@v3
  3. with:
  4. 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:

  1. - name: Checkout main branch
  2. uses: actions/checkout@v3
  3. with:
  4. 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:

确定