Skip to content

Commit 16ea007

Browse files
authored
Merge pull request #175 from Codeuctivity/stesee-patch-1
Refactor GitHub Actions workflow for .NET
2 parents 94942a0 + 42b3c96 commit 16ea007

1 file changed

Lines changed: 64 additions & 66 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,90 @@ env:
55

66
on:
77
push:
8+
pull_request:
89

910
jobs:
1011
build:
12+
if: |
13+
github.event_name == 'push' ||
14+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
1115
runs-on: ${{ matrix.os }}
1216
strategy:
1317
matrix:
1418
os: [ubuntu-latest, macos-latest, windows-latest]
1519
steps:
16-
- uses: actions/checkout@v6
17-
- name: Setup .NET
18-
uses: actions/setup-dotnet@v5
19-
with:
20-
dotnet-version: |
21-
8.0.x
22-
10.0.x
23-
- name: Restore dependencies
24-
run: dotnet restore
25-
- name: Build
26-
run: dotnet build --configuration Release --no-restore
27-
- name: Test
28-
run: dotnet test --no-build --verbosity normal --configuration Release --logger "trx;LogFileName=${{ runner.workspace }}/OpenXmlPowerTools/TestResult/test_results.trx"
29-
- name: Publish Unit Test Results
30-
uses: actions/upload-artifact@v6
31-
if: failure()
32-
with:
33-
name: TestResult
34-
path: "TestResult/**/*"
20+
- uses: actions/checkout@v6
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v5
23+
with:
24+
dotnet-version: |
25+
8.0.x
26+
10.0.x
27+
- name: Restore dependencies
28+
run: dotnet restore
29+
- name: Build
30+
run: dotnet build --configuration Release --no-restore
31+
- name: Test
32+
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/
40+
- name: Publish Unit Test Results
41+
uses: actions/upload-artifact@v6
42+
if: failure()
43+
with:
44+
name: TestResult
45+
path: "TestResult/**/*"
3546

3647
deployRelease:
37-
if: github.ref == 'refs/heads/release'
48+
if: github.event_name == 'push' && github.ref == 'refs/heads/release'
3849
runs-on: ubuntu-latest
39-
needs: build
50+
needs: build
4051
steps:
41-
- uses: actions/checkout@v6
42-
- name: Setup .NET
43-
uses: actions/setup-dotnet@v5
44-
with:
45-
dotnet-version: |
46-
8.0.x
47-
10.0.x
48-
- name: Restore dependencies
49-
run: dotnet restore
50-
- name: Build
51-
run: dotnet build --configuration Release --no-restore
52-
- name: NugetPush
53-
env:
52+
- uses: actions/checkout@v6
53+
- name: Download build artifacts
54+
uses: actions/download-artifact@v6
55+
with:
56+
name: build-artifacts
57+
- name: NugetPush
58+
env:
5459
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }}
55-
if: env.NUGET_TOKEN_EXISTS != ''
56-
run: |
60+
if: env.NUGET_TOKEN_EXISTS != ''
61+
run: |
5762
dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TOKEN}} --source https://api.nuget.org/v3/index.json
58-
- name: Github Release
59-
shell: bash
60-
env:
61-
GITHUB_TOKEN: ${{ github.TOKEN }}
62-
if: env.GITHUB_TOKEN != ''
63-
run: |
63+
- name: Github Release
64+
shell: bash
65+
env:
66+
GITHUB_TOKEN: ${{ github.TOKEN }}
67+
if: env.GITHUB_TOKEN != ''
68+
run: |
6469
gh release create ${{env.CURRENT_VERSION}} ./OpenXmlPowerTools/bin/Release/*.*nupkg --generate-notes
6570
6671
deployTest:
67-
if: github.ref == 'refs/heads/main'
72+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
6873
runs-on: ubuntu-latest
69-
needs: build
74+
needs: build
7075
steps:
71-
- uses: actions/checkout@v6
72-
- name: Setup .NET
73-
uses: actions/setup-dotnet@v5
74-
with:
75-
dotnet-version: |
76-
8.0.x
77-
10.0.x
78-
- name: Restore dependencies
79-
run: dotnet restore
80-
- name: Build
81-
run: dotnet build --configuration Release --no-restore
82-
- name: NugetPush
83-
env:
76+
- uses: actions/checkout@v6
77+
- name: Download build artifacts
78+
uses: actions/download-artifact@v6
79+
with:
80+
name: build-artifacts
81+
- name: NugetPush
82+
env:
8483
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }}
85-
if: env.NUGET_TOKEN_EXISTS != ''
86-
run: |
84+
if: env.NUGET_TOKEN_EXISTS != ''
85+
run: |
8786
ls ./OpenXmlPowerTools/bin/Release
8887
dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json
89-
90-
- name: Github Prerelease
91-
shell: bash
92-
env:
93-
GITHUB_TOKEN: ${{ github.TOKEN }}
94-
if: env.GITHUB_TOKEN != ''
95-
run: |
88+
- name: Github Prerelease
89+
shell: bash
90+
env:
91+
GITHUB_TOKEN: ${{ github.TOKEN }}
92+
if: env.GITHUB_TOKEN != ''
93+
run: |
9694
gh release create ${{env.CURRENT_VERSION}} ./OpenXmlPowerTools/bin/Release/*.*nupkg --prerelease --generate-notes

0 commit comments

Comments
 (0)