Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pushing to repo throws "fatal" error #594

Closed
EndBug opened this issue Mar 4, 2021 · 6 comments
Closed

Pushing to repo throws "fatal" error #594

EndBug opened this issue Mar 4, 2021 · 6 comments

Comments

@EndBug
Copy link

EndBug commented Mar 4, 2021

Hi, I'm using your package in a GitHub action, add-and-commit, and recently some users reported that they're having issues when it comes to pushing the commit to the repo. The error shown is the following:

Error: Error: Pushing to https://github.com/coderaiser/putout
fatal: could not read Username for 'https://github.com': No such device or address

What confuses me is the fact that they're perfectly able to fetch and pull from the repo, but they can't push it. I have never been encountered this issue in any of my workflows, but even looking at theirs I can't figure out what's wrong.

I thought that the error could be caused by a wrong git URL, but then the action would fail when pulling and fetching.
It could also be a wrong username, but they were all using my default option, which uses the name and email directly from the GitHub actor env variable, provided by GitHub itself.

This is how I implemented it:

const pushOption = parseBool(getInput('push')) ?? getInput('push')

if (pushOption === true) {
  // If they want to use the default options, I run this:
  await git.push(
    'origin',
    getInput('branch'),
    { '--set-upstream': null },
    (err, data?) => {
      if (data) setOutput('pushed', 'true')
      return log(err, data)
    }
  )
} else {
  // If they have their own options string I use this:
  debug(`Running: git push ${pushOption}`)
  await git.push(
    undefined,
    undefined,
    pushOption.split(' '),
    (err, data?) => {
      if (data) setOutput('pushed', 'true')
      return log(err, data)
    }
  )
}

(code link)

Do you have any idea of what could be going wrong?

Ref EndBug/add-and-commit#146

@steveukx
Copy link
Owner

steveukx commented Mar 6, 2021

Hi, do you know if this is just some of your users, or is this happening for everyone? Also, do you know if they were using the pushOption as true or as a string? Just in case they were supplying a string that split to unexpected commands.

When you're running git over http(s) in an action, you will likely need the authentication token from the consuming repo to do any write operations (whereas the read operations like pull and fetch would work for any non-private repo without authentication).

The consumers of your action configure a GITHUB_TOKEN environment variable (they don't need to do anything to set that, it's automatically available as a secret):

jobs:
   publish:
      steps:
         - uses: EndBug/add-end-commit
           ...other config...
           env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Your action can bind that token into any request it makes through simple-git using a custom credential helper (see per-command-configuration:

const git = simpleGit({
  baseDir,
  config: {
    'credential.https://github.com/.helper': `"! f() { echo username=x-access-token; echo password=$GITHUB_TOKEN; };f"`
  }
});

(based on the advice given in git-lfs/git-lfs#4031 (comment) - I've not tested this, but do let me know if it helps)

@steveukx steveukx added the more-info-needed More information is required in order to investigate label Mar 6, 2021
@EndBug
Copy link
Author

EndBug commented Mar 6, 2021

Hi, thanks for your reply!

  • This is happening only to a small group of users and only in some repos. Everyone else (myself included) have not experienced it.
  • They were using the default option, which is true

I'll try adding that credential helper and see if that solves their problem 👍🏻

@no-response no-response bot removed the more-info-needed More information is required in order to investigate label Mar 6, 2021
@EndBug
Copy link
Author

EndBug commented Mar 6, 2021

I have a question about the way you're using the config option.
In the typings config is documented as never[] which means that it should be an empty array. Why does it exist if it can't be used? And, more importantly, why is it an array when you've written an object in your code? Does it work anyway?

Also, is the helper supposed to show up in the git config? Because it doesn't at the moment

// code
debug(
      '> Current git config\n' +
        JSON.stringify((await git.listConfig()).all, null, 2)
    )
  ##[debug]> Current git config
  ##[debug]{
  ##[debug]  "filter.lfs.clean": "git-lfs clean -- %f",
  ##[debug]  "filter.lfs.smudge": "git-lfs smudge -- %f",
  ##[debug]  "filter.lfs.process": "git-lfs filter-process",
  ##[debug]  "filter.lfs.required": "true",
  ##[debug]  "core.repositoryformatversion": "0",
  ##[debug]  "core.filemode": "true",
  ##[debug]  "core.bare": "false",
  ##[debug]  "core.logallrefupdates": "true",
  ##[debug]  "remote.origin.url": "https://github.com/EndBug/temp-action-test",
  ##[debug]  "remote.origin.fetch": "+refs/heads/*:refs/remotes/origin/*",
  ##[debug]  "gc.auto": "0",
  ##[debug]  "http.https://github.com/.extraheader": "AUTHORIZATION: basic ***",
  ##[debug]  "branch.add-and-commit.remote": "origin",
  ##[debug]  "branch.add-and-commit.merge": "refs/heads/add-and-commit",
  ##[debug]  "user.email": "[email protected]",
  ##[debug]  "user.name": "EndBug"
  ##[debug]}

@steveukx
Copy link
Owner

steveukx commented Mar 6, 2021

You're right, there's an error in my previous post, you should supply an array of strings

const git = simpleGit({
  baseDir,
  config: [
    'credential.https://github.com/.helper="! f() { echo username=x-access-token; echo password=$GITHUB_TOKEN; };f"'
  ]
});

Supplied in that way you should see the credentials in the config.

@steveukx steveukx added the more-info-needed More information is required in order to investigate label Mar 6, 2021
@EndBug
Copy link
Author

EndBug commented Mar 11, 2021

I've tried your fix and one of the users tested it, and said that it didn't solve the problem.

However, they found out that the issue was in actions/checkout@v1: after upgrading to actions/checkout@v2 they no longer had the issue, even using the "normal, not patched" version. Since everyone was using @v1, I think that that action was causing the issue (I have no idea why, but I'm not that interested in looking into it ahhaha).

Thanks a lot for your help :)

@Nashorn
Copy link

Nashorn commented Apr 22, 2021

Open a terminal, do a git pull, you'll be prompted to re-authenticate. Once done, try it again from your app. This happens when username/pass changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants