简体   繁体   English

如何在 GitHub 操作中将工作目录添加到部署

[英]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-appuses:

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.虽然它是在predeploypostdeploy钩子的上下文中,所以我不确定 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.

相关问题 使用 Github 操作将部署在 Firebase 主机上的 Nuxt 应用程序添加.env 秘密 - Add .env Secrets to Nuxt App Deploying on Firebase Hosting with Github Actions 使用 GitHub 操作在 Firebase 托管上自动部署 Vue-CLI 项目 - Vue-CLI project automatic deployment on Firebase Hosting using GitHub actions 如何通过 github 操作部署 firebase 功能? - How can I deploy firebase functions through github actions? 如何在 github 操作/GPC 上设置 app.yaml 变量 - How to set app.yaml variable on github actions/GPC 在 github 操作上运行 firebase 模拟器 - Run firebase emulators on github actions Firebase部署目录结构 - Firebase Deployment Directory Structure Firebase 部署使用 Github 操作 - Firebase Deployment using Github Action Github 操作 - 如何使我的 env 变量(存储在 .env 文件中)在我的工作流程中可用 - Github Actions - How can I make my env variable(stored in .env file) available in my workflow 如何使用 github 操作和 w9jds/firebase-action 部署到不同的 firebase 环境 - How can I deploy to different firebase environments using github actions and w9jds/firebase-action 将 Angular 应用程序部署到 Firebase 托管 Github 操作 - Deploying Angular App to Firebase Hosting Github Actions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM