我正在尝试设置一些基本的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添加了一个action,就像这样:
.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!!"
那么,有人知道我在这里做错了什么吗?我尝试通过谷歌寻找解决方案,但是...不成功:(
感谢您的时间!