hexojs / hexo-deployer-git

Git deployer plugin for Hexo.
MIT License
567 stars 121 forks source link

Token deploy prompts for username #159

Open oliversturm opened 4 years ago

oliversturm commented 4 years ago

I'm trying to deploy my hexo site to GitHub Pages. Right now I'm testing my setup locally, but I intend to use a CI setup once it works (probably using GitHub actions).

Based on the README, I included this block in my _config.yml:

deploy:
  type: git
  repo: https://github.com/<myusername>/<myrepo>.git
  branch: gh-pages
  token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I created an access token in GitHub with the repo scope. Now I run the deployment from the command line to test it:

GITHUB_TOKEN=<my token> hexo deploy

The site is generated and I see git messages when everything is added to the new local repo. After this, I see a prompt:

Username for 'https://github.com': 

Why does this come up? Who is supposed to enter this username in a CI scenario? My local system is not configured to remember an HTTPS GitHub username, since I normally use SSH. But the CI system would obviously never know this username - how do I specify it?

(I tried using the name setting in the config file as a test, but that doesn't work - looking at the code, it's clearly not intended for that purpose.)

I confirmed that if I enter the username manually, the password prompt appears next. At this point I have to enter the token again and everything works - but it appears that the token configuration in the config file is ignored entirely.

I'm sure I'm misunderstanding something... can anybody confirm that token deployment is supposed to work for my use case?

oliversturm commented 4 years ago

Update: I was looking at https://hexo.io/docs/one-command-deployment.html and I found this.

You will be prompted with username and password of the target repository, unless you authenticate with a token or ssh key.

This is clear enough - I should not expect a prompt when using a token. Does that mean something is wrong with my configuration for the token, or the mechanism that reads it?

SukkaW commented 4 years ago

@oliversturm

export GITHUB_TOKEN=<token>

Will it work?

oliversturm commented 4 years ago

@SukkaW That shouldn't be necessary - the syntax I'm using sets the environment variable without exporting it. Works like a charm, usually.

On the suspicion that the environment variable value is not found for some reason, I tried adding my token to _config.yml directly, but this doesn't change anything about the behavior I'm seeing.

oliversturm commented 4 years ago

So... reading the source code, I find that the token handling is exclusively implemented in this function. As far as I can see, this means that it can only be used with the config structure that has a repo object with a sub-property url - the other syntax variations use other execution paths that don't handle the token at all. How strange.

I'll try to change my config and update this issue.

oliversturm commented 4 years ago

With a different config structure it works correctly now:

deploy:
  type: git
  repo:
    github:
      url: https://github.com/<myusername>/<myrepo>.git
      branch: gh-pages
      token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I'm leaving the issue open - I guess this should either be fixed in code or documented.

At this point I'm only wondering how everybody else does this? I wouldn't normally use this config structure unless I was pushing to multiple repos, which seems like an edge case to me.

PinkyJie commented 4 years ago

Thanks @oliversturm, I was stuck for the same issue for hours, finally it was solved by your solution!

tienhm0202 commented 4 years ago

Thanks @oliversturm. I do believe this need an document update. As you said, it's not common case

carlos-algms commented 3 years ago

The @oliversturm solution does not work for me 😞 I'm getting an error about password:

fatal: could not read Password for 'https://***@github.com': No such device or address

ilharp commented 3 years ago

Thanks. I add .git to my repo.github.url and it works.

lawrence910426 commented 2 years ago

Thanks @oliversturm you saved my day (lol).

Thank you for your solution!!!

leimao commented 2 years ago

With a different config structure it works correctly now:

deploy:
  type: git
  repo:
    github:
      url: https://github.com/<myusername>/<myrepo>.git
      branch: gh-pages
      token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I'm leaving the issue open - I guess this should either be fixed in code or documented.

At this point I'm only wondering how everybody else does this? I wouldn't normally use this config structure unless I was pushing to multiple repos, which seems like an edge case to me.

Not sure why your solution did not work for me. It kept asking me for username and password.

leimao commented 2 years ago

I think this should be the correct way of deploying the website using token, although the token unfortunately has to be concretely typed in the yaml file. https://github.com/hexojs/hexo/issues/2084#issuecomment-466350089

mzaydman commented 1 year ago

password auth has been deprecated by github, this should really be in the main docs.

stevenjoezhang commented 1 year ago

password auth has been deprecated by github, this should really be in the main docs.

See also https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-experiencing-github-pushfetch-problems

isaaxite commented 1 year ago

With a different config structure it works correctly now:

deploy:
  type: git
  repo:
    github:
      url: https://github.com/<myusername>/<myrepo>.git
      branch: gh-pages
      token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I'm leaving the issue open - I guess this should either be fixed in code or documented.

At this point I'm only wondering how everybody else does this? I wouldn't normally use this config structure unless I was pushing to multiple repos, which seems like an edge case to me.

thanks ur share!

uiolee commented 10 months ago

same issue