Skip to content

Commit 461cc86

Browse files
committed
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.
1 parent b4067a3 commit 461cc86

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

.github/workflows/dotnet.yml

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99

1010
jobs:
1111
build:
12+
if: |
13+
github.event_name == 'push' ||
14+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
1215
runs-on: ${{ matrix.os }}
1316
strategy:
1417
matrix:
@@ -27,6 +30,13 @@ jobs:
2730
run: dotnet build --configuration Release --no-restore
2831
- name: Test
2932
run: dotnet test --no-build --verbosity normal --configuration Release --logger "trx;LogFileName=${{ runner.workspace }}/OpenXmlPowerTools/TestResult/test_results.trx"
33+
- name: Upload build artifacts
34+
uses: actions/upload-artifact@v6
35+
if: matrix.os == 'ubuntu-latest'
36+
with:
37+
name: build-artifacts
38+
path: |
39+
OpenXmlPowerTools/bin/Release/
3040
- name: Publish Unit Test Results
3141
uses: actions/upload-artifact@v6
3242
if: failure()
@@ -40,16 +50,10 @@ jobs:
4050
needs: build
4151
steps:
4252
- uses: actions/checkout@v6
43-
- name: Setup .NET
44-
uses: actions/setup-dotnet@v5
53+
- name: Download build artifacts
54+
uses: actions/download-artifact@v6
4555
with:
46-
dotnet-version: |
47-
8.0.x
48-
10.0.x
49-
- name: Restore dependencies
50-
run: dotnet restore
51-
- name: Build
52-
run: dotnet build --configuration Release --no-restore
56+
name: build-artifacts
5357
- name: NugetPush
5458
env:
5559
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }}
@@ -70,24 +74,17 @@ jobs:
7074
needs: build
7175
steps:
7276
- uses: actions/checkout@v6
73-
- name: Setup .NET
74-
uses: actions/setup-dotnet@v5
77+
- name: Download build artifacts
78+
uses: actions/download-artifact@v6
7579
with:
76-
dotnet-version: |
77-
8.0.x
78-
10.0.x
79-
- name: Restore dependencies
80-
run: dotnet restore
81-
- name: Build
82-
run: dotnet build --configuration Release --no-restore
80+
name: build-artifacts
8381
- name: NugetPush
8482
env:
8583
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }}
8684
if: env.NUGET_TOKEN_EXISTS != ''
8785
run: |
8886
ls ./OpenXmlPowerTools/bin/Release
8987
dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json
90-
9188
- name: Github Prerelease
9289
shell: bash
9390
env:

0 commit comments

Comments
 (0)