A project that useses public NUGET.ORG packages and also packages from my Org's ownnuget Github Packages registry restores just fine locally, but fails to do so inside a Github Action. Here's the exerpt from the action's yml:
name: workflow1
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
issues: write
steps:
- name: Check that shit out
uses: actions/checkout@v3
- name: Set that shit up
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.x.x'
- name: Build that shit
run: |
dotnet nuget add source https://nuget.pkg.github.com/myorg/index.json -n github -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
dotnet restore ./project.sln
dotnet build ./project.sln --no-restore --configuration Release --nologo
Adding the nuget source is the same as recommended (as working) here. Unfortunately the Build step fails with an error like this
error NU***0***: Unable to find package <packageId>. No packages exist with this id in source(s): github, nuget.org
I have also tried using a dedicated nuget.config file instead of expicitly adding the source on the run. This also fails, but curiously, the Github Packages registry is not even listed.
In other workflows I am also using the GITHUB_TOKEN to publish/write to the Gihub Packages registry. Now I only need to read from it, but the permissions should be okay I guess.
Any thoughts on why this keeps crahing? Any help is appreciated! Thanks.
Solved it now by myself. Posting here so it might be useful for someone else.
create nuget.config at project root, include a packageSourceMapping
section.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github" value="https://nuget.pkg.github.com/myOrg/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="github">
<package pattern="packageId" />
</packageSource>
<packageSource key="nuget">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
update the source's credentials on-the-fly in the GH action's execution
name: ci
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
issues: write
steps:
- name: Check that shit out
uses: actions/checkout@v3
- name: Set that shit up
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.x.x'
- name: Build that shit
run: |
dotnet nuget update source github -u ${{ github.actor }} -p ${{ secrets.READ_GH_PACKAGES_PAT_ORG }} --store-password-in-clear-text
dotnet restore ./project.sln
dotnet build ./project.sln --no-restore --configuration Release --nologo
Note, that in my case I couldn't use the built-in ${{ secrets.GITHUB_TOKEN }}
and had to create one myself, since the repo containing the registry is private and not public. I also had to authorize the token for use within my organisation.