dom96 / choosenim

Tool for easily installing and managing multiple versions of the Nim programming language.
BSD 3-Clause "New" or "Revised" License
681 stars 64 forks source link

Use GITHUB_TOKEN env var if present #209

Closed iffy closed 4 years ago

iffy commented 4 years ago

This change inserts the value of the env var GITHUB_TOKEN into the authentication section of Github API URLs.

This is to fix #208

I'm fine if you want to throw this away and do your own implementation.

genotrance commented 4 years ago

Best way to test this is to update the tester which works around the API limit today.

https://github.com/dom96/choosenim/blob/master/tests/tester.nim#L199

We can add a read-only token to the choosenim CI and see if the build passes.

The env var is the best way for tokens with a CI. However, a file is more appropriate for regular users. See the nimble implementation to see how it deals with this. Might be best to keep choosenim and nimble similar.

https://github.com/nim-lang/nimble/blob/master/src/nimblepkg/publish.nim#L52

dom96 commented 4 years ago

I don't know how to build choosenim to test this, so I don't know if it works

nimble build should work...

iffy commented 4 years ago

nimble build worked great!

What's the authoritative spec for GITHUB_TOKEN? What does it contain? username:password?

It's an opaque hexadecimal string that can be used as a username in an HTTP request. You can also use it as a Bearer token in an HTTP header. I've added some cli documentation that might make it clearer?

Also, please add some code to show an info message when the token is used.

Done

iffy commented 4 years ago

I'm not sure why this change causes this build failure:

/Users/travis/build/dom96/choosenim/tests/tester.nim(179, 19): Check failed: exitCode == QuitSuccess
exitCode was 1
QuitSuccess was 0
   Updating devel
    Warning fatal: unable to access 'https://github.com/nim-lang/Nim/': Could not resolve host: github.com
        ... git ls-remote failed
Downloading Nim devel from GitHub
/Users/travis/build/dom96/choosenim/src/choosenim.nim(299) choosenim
/Users/travis/build/dom96/choosenim/src/choosenim.nim(274) performAction
/Users/travis/build/dom96/choosenim/src/choosenim.nim(166) update
/Users/travis/build/dom96/choosenim/src/choosenim.nim(24) installVersion
/Users/travis/build/dom96/choosenim/src/choosenimpkg/download.nim(282) download
/Users/travis/build/dom96/choosenim/src/choosenimpkg/download.nim(253) downloadImpl
/Users/travis/build/dom96/choosenim/src/choosenimpkg/download.nim(188) downloadFile
/Users/travis/build/dom96/choosenim/src/choosenimpkg/download.nim(152) downloadFileCurl
/Users/travis/build/dom96/choosenim/src/choosenimpkg/download.nim(70) checkCurl
Error: unhandled exception: CURL failed: Couldn't resolve host name [AssertionError]
/Users/travis/build/dom96/choosenim/tests/tester.nim(188, 19): Check failed: exitCode == QuitSuccess
exitCode was 1
QuitSuccess was 0
/Users/travis/build/dom96/choosenim/tests/tester.nim(193, 17): Check failed: inLines(output.processOutput, "latest changes")
/Users/travis/build/dom96/choosenim/tests/tester.nim(194, 17): Check failed: inLines(output.processOutput, "building")
[FAILED] can update devel with git
genotrance commented 4 years ago

Restarting the failed job - travis network is flaky sometimes.