From 588f630af56e49df85dd0a447b028e3379847d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Vieira?= Date: Tue, 10 Feb 2026 14:35:37 +0000 Subject: [PATCH 1/3] Make the restore-dotnet composite compatible with projects using nuget.config --- restore-dotnet/action.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/restore-dotnet/action.yml b/restore-dotnet/action.yml index 1094ac5e..600357be 100644 --- a/restore-dotnet/action.yml +++ b/restore-dotnet/action.yml @@ -20,13 +20,18 @@ runs: with: dotnet-version: ${{ inputs.dotnetVersion }} - - name: Add Trakx github nuget source + - name: Ensure Trakx github nuget source exists (only if missing) shell: bash - run: dotnet nuget add source "https://nuget.pkg.github.com/trakx/index.json" - --name "github" - --username "trakx-bot" - --password ${{inputs.packageReadonlyPat}} - --store-password-in-clear-text + run: | + set -euo pipefail + if dotnet nuget list source | grep -qE '^\s*github\s'; then + echo "NuGet source 'github' already exists." + echo "ADDED_GITHUB_SOURCE=false" >> "$GITHUB_ENV" + else + echo "Adding NuGet source 'github'." + dotnet nuget add source "https://nuget.pkg.github.com/trakx/index.json" --name "github" + echo "ADDED_GITHUB_SOURCE=true" >> "$GITHUB_ENV" + fi - name: Restore Cache uses: actions/cache@v4 @@ -39,8 +44,10 @@ runs: shell: bash env: DOTNET_NUGET_SIGNATURE_VERIFICATION: false + NUGET_AUTH_TOKEN: ${{ inputs.packageReadonlyPat }} run: dotnet restore --locked-mode - - name: Remove Trakx github source + - name: Remove Trakx github source (only if action added it) + if: env.ADDED_GITHUB_SOURCE == 'true' shell: bash - run: dotnet nuget remove source "github" \ No newline at end of file + run: dotnet nuget remove source "github" || true \ No newline at end of file From 2a3e1ef5c14921058048dd5da09d79ea7d3fd75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Vieira?= Date: Tue, 10 Feb 2026 14:49:58 +0000 Subject: [PATCH 2/3] Fix action --- restore-dotnet/action.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/restore-dotnet/action.yml b/restore-dotnet/action.yml index 600357be..1c738875 100644 --- a/restore-dotnet/action.yml +++ b/restore-dotnet/action.yml @@ -24,12 +24,16 @@ runs: shell: bash run: | set -euo pipefail - if dotnet nuget list source | grep -qE '^\s*github\s'; then - echo "NuGet source 'github' already exists." + + FEED_NAME="github" + FEED_URL="https://nuget.pkg.github.com/trakx/index.json" + + if dotnet nuget list source --format Short | awk '{print $2}' | grep -qxF "$FEED_URL"; then + echo "GitHub Packages feed already configured ($FEED_URL)." echo "ADDED_GITHUB_SOURCE=false" >> "$GITHUB_ENV" else - echo "Adding NuGet source 'github'." - dotnet nuget add source "https://nuget.pkg.github.com/trakx/index.json" --name "github" + echo "Adding GitHub Packages feed as '$FEED_NAME' ($FEED_URL)." + dotnet nuget add source "$FEED_URL" --name "$FEED_NAME" echo "ADDED_GITHUB_SOURCE=true" >> "$GITHUB_ENV" fi From 8ead22d6c396eae870e20bf57276ff40ce37bc51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Vieira?= Date: Tue, 10 Feb 2026 15:08:26 +0000 Subject: [PATCH 3/3] Fix action --- restore-dotnet/action.yml | 43 +++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/restore-dotnet/action.yml b/restore-dotnet/action.yml index 1c738875..b14469b5 100644 --- a/restore-dotnet/action.yml +++ b/restore-dotnet/action.yml @@ -20,21 +20,52 @@ runs: with: dotnet-version: ${{ inputs.dotnetVersion }} - - name: Ensure Trakx github nuget source exists (only if missing) + - name: Ensure Trakx GitHub Packages source exists and has credentials shell: bash + env: + PACKAGE_READONLY_PAT: ${{ inputs.packageReadonlyPat }} run: | set -euo pipefail - FEED_NAME="github" FEED_URL="https://nuget.pkg.github.com/trakx/index.json" + FEED_FALLBACK_NAME="github" + FEED_USERNAME="trakx-bot" + + get_nuget_source_name_by_url() { + local source_url="$1" + dotnet nuget list source \ + | awk -v url="$source_url" ' + match($0, /^[[:space:]]*[0-9]+[.][[:space:]]*(.+)[[:space:]]+\[(Enabled|Disabled)\][[:space:]]*$/, m) { + name=m[1] + status=m[2] + next + } + index($0, url) && status=="Enabled" { + print name + exit + } + ' + } + + FEED_NAME="$(get_nuget_source_name_by_url "$FEED_URL" || true)" - if dotnet nuget list source --format Short | awk '{print $2}' | grep -qxF "$FEED_URL"; then - echo "GitHub Packages feed already configured ($FEED_URL)." + if [ -n "${FEED_NAME:-}" ]; then + echo "GitHub feed already configured as '$FEED_NAME'. Updating credentials." echo "ADDED_GITHUB_SOURCE=false" >> "$GITHUB_ENV" + + dotnet nuget update source "$FEED_NAME" \ + --username "$FEED_USERNAME" \ + --password "$PACKAGE_READONLY_PAT" \ + --store-password-in-clear-text else - echo "Adding GitHub Packages feed as '$FEED_NAME' ($FEED_URL)." - dotnet nuget add source "$FEED_URL" --name "$FEED_NAME" + echo "GitHub feed not configured. Adding as '$FEED_FALLBACK_NAME'." echo "ADDED_GITHUB_SOURCE=true" >> "$GITHUB_ENV" + + dotnet nuget add source "$FEED_URL" \ + --name "$FEED_FALLBACK_NAME" \ + --username "$FEED_USERNAME" \ + --password "$PACKAGE_READONLY_PAT" \ + --store-password-in-clear-text fi - name: Restore Cache