【问题标题】:Git config --global user.email = "email@example.com" and user.name error in GitHub actionGit config --global user.email = "email@example.com" 和 GitHub 操作中的 user.name 错误
【发布时间】:2020-08-09 10:45:18
【问题描述】:

我正在尝试为 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,所以我需要以某种方式将适当的凭据传递给操作以允许这些命令。有谁知道我该怎么做?

【问题讨论】:

  • git 都是小写字母,在user.email 之前不需要=。另一个你应该使用的命令为git config --global user.name "Your name here"
  • 那个 git 消息是我从操作中收到的错误,而不是我运行的命令
  • 您能先运行git config --list --global 来检查这些存储的值吗?

标签: git github-actions


【解决方案1】:

如果您尝试设置电子邮件和用户,您可以通过以下两种方式之一进行:

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}"`);

如上面我的 cmets 所述,各有利弊。

【讨论】:

    猜你喜欢
    • 2021-12-18
    • 2021-01-11
    • 1970-01-01
    • 2013-04-27
    • 2017-06-29
    • 2018-08-30
    • 1970-01-01
    • 2022-10-30
    • 1970-01-01
    相关资源
    最近更新 更多