Git config --global user.email = GitHub 操作中"email@example.com"和 user.name 错误



我正试图为react项目创建一个GitHub操作。从本质上讲,我希望操作执行两个步骤:
1。npm install
2。npm run deploy
但我的操作在
Git config --global user.email = "email@example.com"Git config --global user.name"
npm run deploy命令执行git addgit commitgit push等操作,因此我需要以某种方式将适当的凭据传递给操作以允许这些命令。有人知道我该怎么做吗?

如果你试图设置电子邮件和用户,你可以用两种方法之一:

import { context } from '@actions/github';
await exec(`git config --local user.name "${context.actor}"`);
await exec(`git config --local user.email "github-action-${context.actor}@users.noreply.github.com"`); // This is basically a bogus email, but you get the idea

import { context } from '@actions/github';
const author = context.payload.commits[0].author; // Be careful using this, it may not always be here. For example, in the case of a pull_request triggered action, this will result in an error.
await exec(`git config --local user.name "${author.name}"`);
await exec(`git config --local user.email "${author.email}"`);

正如我在上面的评论中所描述的,每一种都有利弊。

相关内容

最新更新