github-actions - 如何在 Github Actions 和 Monorepo 中使用子文件夹?
问题描述
它有一个 monorepo,其中将包含两个子文件夹,它们是:
每个都有各自的项目和包。我正在尝试访问某个子文件夹以执行其各自的操作,但是当我运行命令以使用 lint 进行测试时出现错误,即:
error Couldn't find a package.json file in "/github/workspace"
它可能不应该访问前端子文件夹。我需要它来运行这个子文件夹中的所有命令,我该怎么做?
我的.YML
:
name: PIPELINE OF TESTS
on:
push:
branches: [frontend-develop, backend-develop]
pull_request_target:
types: [opened, edited, closed]
branches: [main]
jobs:
test-frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
strategy:
matrix:
node-version: [14.x]
architecture: [x64]
steps:
- name: CHECK-OUT GIT REPOSITORY
uses: actions/checkout@v2
- name: USE NODEJS ${{ matrix.node-version }} - ${{ matrix.architecture }}
uses: actions/setup-node@v2
- name: INSTALL PROJECT DEPENDENCIES (YARN)
uses: borales/actions-yarn@v2.0.0
with:
cmd: install
- name: CODE ANALYSE (LINT) AND STYLE-GUIDE ANALYSE (PRETTIER + AIRBNB)
uses: borales/actions-yarn@v2.0.0
with:
cmd: lint-check
- name: UNIT TEST (JEST)
uses: borales/actions-yarn@v2.0.0
with:
cmd: test
解决方案
使用defaults
withrun
只会应用于运行步骤(例如,您自己执行的脚本/命令而不是操作)。请参阅文档:
为作业中的所有步骤提供默认值
shell
和。本节不允许使用上下文和表达式。working-directory
run
当您使用 GitHub 操作(您有uses:
)时,无法更改工作目录。请记住,某些操作支持这一点 - 您可以将附加参数传递给with:
,但在您的情况下borales/actions-yarn
不支持。
你能做什么?
正如borales/actions-yarn
REAME.md中所建议的:
请记住,这个 Action 最初是为 GitHub Actions beta 编写的(当时 Docker 是唯一的做事方式)。考虑使用操作/设置节点来处理 Yarn。该存储库将主要支持现有流程。
您可以删除这些操作并直接在run:
. 您的工作流程应如下所示:
name: PIPELINE OF TESTS
on:
push:
branches: [frontend-develop, backend-develop]
pull_request_target:
types: [opened, edited, closed]
branches: [main]
jobs:
test-frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
strategy:
matrix:
node-version: [14.x]
architecture: [x64]
steps:
- name: CHECK-OUT GIT REPOSITORY
uses: actions/checkout@v2
- name: USE NODEJS ${{ matrix.node-version }} - ${{ matrix.architecture }}
uses: actions/setup-node@v2
- name: INSTALL PROJECT DEPENDENCIES (YARN)
run: yarn install
- name: CODE ANALYSE (LINT) AND STYLE-GUIDE ANALYSE (PRETTIER + AIRBNB)
run: yarn lint-check
- name: UNIT TEST (JEST)
run: yarn test
推荐阅读
- bash - 如何在bash中查找后跟某个数字的任何字符序列
- javascript - 在构建项目中手动输入 URL,而已经在子页面上会导致样式失真
- firebase - 如何在firebase中设置规则以防止相同的昵称?
- c++ - Win7 C++ - 从以用户身份登录的服务中以用户身份启动可执行文件
- c# - Kerberos 令牌要求再次调用以完成上下文
- javascript - Angular 的循环模板可以遍历枚举吗?
- arrays - Postgres对象数组错误`错误:无法确定多态类型,因为输入的类型为“未知”`
- php - 带有int或浮点数的PHP字符串
- java - JsonPathResultMatchers 不能应用于 ResultMatcher
- php - 循环遍历数组并回显下一个事件