[英]How to add working directory to deployment in GitHub actions
I recently moved into GitHub actions, so what I'm trying to do is host my react project in firebase when a push is done.我最近进入了 GitHub 操作,所以我要做的是在完成推送后将我的反应项目托管在 firebase 中。 And I used GitHub actions to this CI/CD process.
我对这个 CI/CD 流程使用了 GitHub 操作。 And this is the main.yml that I have right now.
这是我现在拥有的 main.yml。
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Install Dependencies
working-directory: ./my-app
run: npm install
- name: Build
working-directory: ./my-app
run: npm run build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
And I somehow manage to set the working directory when npm installation and project building.当 npm 安装和项目构建时,我以某种方式设法设置工作目录。 But in deployment I'm keep getting this error,
但是在部署中我不断收到这个错误,
So what I have understood is, this error occurs due to the working directory problem.所以我的理解是,这个错误是由于工作目录问题而发生的。 So my current project structure looks like this.
所以我目前的项目结构是这样的。
. (root of my GitHub repository)
└── my-app
├── firebase.json <-- Git Hub action must point to this sub-dir
└── my-app-mobile
├── packages.json
So how should I do this within my firebase deployment process?那么我应该如何在我的 firebase 部署过程中执行此操作? If I'm wrong with the problem, What would be the problem and the answer?
如果我对问题有误,问题和答案是什么? It seems I can't use
working-directory: ./my-app
with uses:
看来我不能使用
working-directory: ./my-app
的uses:
I looked at the documentation for the firebase CLI and didn't see any way to set the path to your firebase.json
via a CLI parameter.我查看了 firebase CLI 的文档,但没有看到任何方法可以通过 CLI 参数设置
firebase.json
的路径。 There is, however, an environment variable that stores the root directory.但是,有一个存储根目录的环境变量。 It's in the context of
predeploy
and postdeploy
hooks though, so I'm not sure if the CLI will respect it.虽然它是在
predeploy
和postdeploy
钩子的上下文中,所以我不确定 CLI 是否会尊重它。
$PROJECT_DIR — The root directory containing firebase.json
$PROJECT_DIR — 包含 firebase.json 的根目录
https://firebase.google.com/docs/cli#environment_variables https://firebase.google.com/docs/cli#environment_variables
The w9jds/firebase-action
you are using is just a wrapper around the CLI.您使用的
w9jds/firebase-action
只是 CLI 的一个包装器。 I'm not sure if this will work but you could try setting the project directory as follows.我不确定这是否可行,但您可以尝试如下设置项目目录。 The reason the variable is set in a separate step is because you cannot evaluate expressions in
env
sections.在单独的步骤中设置变量的原因是您无法评估
env
部分中的表达式。 See this answer for more detail.有关更多详细信息,请参阅此答案。 Container actions like
w9jds/firebase-action
will have access to the variable without passing it directly via env
. w9jds/firebase-action
类的容器操作将可以访问该变量,而无需直接通过env
传递它。
- name: Set project dir environment var
run: echo ::set-env name=PROJECT_DIR::"$GITHUB_WORKSPACE/my-app"
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
If that doesn't work, an alternative is to fork w9jds/firebase-action
and add a PROJECT_PATH
parameter to the entrypoint.sh script here: https://github.com/w9jds/firebase-action/blob/master/entrypoint.sh如果这不起作用,另一种方法是分叉
w9jds/firebase-action
并将PROJECT_PATH
参数添加到 entrypoint.sh 脚本: https://github.com/w9jds/firebase-action/blob/master/entrypoint。嘘
Update: I raised a PR to add a PROJECT_PATH
parameter to w9jds/firebase-action
.更新:我提出了一个 PR来向
w9jds/firebase-action
添加一个PROJECT_PATH
参数。 You can now use the action as follows.您现在可以按如下方式使用该操作。
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_PATH: ./my-app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.