From 2b0d66b7b5ea5d1d04904ffa46d016e8b996be45 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 20 Feb 2026 13:40:15 -0500 Subject: [PATCH] Fix Gitea NuGet workflow to run without Node-based checkout in container. --- .gitea/workflows/nuget-publish.yml | 58 ++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/nuget-publish.yml b/.gitea/workflows/nuget-publish.yml index 3d5d567..f3b0310 100644 --- a/.gitea/workflows/nuget-publish.yml +++ b/.gitea/workflows/nuget-publish.yml @@ -11,8 +11,19 @@ jobs: container: image: mcr.microsoft.com/dotnet/sdk:10.0 steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Checkout Repository + run: | + set -euo pipefail + REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" + if [ -n "${GITHUB_TOKEN:-}" ]; then + REPO_URL="${GITHUB_SERVER_URL/https:\/\//https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@}/${GITHUB_REPOSITORY}.git" + fi + + git init . + git config --global --add safe.directory "$PWD" + git remote add origin "$REPO_URL" + git fetch --depth=1 origin "${GITHUB_SHA}" + git checkout --detach FETCH_HEAD - name: Restore run: dotnet restore CBDD.slnx @@ -28,21 +39,29 @@ jobs: dotnet pack src/CBDD.Core/ZB.MOM.WW.CBDD.Core.csproj -c Release -o nupkgs --no-build dotnet pack src/CBDD.SourceGenerators/ZB.MOM.WW.CBDD.SourceGenerators.csproj -c Release -o nupkgs --no-build - - name: Upload Package Artifacts - uses: actions/upload-artifact@v4 - with: - name: nuget-packages - path: nupkgs/*.nupkg - publish-to-gitea: needs: build-and-pack runs-on: ubuntu-latest - if: ${{ gitea.ref == 'refs/heads/main' && secrets.GITEA_NUGET_USERNAME != '' && secrets.GITEA_NUGET_TOKEN != '' }} + if: ${{ github.ref == 'refs/heads/main' }} container: image: mcr.microsoft.com/dotnet/sdk:10.0 + env: + GITEA_NUGET_USERNAME: ${{ secrets.GITEA_NUGET_USERNAME }} + GITEA_NUGET_TOKEN: ${{ secrets.GITEA_NUGET_TOKEN }} steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Checkout Repository + run: | + set -euo pipefail + REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" + if [ -n "${GITHUB_TOKEN:-}" ]; then + REPO_URL="${GITHUB_SERVER_URL/https:\/\//https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@}/${GITHUB_REPOSITORY}.git" + fi + + git init . + git config --global --add safe.directory "$PWD" + git remote add origin "$REPO_URL" + git fetch --depth=1 origin "${GITHUB_SHA}" + git checkout --detach FETCH_HEAD - name: Restore run: dotnet restore CBDD.slnx @@ -60,15 +79,26 @@ jobs: - name: Configure Gitea NuGet Source run: | + set -euo pipefail + USERNAME="${GITEA_NUGET_USERNAME:-${GITHUB_ACTOR}}" + TOKEN="${GITEA_NUGET_TOKEN:-${GITHUB_TOKEN:-}}" + + if [ -z "$TOKEN" ]; then + echo "No token available for NuGet publish" + exit 1 + fi + + dotnet nuget remove source gitea >/dev/null 2>&1 || true dotnet nuget add source \ - "https://gitea.dohertylan.com/api/packages/dohertj2/nuget/index.json" \ + "${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/nuget/index.json" \ --name gitea \ - --username "${{ secrets.GITEA_NUGET_USERNAME }}" \ - --password "${{ secrets.GITEA_NUGET_TOKEN }}" \ + --username "$USERNAME" \ + --password "$TOKEN" \ --store-password-in-clear-text - name: Publish Packages run: | + set -euo pipefail for pkg in nupkgs/*.nupkg; do if [ -f "$pkg" ] && [[ "$pkg" != *.snupkg ]]; then dotnet nuget push "$pkg" --source gitea --skip-duplicate