英文:
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".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论