【问题标题】:How do I run my CI steps in a specific folder in github action如何在 github 操作的特定文件夹中运行我的 CI 步骤
【发布时间】:2020-05-25 11:42:27
【问题描述】:

我有一个带有react 客户端的golang 存储库。我想为我的客户使用 github 操作设置 CI。 React 客户端位于工作区的 client 文件夹中。 我已经编写了以下工作流程

name : Node.js CI

on: [push, pull_request]

jobs:

  build:
    name: build
    runs-on: ubuntu-latest
    steps:

    - uses: actions/checkout@v2 
      with:
        path: client
    - name: Set up Node.js
      uses: actions/setup-node@v1
      with:
        node-version: 12.x

    - run: yarn install

    - run: yarn build

但在提交时显示以下错误

 Run yarn build1s
##[error]Process completed with exit code 1.
Run yarn build
yarn run v1.21.1
error Couldn't find a package.json file in "/home/runner/work/evential/evential"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
##[error]Process completed with exit code 1

sn-p

- uses: actions/checkout@v2 
      with:
        path: client

不会使以下步骤在 client 文件夹中运行。

需要帮助。提前致谢。

【问题讨论】:

    标签: node.js github-actions


    【解决方案1】:

    您可以在run 步骤中使用working-directory 关键字。请参阅文档here

        - run: yarn install
          working-directory: client
    
        - run: yarn build
          working-directory: client
    

    【讨论】:

    • 我认为这不能回答问题,因为这无法解决 uses 无法在工作目录中运行并且仍然会失败的问题。
    • uses 引用的操作需要支持path 输入。如果他们不这样做,那么你真的无能为力。你应该要求动作作者支持它。
    • gyazo.com/c586ad6448df17a1034a99f451a38ff7working-directory: '../../frontend/' 不工作你能看看结构
    【解决方案2】:

    假设您的存储库结构如下所示:

    .
    ├── README.md
    ├── client
    │   └── ... # your source files
    └── workflows
        └── example-ci.yml
    

    您还可以使用以下方法为多个步骤设置默认工作目录:

    defaults:
      run:
        working-directory: client # The working directory path
    

    这样您就不需要为每个步骤指定它。 您还可以根据放置上述 sn-p 的位置来调整范围,无论是:

    • 所有作业的所有步骤:将其置于工作流程的基础
    • 一项作业的所有步骤:将其在作业中放在工作流的作业属性中,以便应用于该作业的步骤。

    【讨论】:

      猜你喜欢
      • 2020-01-16
      • 2020-12-07
      • 2020-11-28
      • 2021-11-16
      • 2022-11-18
      • 2019-12-21
      • 2019-08-02
      • 2022-10-17
      • 2020-12-15
      相关资源
      最近更新 更多