无法提交并推回github操作所做的更改(无效用户) [英] Unable to commit and push back changes made by github action (invalid user)

查看:253
本文介绍了无法提交并推回github操作所做的更改(无效用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作流程结束时要执行以下步骤。它在将代码推送到master时运行,其想法是一旦该操作完成,将github动作更改的所有文件提交回master。

I have following step at the end of my action workflow. It runs when code is pushed to master, the idea is to commit all files changed by github action back to master once this action finishes.

    - name: Commit and push changes
      run: |
        git config --global user.name 'myGithubUserName'
        git config --global user.email 'myEmail@gmail.com'
        git add -A
        git commit -m "Increased build number [skip ci]"
        git push -u origin HEAD

但是我即使我正在配置用户和电子邮件,也会不断出现以下错误。

However I keep getting following error, even though I am configuring user and email.


致命:无法读取' https://github.com ':未配置设备

fatal: could not read Username for 'https://github.com': Device not configured

请注意,此代码在 macOS最新版本,并使用预包装的git。

Note, this runs on macOS-latest and uses git that comes prepackaged with it.

推荐答案

actions / checkout @ v2

第二版结帐解决了独立的HEAD状态问题,并简化了推向原点的过程。

Version 2 of checkout resolves the detached HEAD state issue and simplifies pushing to origin.

name: Push commit
on: push
jobs:
  report:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Create report file
        run: date +%s > report.txt
      - name: Commit report
        run: |
          git config --global user.name 'Your Name'
          git config --global user.email 'your-username@users.noreply.github.com'
          git commit -am "Automated report"
          git push

如果您需要push事件来触发其他工作流程,请使用 repo 范围为个人访问令牌

If you need the push event to trigger other workflows, use a repo scoped Personal Access Token.

      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.PAT }}

actions / checkout @ v1(原始答案)

问题是 actions / checkout @ v1 操作使git存储库处于分离的HEAD状态。请参阅此问题以获取更多详细信息: https://github.com/actions/checkout/ Issues / 6

The problem is that the actions/checkout@v1 action leaves the git repository in a detached HEAD state. See this issue about it for more detailed information: https://github.com/actions/checkout/issues/6

我成功使用的解决方法是如下设置遥控器:

The workaround I have used successfully is to setup the remote as follows:

git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/username/repository

您可能还需要结帐。您可以从 GITHUB_REF 中提取分支名称:

You may also need to checkout. You can extract the branch name from the GITHUB_REF:

git checkout "${GITHUB_REF:11}"

这里是一个完整的示例。

Here is a complete example to demonstrate.

name: Push commit example
on: push
jobs:
  report:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Create report file
        run: date +%s > report.txt
      - name: Commit report
        run: |
          git config --global user.name 'Your Name'
          git config --global user.email 'your-username@users.noreply.github.com'
          git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
          git checkout "${GITHUB_REF:11}"
          git commit -am "Automated report"
          git push

顺便说一句,我编写了一个GitHub动作,可能会有所帮助您实现了您想要做的。它将接受在工作流期间本地进行的所有更改,将它们提交到新分支并提出拉取请求。
https://github.com/peter-evans/create-pull-请求

By the way, I have written a GitHub action which may help you achieve what you want to do. It will take any changes made locally during a workflow, commit them to a new branch and raise a pull request. https://github.com/peter-evans/create-pull-request

也请参见此相关问答。 从GitHub操作推送到源

Also see this related question and answer. Push to origin from GitHub action

这篇关于无法提交并推回github操作所做的更改(无效用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆