Is there a way to define and use GitHub PAT for downloading dependencies?

Hello everyone!

I currently use Netlify to make previews of Pull requests towards a documentation I manage.
For the documentation do I use “Material for MkDocs” which I install using a requirements.txt file containing mkdocs-material>=7.0

But now do I want to use the Insider version (A Sponsor-reward containing early features) for my docs. Unfortunately can I not just use something like mkdocs-material-insiders in the requirements file, since that particular project is private.
To get it do I need to use the git+ option of Pip together with a PAT (Personal Access Token) from GitHub to access and download it.

My problem now is, that I can’t just put my PAT in the requirements file, for obvious reasons. I now need to find an alternative way to make Netlify download and use that specific version, so that I can utilize its features.

If it is of any importance, is the URL to use in pip git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git

I appreciate any help.
If my explanation is a bit unclear, ask me for more clarification and I’ll do my best.

1 Like

Hey there, @Andre601 :wave:

Thanks for writing in! Sorry for the slow response here.

You most likely won’t be able to use our auto-install with custom settings like this. I wish I had better news! However, I have spoken with our Support staff and here is a recommendation for moving forward:

  1. You could try not having it as a dep (or use the free version which you’ll overwrite below, if it is required to have something to install your other deps)

  2. You could set your PAT in an environment variable in our UI

  3. You could run the build instead as pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git p && run-my-usual-build

Give these a try and let us know how it works! Additionally, if anything has changed in the past week since you posted this, please let us know :slight_smile:

How would I actually use this one tho?
Would I make a Env Variable called GH_TOKEN to then use this?
And where would I actually use this on? This sadly confuses me even more than helping right now…

To the other points:
I currently use the mkdocs-material dependency to also install all its required dependencies such as MkDocs itself, so I could first install that and then later manually install the insiders version, or use the command you just mentioned to achieve a similar result before executing the remaining commands for building the docs…
But again do I have no idea where I could define this stuff to make it work properly.

Yup, what Hillary is suggesting is that you’d create that variable, in your Site->Deploy Settings->Environment variables UI section for that site. I don’t know which site you are working on so can’t link you directly to it, but if you can’t find it, let me know! The documentation on that section of our settings is here in case that helps: Build environment variables | Netlify Docs

That should be the only change needed to support your build - if it doesn’t work, please link us to the logs so we can give the most relevant advice :slight_smile:

Thanks for the reply.
Unfortunately does this still not answer a question I asked:

Just setting the Env variable would most likely not do the trick I assume unless Netlify is that smart and recognizes any ${text} pattern to replace them with the corresponding values.
If not would I still need a solution here, as I have 0 idea on what I have to configure and how I have to configure it to make Netlify work with it.

Hey @Andre601,
You can set environment variables in your site dashboard here: https://app.netlify.com/sites/YOUR-SITE-NAME/settings/deploys#environment

and then you can access them with process.env.GH_TOKEN or $GH_TOKEN during your build

so as your build command, you could try putting: pip install git+https://$GH_TOKEN@github.com/squidfunk/mkdocs-material-insiders.git && mkdocs ← or whatever the usual build command if it’s not mkdocs

Wanna give it a shot? If you get any errors, it’d be great if you could share your Netlify site url so we can take a look.