From 813343220c58835f2834cfa1e17e4c6eb6fc72ca Mon Sep 17 00:00:00 2001 From: Morten Buhl Date: Tue, 21 Apr 2026 13:24:20 +0200 Subject: [PATCH 1/2] Publish nupkg from pr to internal dev feed --- .github/workflows/common-build.yml | 101 +++++++++++++++++++++--- .github/workflows/common-nuget-push.yml | 8 +- 2 files changed, 92 insertions(+), 17 deletions(-) diff --git a/.github/workflows/common-build.yml b/.github/workflows/common-build.yml index 44f0207..6449a83 100644 --- a/.github/workflows/common-build.yml +++ b/.github/workflows/common-build.yml @@ -3,25 +3,106 @@ name: Build on: workflow_call: +permissions: + contents: read + pull-requests: write + issues: write + +env: + PROJECT_PATH: '**/*.csproj' + PRIVATE_NUGET_FEED_URL: 'https://core.nuget.dynamicweb-cms.com/v3/index.json' + PRIVATE_NUGET_FEED_API_KEY: ${{ secrets.DYNAMICWEB_NUGET_API_KEY }} + + --api-key "$LOCAL_FEED_API" --skip-duplicate + jobs: - Build: + test: runs-on: ubuntu-latest steps: - name: Set current date as env variable run: echo "NOW=$(date +'%Y-%m-%d-%H%M')" >> $GITHUB_ENV - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 9.0.x + - name: Restore dependencies run: dotnet restore + - name: Build - run: dotnet build --no-restore --configuration Release --version-suffix ${{ github.event.number }} + run: dotnet build --no-restore --configuration Release + - name: Test - run: dotnet test --no-build --verbosity normal - #- name: Push Nuget Packages to DEV feed - # uses: EasyDesk/action-nuget-push@v1.0.0 - # with: - # publish-dir: "./**" # optional, default is . - # nuget-url: 'http://feed.dw-i001.nuget.dynamicweb-cms.com/v3/index.json' + run: dotnet test --no-build --configuration Release --verbosity normal --logger trx --results-directory ./test-results + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results + path: ./test-results/*.trx + build-and-publish: + needs: test + runs-on: ubuntu-latest + if: github.event.pull_request.head.repo.full_name == github.repository + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 9.0.x + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --no-restore --configuration Release + + - name: Generate prerelease version + id: version + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + RUN_NUMBER=${{ github.run_number }} + + # Use dotnet to evaluate the VersionPrefix property + BASE_VERSION=$(dotnet msbuild ${{ env.PROJECT_PATH }} -getProperty:VersionPrefix -nologo) + + if [ -z "$BASE_VERSION" ]; then + echo "Error: Could not extract VersionPrefix from ${{ env.PROJECT_PATH }}" + exit 1 + fi + + PRERELEASE_VERSION="${BASE_VERSION}-pr${PR_NUMBER}.${RUN_NUMBER}" + echo "prerelease_version=${PRERELEASE_VERSION}" >> $GITHUB_OUTPUT + echo "Extracted base version: ${BASE_VERSION}" + echo "Generated prerelease version: ${PRERELEASE_VERSION}" + + - name: Build + run: dotnet build --no-restore --configuration Release + + - name: Pack NuGet package + run: | + dotnet pack ${{ env.PROJECT_PATH }} \ + --no-build \ + --configuration Release \ + --output ./artifacts \ + -p:PackageVersion=${{ steps.version.outputs.prerelease_version }} \ + -p:VersionSuffix="" + + - name: Push to Dynamicweb NuGet feed + run: | + dotnet nuget push ./artifacts/*.nupkg \ + --api-key ${{ secrets.DYNAMICWEB_NUGET_API_KEY }} \ + --source ${{ env.PRIVATE_NUGET_FEED_URL }} \ + --skip-duplicate + + - name: Upload package artifact + uses: actions/upload-artifact@v4 + with: + name: nuget-package-pr${{ github.event.pull_request.number }} + path: ./artifacts/*.nupkg diff --git a/.github/workflows/common-nuget-push.yml b/.github/workflows/common-nuget-push.yml index b6f8d60..89a6d38 100644 --- a/.github/workflows/common-nuget-push.yml +++ b/.github/workflows/common-nuget-push.yml @@ -8,7 +8,6 @@ on: DW_TOKEN_API: required: false env: - dwPackageVersion: ${{ format('{0}{1}', vars.RELEASEPREFIX, vars.PRERELEASEVERSION) }} dwRepo: ${{ github.event.repository.name }} GH_TOKEN: ${{secrets.DW_TOKEN_API}} @@ -36,9 +35,4 @@ jobs: with: nuget-api-key: "${{secrets.NUGETAPI}}" publish-dir: "./**" # optional, default is . - #- run: | - # echo ${{ secrets.DW_TOKEN_API }} - # gh api --method PATCH -H "Accept:application/vnd.github+json" /repos/dynamicweb/${{ github.event.repository.name }}/actions/variables/PRERELEASEVERSION -f name='PRERELEASEVERSION' -f value='SETMEGODGODDAMMIT' - # env: - # GH_TOKEN: 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 - #- run: gh api --method PATCH -H "Accept:application/vnd.github+json" /repos/dynamicweb/$dwRepo/actions/variables/PRERELEASEVERSION -f value='0005' + \ No newline at end of file From abbbff2f3c01a3766a089ee3fe9e22b3c9d43c02 Mon Sep 17 00:00:00 2001 From: Morten Buhl <33415638+MrBuhl@users.noreply.github.com> Date: Tue, 21 Apr 2026 16:17:59 +0200 Subject: [PATCH 2/2] Fix variable names Added a required secret for NuGet API key and removed unused steps. --- .github/workflows/common-build.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/common-build.yml b/.github/workflows/common-build.yml index 6449a83..594f078 100644 --- a/.github/workflows/common-build.yml +++ b/.github/workflows/common-build.yml @@ -2,6 +2,9 @@ name: Build on: workflow_call: + secrets: + DYNAMICWEB_NUGET_API_KEY: + required: true permissions: contents: read @@ -13,16 +16,11 @@ env: PRIVATE_NUGET_FEED_URL: 'https://core.nuget.dynamicweb-cms.com/v3/index.json' PRIVATE_NUGET_FEED_API_KEY: ${{ secrets.DYNAMICWEB_NUGET_API_KEY }} - --api-key "$LOCAL_FEED_API" --skip-duplicate - jobs: test: runs-on: ubuntu-latest steps: - - name: Set current date as env variable - run: echo "NOW=$(date +'%Y-%m-%d-%H%M')" >> $GITHUB_ENV - - uses: actions/checkout@v4 - + - name: Setup .NET uses: actions/setup-dotnet@v4 with: