Skip to content

Commit 13e40aa

Browse files
authored
Add blocking .NET test gates for PRs and releases (#17)
1 parent dfa40ed commit 13e40aa

2 files changed

Lines changed: 101 additions & 7 deletions

File tree

.github/workflows/pr-tests.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: PR Unit Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "**"
7+
8+
jobs:
9+
test-gate:
10+
name: PR Test Gate
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v6
16+
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v5
19+
with:
20+
dotnet-version: '10.0.x'
21+
cache: true
22+
cache-dependency-path: |
23+
FluentAAS/**/*.csproj
24+
FluentAAS/global.json
25+
26+
- name: Locate solution file
27+
id: solution
28+
shell: bash
29+
run: |
30+
SOLUTION=$(find . -maxdepth 5 -name "*.sln" | head -n 1)
31+
if [ -z "$SOLUTION" ]; then
32+
echo "❌ No solution file (*.sln) found in the repo."
33+
exit 1
34+
fi
35+
echo "SOLUTION_PATH=$SOLUTION" >> $GITHUB_OUTPUT
36+
echo "✅ Found solution: $SOLUTION"
37+
38+
- name: Restore dependencies
39+
run: dotnet restore "${{ steps.solution.outputs.SOLUTION_PATH }}"
40+
41+
- name: Build solution
42+
run: dotnet build "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-restore
43+
44+
# Blocking PR gate: reviewers can see this check and it must pass before merge.
45+
- name: Run unit tests (blocking gate)
46+
run: dotnet test "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx"
47+
48+
- name: Upload test result artifacts
49+
if: always()
50+
uses: actions/upload-artifact@v7
51+
with:
52+
name: pr-test-results
53+
path: |
54+
**/TestResults/*.trx
55+
**/test-results.trx

.github/workflows/release-nuget.yml

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,50 @@ on:
2020
default: "main"
2121

2222
jobs:
23+
# Blocking gate: all tests must pass before any packing/publishing can run.
24+
test-gate:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v6
30+
with:
31+
fetch-depth: 0
32+
ref: ${{ inputs.ref || github.ref }}
33+
34+
- name: Setup .NET
35+
uses: actions/setup-dotnet@v5
36+
with:
37+
dotnet-version: '10.0.x'
38+
cache: true
39+
cache-dependency-path: |
40+
FluentAAS/**/*.csproj
41+
FluentAAS/global.json
42+
43+
- name: Locate solution file
44+
id: solution
45+
shell: bash
46+
run: |
47+
SOLUTION=$(find . -maxdepth 5 -name "*.sln" | head -n 1)
48+
if [ -z "$SOLUTION" ]; then
49+
echo "❌ No solution file (*.sln) found in the repo."
50+
exit 1
51+
fi
52+
echo "SOLUTION_PATH=$SOLUTION" >> $GITHUB_OUTPUT
53+
echo "✅ Found solution: $SOLUTION"
54+
55+
- name: Restore dependencies
56+
run: dotnet restore "${{ steps.solution.outputs.SOLUTION_PATH }}"
57+
58+
- name: Build solution
59+
run: dotnet build "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-restore
60+
61+
- name: Test solution (blocking gate)
62+
run: dotnet test "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-build --verbosity normal
63+
2364
build-pack-push:
2465
runs-on: ubuntu-latest
66+
needs: test-gate
2567

2668
steps:
2769
- name: Checkout
@@ -85,9 +127,6 @@ jobs:
85127
- name: Build solution
86128
run: dotnet build "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-restore
87129

88-
- name: Test solution
89-
run: dotnet test "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release --no-build --verbosity normal
90-
91130
- name: Pack NuGet packages
92131
run: dotnet pack "${{ steps.solution.outputs.SOLUTION_PATH }}" -c Release -o ./artifacts --no-build /p:PackageVersion=${{ steps.version.outputs.VERSION }}
93132

@@ -96,16 +135,16 @@ jobs:
96135
run: |
97136
shopt -s nullglob
98137
packages=(./artifacts/*.nupkg)
99-
138+
100139
if [ ${#packages[@]} -eq 0 ]; then
101140
echo "❌ No NuGet packages found in ./artifacts/"
102141
exit 1
103142
fi
104-
143+
105144
echo "📦 Generated NuGet packages:"
106145
VERSION="${{ steps.version.outputs.VERSION }}"
107146
ESCAPED_VERSION="${VERSION//./\\.}"
108-
147+
109148
for pkg in "${packages[@]}"; do
110149
filename=$(basename "$pkg")
111150
echo " - $filename"
@@ -149,4 +188,4 @@ jobs:
149188
prerelease: false
150189
env:
151190
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152-
GITHUB_REPOSITORY: ${{ github.repository }}
191+
GITHUB_REPOSITORY: ${{ github.repository }}

0 commit comments

Comments
 (0)