Can't authenticate with .netrc for a private Git repo: "warning: here-document at line 109 delimited by end-of-file (wanted !’)`"

Hi,

I’ve been trying to use a private composer repo inside TravisCI.
I’ve set up the composer repo as usual, and this downloads locally.

I’ve approximately followed the basic tutorial/guide for using an API token.

I’ve added the following to the travis.yaml file:

before_script:
  - echo -e "machine github.com\n  login $GITHUB_TOKEN" >> ~/.netrc

And I uploaded an Environment Variable using the website UI:

GITHUB_TOKEN

It is set as available to all.
(Note, this is a new format github token, of the form: “ghp_”…)

When I run this test, I get the following:

"Failed to download [user]/[repo] from source: Failed to execute git clone --mirror ‘git@github.com:[user]/[repo].git’ ‘/home/travis/.cache/composer/vcs/git-github.com-[user]-[repo].git/’

Please make sure you have the correct access rights and the repository exists.

… and later:

"[Composer\Downloader\TransportException]
The “https://api.github.com/repos/[user]/[repo]/zipball/5707887
b973eadb25e3b19e56c6f7214bd0585a7” file could not be downloaded (HTTP/1.1 4
04 Not Found)

The token has been tested elsewhere and works.

What am I missing to get this working?

Thanks

To be clear: this is the travis.yaml instruction:

before_script:
  - git config --global credential.helper store
  - |
    git credential fill <<! | git credential approve
    url=https://github.com/
    username=native-api
    password=$GITHUB_TOKEN
    !
  - travis_retry composer self-update
  - travis_retry composer install

I’ve also tried with:

username=$GITHUB_USERNAME
password=$GITHUB_TOKEN

and:

username=$GITHUB_USERNAME
password=$GITHUB_PASSWORD

(all $… vars are set up using the UI).

UPDATE:

I’ve also found the following in the code, which I’m trying to debug:

0.01s$ git config --global credential.helper store before_script.2
0.01s$ git credential fill <<! | git credential approve
  url=https://github.com/
  username=native-api
  password=$GITHUB_TOKEN
  !

/home/travis/.travis/functions: line 114: warning: here-document at line 109 delimited by end-of-file 
(wanted `!')
warning: invalid credential line:   !
fatal: unable to read credential from stdin

https://www.krenger.ch/blog/bash-here-document-at-line-n-delimited-by-end-of-file-wanted-eof/
The trailing ! seems to be the answer, but I’m no bash/yaml expert, so I don’t know how to change the provided script. Any ideas?

PS: given that this is a likely common thing and the documentation is out of date: who do I ping/message to fix this for other users?

Thanks!
Rick

This is me succeding with the ~/.netrc route as described in the docs: Travis CI - Test and Deploy with Confidence. There relevant part of config is:

script:
  - |
    cat >~/.netrc <<!
    machine github.com
    login $GITHUB_TOKEN
    !

This means that you’re not encoding this command correctly into YAML. There must be no spaces at the front of here-document lines in the resulting multiline string in data representation. Check my example, and you can also use https://yaml-online-parser.appspot.com/ to check what your YAML is parsed into. See also the YAML 1.1 spec for syntax reference.

Hi,

Encoding seems to have cracked it… I went through and basically “hard copy pasted” other examples.
I ended up changing basically zero code and now it works!

Thanks for chasing this up.

Rick

Imprint