From b4067a3cd84a8c5bdeaa29e0a272529d0fa8ce2e Mon Sep 17 00:00:00 2001 From: Stefan Seeland <168659+stesee@users.noreply.github.com> Date: Tue, 6 Jan 2026 10:48:06 +0100 Subject: [PATCH 1/3] Refactor GitHub Actions workflow for .NET --- .github/workflows/dotnet.yml | 127 ++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index f33679db..ff1bdb56 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -5,6 +5,7 @@ env: on: push: + pull_request: jobs: build: @@ -13,84 +14,84 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal --configuration Release --logger "trx;LogFileName=${{ runner.workspace }}/OpenXmlPowerTools/TestResult/test_results.trx" - - name: Publish Unit Test Results - uses: actions/upload-artifact@v6 - if: failure() - with: - name: TestResult - path: "TestResult/**/*" + - uses: actions/checkout@v6 + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: | + 8.0.x + 10.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal --configuration Release --logger "trx;LogFileName=${{ runner.workspace }}/OpenXmlPowerTools/TestResult/test_results.trx" + - name: Publish Unit Test Results + uses: actions/upload-artifact@v6 + if: failure() + with: + name: TestResult + path: "TestResult/**/*" deployRelease: if: github.ref == 'refs/heads/release' runs-on: ubuntu-latest - needs: build + needs: build steps: - - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: NugetPush - env: + - uses: actions/checkout@v6 + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: | + 8.0.x + 10.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: NugetPush + env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | + if: env.NUGET_TOKEN_EXISTS != '' + run: | dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TOKEN}} --source https://api.nuget.org/v3/index.json - - name: Github Release - shell: bash - env: - GITHUB_TOKEN: ${{ github.TOKEN }} - if: env.GITHUB_TOKEN != '' - run: | + - name: Github Release + shell: bash + env: + GITHUB_TOKEN: ${{ github.TOKEN }} + if: env.GITHUB_TOKEN != '' + run: | gh release create ${{env.CURRENT_VERSION}} ./OpenXmlPowerTools/bin/Release/*.*nupkg --generate-notes deployTest: if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest - needs: build + needs: build steps: - - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: NugetPush - env: + - uses: actions/checkout@v6 + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: | + 8.0.x + 10.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: NugetPush + env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | + if: env.NUGET_TOKEN_EXISTS != '' + run: | ls ./OpenXmlPowerTools/bin/Release dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json - - name: Github Prerelease - shell: bash - env: - GITHUB_TOKEN: ${{ github.TOKEN }} - if: env.GITHUB_TOKEN != '' - run: | + - name: Github Prerelease + shell: bash + env: + GITHUB_TOKEN: ${{ github.TOKEN }} + if: env.GITHUB_TOKEN != '' + run: | gh release create ${{env.CURRENT_VERSION}} ./OpenXmlPowerTools/bin/Release/*.*nupkg --prerelease --generate-notes From 461cc86bfb2e57622d8cbf6388a654d97e55df43 Mon Sep 17 00:00:00 2001 From: Stefan Seeland <168659+stesee@users.noreply.github.com> Date: Tue, 6 Jan 2026 11:04:40 +0100 Subject: [PATCH 2/3] Optimize build workflow and artifact handling Adds conditional job execution for push and pull requests from forks, uploads build artifacts only on Ubuntu, and refactors publish/test jobs to use downloaded artifacts instead of rebuilding. This streamlines CI/CD, reduces redundant builds, and improves artifact management. --- .github/workflows/dotnet.yml | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ff1bdb56..1523f4ae 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -9,6 +9,9 @@ on: jobs: build: + if: | + github.event_name == 'push' || + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) runs-on: ${{ matrix.os }} strategy: matrix: @@ -27,6 +30,13 @@ jobs: run: dotnet build --configuration Release --no-restore - name: Test run: dotnet test --no-build --verbosity normal --configuration Release --logger "trx;LogFileName=${{ runner.workspace }}/OpenXmlPowerTools/TestResult/test_results.trx" + - name: Upload build artifacts + uses: actions/upload-artifact@v6 + if: matrix.os == 'ubuntu-latest' + with: + name: build-artifacts + path: | + OpenXmlPowerTools/bin/Release/ - name: Publish Unit Test Results uses: actions/upload-artifact@v6 if: failure() @@ -40,16 +50,10 @@ jobs: needs: build steps: - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 + - name: Download build artifacts + uses: actions/download-artifact@v6 with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore + name: build-artifacts - name: NugetPush env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }} @@ -70,16 +74,10 @@ jobs: needs: build steps: - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 + - name: Download build artifacts + uses: actions/download-artifact@v6 with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore + name: build-artifacts - name: NugetPush env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }} @@ -87,7 +85,6 @@ jobs: run: | ls ./OpenXmlPowerTools/bin/Release dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json - - name: Github Prerelease shell: bash env: From 42b3c961a7737dd7a645fa06abc2cfdc5dbb1631 Mon Sep 17 00:00:00 2001 From: Stefan Seeland <168659+stesee@users.noreply.github.com> Date: Tue, 6 Jan 2026 12:04:01 +0100 Subject: [PATCH 3/3] Restrict deploy jobs to push events on main and release Updated the deployRelease and deployTest jobs in the GitHub Actions workflow to only run on push events to the 'release' and 'main' branches, respectively. This prevents deployments from being triggered by other event types. --- .github/workflows/dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 1523f4ae..c2a4ec07 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -45,7 +45,7 @@ jobs: path: "TestResult/**/*" deployRelease: - if: github.ref == 'refs/heads/release' + if: github.event_name == 'push' && github.ref == 'refs/heads/release' runs-on: ubuntu-latest needs: build steps: @@ -69,7 +69,7 @@ jobs: gh release create ${{env.CURRENT_VERSION}} ./OpenXmlPowerTools/bin/Release/*.*nupkg --generate-notes deployTest: - if: github.ref == 'refs/heads/main' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest needs: build steps: