如何在 github 操作中的特定文件夹中运行我的 CI 步骤



我有一个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

代码段

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

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

需要帮助。提前谢谢。

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

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

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

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

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

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

这样,您无需为每个步骤指定它。 您还可以根据放置上述代码段的位置调整范围,例如:

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

最新更新