hexojs / hexo-deployer-git

Git deployer plugin for Hexo.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Token deploy prompts for username

oliversturm opened this issue · comments

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?

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?

commented

@oliversturm

export GITHUB_TOKEN=<token>

Will it work?

@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.

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.

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 @oliversturm, I was stuck for the same issue for hours, finally it was solved by your solution!

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

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

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

Thanks @oliversturm you saved my day (lol).

Thank you for your solution!!!

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.

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.
hexojs/hexo#2084 (comment)

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

commented

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

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!