uv: uv add private GitHub repository with PAT on Actions fails
Summary
I’m Trying to setup a CI Workflow on GitHub Actions for a private repository that must pull another private repository. Using a Github PAT, I can make it work in pip but it fails with uv.
My CI.yml file is the following
...
jobs:
...
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Pip install packages
run: |
# using pip here would work, but uv fails
uv --verbose add "git+https://x-access-token:${TOKEN}@github.com/organization/private_repo"
uv sync
env:
TOKEN: ${{ secrets.GH_READONLY_PAT }}
where secrets.GH_READONLY_PAT is a PAT with read only access to private repos, which I tested and works correctly.
Running the action gives the following error
DEBUG No netrc file found
DEBUG GitHub API request failed for: https://api.github.com/repos/NeuralQXLab/netket_pro/commits/HEAD (404 Not Found)
DEBUG Fetching source distribution from Git: https://github.com/NeuralQXLab/netket_pro
DEBUG Acquired lock for `[https://github.com/neuralqxlab/netket_pro`](https://github.com/neuralqxlab/netket_pro%60)
DEBUG Updating Git source `[https://github.com/NeuralQXLab/netket_pro`](https://github.com/NeuralQXLab/netket_pro%60)
Updating https://github.com/NeuralQXLab/netket_pro (HEAD)
DEBUG Attempting GitHub fast path for: https://api.github.com/repos/NeuralQXLab/netket_pro/commits/HEAD
DEBUG Failed to check GitHub HTTP status client error (404 Not Found) for url (https://api.github.com/repos/NeuralQXLab/netket_pro/commits/HEAD)
DEBUG Performing a Git fetch for: https://github.com/NeuralQXLab/netket_pro
DEBUG Released lock at `/home/runner/actions-runner/_work/_temp/setup-uv-cache/git-v0/locks/d25fca3599406dfa`
DEBUG Reverting changes to `pyproject.toml`
DEBUG Removing `uv.lock`
× Failed to download and build `netket-pro @
│ git+[https://github.com/NeuralQXLab/netket_pro`](https://github.com/NeuralQXLab/netket_pro%60)
├─▶ Git operation failed
├─▶ failed to clone into:
│ /home/runner/actions-runner/_work/_temp/setup-uv-cache/git-v0/db/d25fca3599406dfa
╰─▶ process didn't exit successfully: `/usr/bin/git fetch --force
--update-head-ok 'https://github.com/NeuralQXLab/netket_pro'
'+HEAD:refs/remotes/origin/HEAD'` (exit status: 128)
--- stderr
fatal: could not read Username for 'https://github.com/': No such device
or address
I tried the following things:
- Execute the command above on my machine, with the same token, it works.
- Create a .netrc file in a preceding step with the token inside, but it is not used/does not solve the problem.
Most interestingly, by ssh-ing in the runner if the step fails, and running exactly the same command, the command success, so I have the feeling that if the session is interactive something different is triggered
Platform
linux GitHub runner
Version
0.5.29
Python version
3.12
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 15 (4 by maintainers)
Weird, I don’t understand what’s going on here. We can look into this.
Looking through this and related issues, I’m aware of three generic ways to get a Personal Access Token (PAT) to
gitinvocations that happen in the guts of tools likeuv. The first way is~/.netrc. As folks have mentioned here,gitdoesn’t know about theNETRCenv var, and this approach interacts kind of poorly with Docker. Also no one’s thrilled about writing secrets to disk.The second way is using the
ghcommand line utility, as mentioned here.ghis installed by default in GitHub runners. It works by configuring itself as a “credential helper” in~/.gitconfig, and if it can’t find a system keyring it also stores your token under~/.config/ghor similar. This way is the most convenient, and I recommend it if you’re not sure what to do, but it only works with GitHub specifically. Here’s a working example. The relevant lines of that.github/workflows/ci.ymlare:The third way is to wrap the token in a trivial “credential helper” (
echo) configured entirely via environment variables. This approach has the most annoying syntax, but it could be the most reliable approach if multiple layers of your stack that don’t necessarily know about each other need to configure Git. It also keeps your token off the disk, and it might be easier to get it working with container barriers like Docker (i.e. using--env). Here’s a working example. Here are the relevant lines:In a truly generic, “who knows what other layers above and below me are doing” scenario, you’d read
GIT_CONFIG_COUNTfrom your own environment, name the other two variables accordingly (exportlets you set variables with other variables in their names), and then increment the count. There’s some very sensitive punctuation there; for a longer explanation see the giant comment in that file.Also in case anyone finds this thread who’s working PATs for the first time, for completeness, in all of these approaches you have to start by manually adding the PAT to your CI environment using GitHub’s “Secrets and Variables -> Actions” repo settings:
In this thread, we have multiple use cases:
(in our context, we do both: “classic” to run tests and “docker build” to push the deployment artifacts on our private docker registry)
classic install and build:
using https://github.com/extractions/netrc
This works.
GH_REPO_PATis a fine-grained personal access token, withRead access to code and metadatapermission to the private repo of the dependency.(to be continued)
We use the following in our Dockerfile, in combination with netrc and Docker action:
Action:
For us, this works if the (classical) PAT has “Full control of private repositories” selected. In other cases, it complained about not having write access or the repository not existing. Fine grained tokens did not work.
Follow up:
This error message:
I tried to find out what’s going on here:
When creating a git repository and entering the
git fetchcommand manually I got a prompt forusernameandpassword.Trying with a different directory that has been shown in the uv error message:
-> a git repository 👍
Another try with
--git-dir:-> no git repository?! 🤨
Facing similar issue with uv version
0.6.14inside docker.fatal: could not read Username for 'https://github.com': terminal prompts disabledmy pyproject.toml
I am using
NETRCfile for storing the PAT github token.