githubgithub-actions

Github workflow with private repo & tag


I asked this question here and got no response: https://github.community/t/private-repo-w-tag-in-workflow/229573

We have three private repos with tags in our package.json as dependencies, one example:

"Private-Repo1": "https://<PAT>:x-oauth-basic@github.com/project/Private-Repo.git#v1.0.0",

We use oauth keys to access our repos. My PAT is set to allow checking out the repo as well as workflow access.

When we run our Workflow action, it fails at npm ci for this line with an error of:

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ***github.com/project/Private-Repo.git
npm ERR! remote: Repository not found.
npm ERR! fatal: repository 'https://github.com/project/Private-Repo.git/' not found

Local testing is pointing to the reason that we’re failing is that git ls-remote fails when you point to a private repo with a tag number, if I remove the tag it works.

How can we use a PAT to pull a specific tag from a private repo in our workflow via our package.json? Everything I can find is how to access a private repo, but not how to access a private repo's tag.


Solution

  • The problem wasn't git ls-remote it was the token. I was calling it in the wrong place. It needs to be set in the checkout step, not setup-node step. Here is my working yaml that allows me to run a workflow with a private repo and tag that uses an oauth token. The only setup needed is to make a secret called GIT_TOKEN (or whatever you want to call it) and give it workflow access.

    name: API auto test and lint workflow
    
    on: push
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
            with:
              token: ${{ secrets.GIT_TOKEN }}
          - uses: actions/setup-node@v1
            with:
              node-version: 16.x
          - run: npm ci
          - run: npm run lint
          - run: npm run test