Skip to content

Instantly share code, notes, and snippets.

@woehrl01
Last active July 21, 2021 11:23
Show Gist options
  • Save woehrl01/eba8e0e019b5fcd1f33d7986c78263ae to your computer and use it in GitHub Desktop.
Save woehrl01/eba8e0e019b5fcd1f33d7986c78263ae to your computer and use it in GitHub Desktop.
GitHub Action Nuget restore configuration
# This gist demonstrated how you can configure NuGet source without storing the credentials in plaintext on the disc
# We enable this by only storing references to environment variables into the NuGet configuration (%NUGET_USERNAME%)
name: Configure NuGet source on private GitHub package repository
jobs:
build:
env:
NUGET_USERNAME: ${{ secrets.NUGET_USERNAME }} #Needs to be the user associated with the personal access token (PAT)
NUGET_PATTOKEN: ${{ secrets.NUGET_PATTOKEN }} #PAT only needs the read:packages scope
NUGET_GITHUB_ORGANISATION: ${{ github.repository_owner }} #Name of the organization where the feed is stored
steps:
- run: |
if ! grep -q "github_$NUGET_GITHUB_ORGANISATION" ~/.nuget/NuGet/NuGet.Config;
then
dotnet nuget add source --username "%NUGET_USERNAME%" --password "%NUGET_PATTOKEN%" \
--store-password-in-clear-text --name "github_$NUGET_GITHUB_ORGANISATION" \
"https://nuget.pkg.github.com/$NUGET_GITHUB_ORGANISATION/index.json";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment