github 找不到动作 package.json
github actions can not find package.json
我正在尝试设置一些基本的 GitHub 操作来对 PR 发表评论。
操作发布在 github 上,看起来像这样:
action.yml 文件:
name: !!name!!
description: !!description!!
author: !!me!!
inputs:
token:
description: "Github token"
required: true
runs:
using: "node12"
main: "index.js"
index.js 文件:
const core = require("@actions/core");
const { execSync } = require("child_process");
const { GitHub, context } = require("@actions/github");
const main = async () => {
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const token = core.getInput("token");
const testCommand = "yarn test --watchAll=false";
const prNumber = context.payload.number;
const githubClient = new GitHub(token);
const reportAsString = execSync(testCommand).toString();
const commentBody = `<div><h2>Test report</h2>
<p>
<pre>${reportAsString}</pre>
</p>
</div>`;
await githubClient.issues.createComment({
repo: repoName,
owner: repoOwner,
body: commentBody,
issue_number: prNumber,
});
};
main().catch((err) => core.setFailed(err.message));
在项目中,我通过github添加了动作,像这样
.github/workflows/main.yml 文件:
on: [push]
jobs:
start_tests:
runs-on: ubuntu-latest
name: A test job
steps:
- name: !!name!!
uses: !!link to my action on github with version!!
with:
token: ${{ secrets.GITHUB_TOKEN }}
但是,我的 PR 操作失败了,原因如下:
error Couldn't find a package.json file in "/home/runner/work/!!project_name!!/!!project_name!!"
##[error]Command failed: yarn test --watchAll=false
error Couldn't find a package.json file in "/home/runner/work/!!project_name!!/!!project_name!!"
那么,有人知道我在这里做错了什么吗?我尝试 google 解决方案,但是呃……没有成功 :(
感谢您的宝贵时间!
package.json
文件必须出现在 运行 yarn test
命令中。正如我们在错误中看到的那样,没有这样的文件只是因为根本没有项目文件夹。这意味着该工作对要使用的项目一无所知。因此,您必须进行以下更改之一:
如果您的操作发布到市场
on: [push]
jobs:
start_tests:
runs-on: ubuntu-latest
name: A test job
steps:
- uses: actions/checkout@v2.1.0
- name: !!name!!
uses: !!link to my action on github with version!!
with:
token: ${{ secrets.GITHUB_TOKEN }}
如果您的操作尚未发布或者您只是想 运行 它 "locally"
on: [push]
jobs:
start_tests:
runs-on: ubuntu-latest
name: A test job
steps:
- name: !!name!!
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}
我正在尝试设置一些基本的 GitHub 操作来对 PR 发表评论。
操作发布在 github 上,看起来像这样:
action.yml 文件:
name: !!name!!
description: !!description!!
author: !!me!!
inputs:
token:
description: "Github token"
required: true
runs:
using: "node12"
main: "index.js"
index.js 文件:
const core = require("@actions/core");
const { execSync } = require("child_process");
const { GitHub, context } = require("@actions/github");
const main = async () => {
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const token = core.getInput("token");
const testCommand = "yarn test --watchAll=false";
const prNumber = context.payload.number;
const githubClient = new GitHub(token);
const reportAsString = execSync(testCommand).toString();
const commentBody = `<div><h2>Test report</h2>
<p>
<pre>${reportAsString}</pre>
</p>
</div>`;
await githubClient.issues.createComment({
repo: repoName,
owner: repoOwner,
body: commentBody,
issue_number: prNumber,
});
};
main().catch((err) => core.setFailed(err.message));
在项目中,我通过github添加了动作,像这样
.github/workflows/main.yml 文件:
on: [push]
jobs:
start_tests:
runs-on: ubuntu-latest
name: A test job
steps:
- name: !!name!!
uses: !!link to my action on github with version!!
with:
token: ${{ secrets.GITHUB_TOKEN }}
但是,我的 PR 操作失败了,原因如下:
error Couldn't find a package.json file in "/home/runner/work/!!project_name!!/!!project_name!!"
##[error]Command failed: yarn test --watchAll=false
error Couldn't find a package.json file in "/home/runner/work/!!project_name!!/!!project_name!!"
那么,有人知道我在这里做错了什么吗?我尝试 google 解决方案,但是呃……没有成功 :(
感谢您的宝贵时间!
package.json
文件必须出现在 运行 yarn test
命令中。正如我们在错误中看到的那样,没有这样的文件只是因为根本没有项目文件夹。这意味着该工作对要使用的项目一无所知。因此,您必须进行以下更改之一:
如果您的操作发布到市场
on: [push]
jobs:
start_tests:
runs-on: ubuntu-latest
name: A test job
steps:
- uses: actions/checkout@v2.1.0
- name: !!name!!
uses: !!link to my action on github with version!!
with:
token: ${{ secrets.GITHUB_TOKEN }}
如果您的操作尚未发布或者您只是想 运行 它 "locally"
on: [push]
jobs:
start_tests:
runs-on: ubuntu-latest
name: A test job
steps:
- name: !!name!!
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}