Skip to content

Commit 225c596

Browse files
committed
Refactor GitHub Actions workflows to consolidate test execution into a reusable matrix configuration and add support for .NET 10.0
1 parent d78beb0 commit 225c596

File tree

3 files changed

+84
-114
lines changed

3 files changed

+84
-114
lines changed

.github/workflows/pull-request.yml

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,7 @@ on:
55
branches: ['master']
66

77
jobs:
8-
prepare:
9-
runs-on: ubuntu-latest
10-
outputs:
11-
matrix: ${{ steps.set-matrix.outputs.matrix }}
12-
steps:
13-
- uses: actions/checkout@v2
14-
- id: set-matrix
15-
run: |
16-
PROJECTS=$(find . -name '*.Tests.csproj' | sed 's|.*/\([^/]*\)\.csproj|\1|' | jq -R -s -c 'split("\n")[:-1]')
17-
FRAMEWORKS='["net8.0", "net9.0"]'
18-
MATRIX=$(jq -n \
19-
--argjson projects "$PROJECTS" \
20-
--argjson frameworks "$FRAMEWORKS" \
21-
'{
22-
"test_project": $projects,
23-
"framework": $frameworks
24-
}')
25-
echo "matrix=$(echo $MATRIX | jq -c .)" >> $GITHUB_OUTPUT
26-
shell: bash
27-
288
tests:
29-
needs: prepare
30-
runs-on: ubuntu-latest
31-
name: ${{ matrix.test_project }} ${{ matrix.framework }}
32-
strategy:
33-
matrix:
34-
test_project: ${{fromJson(needs.prepare.outputs.matrix).test_project}}
35-
framework: ${{fromJson(needs.prepare.outputs.matrix).framework}}
36-
fail-fast: false
37-
steps:
38-
- name: Checkout code
39-
uses: actions/checkout@v2
40-
41-
- name: Setup .NET
42-
uses: actions/setup-dotnet@v4
43-
with:
44-
dotnet-version: |
45-
8
46-
9
47-
10
48-
49-
- name: Docker Information
50-
run: |
51-
echo -e "\n\033[0;34mDocker System Info \033[0m"
52-
docker system info
53-
echo -e "\n\033[0;34mDocker Containers \033[0m"
54-
docker ps -a
55-
shell: bash
56-
57-
- name: Restore tools
58-
run: dotnet tool restore
59-
shell: bash
60-
61-
- name: Build project
62-
run: |
63-
PROJECT_PATH=$(find . -name "${{ matrix.test_project }}.csproj")
64-
dotnet build "$PROJECT_PATH" -c Debug /p:WarningLevel=0 -f "${{ matrix.framework }}"
65-
shell: bash
66-
67-
- name: Run tests
68-
run: |
69-
PROJECT_PATH=$(find . -name "${{ matrix.test_project }}.csproj")
70-
echo -e "\n\033[0;34mTesting ${{ matrix.test_project }} (${{ matrix.framework }})\033[0m\n"
71-
dotnet test "$PROJECT_PATH" -c Debug --no-build -f "${{ matrix.framework }}" -p:"CollectCoverage=true" -p:"Exclude=[xunit.*]*" -p:"CoverletOutputFormat=opencover"
72-
shell: bash
9+
uses: ./.github/workflows/test-matrix.yml
10+
with:
11+
include_docker_info: true

.github/workflows/release.yml

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,10 @@ on:
66
- "*"
77

88
jobs:
9-
prepare:
10-
runs-on: ubuntu-latest
11-
outputs:
12-
matrix: ${{ steps.set-matrix.outputs.matrix }}
13-
steps:
14-
- uses: actions/checkout@v2
15-
- id: set-matrix
16-
run: |
17-
PROJECTS=$(find . -name '*.Tests.csproj' | sed 's|.*/\([^/]*\)\.csproj|\1|' | jq -R -s -c 'split("\n")[:-1]')
18-
FRAMEWORKS='["net8.0", "net9.0"]'
19-
MATRIX=$(jq -n \
20-
--argjson projects "$PROJECTS" \
21-
--argjson frameworks "$FRAMEWORKS" \
22-
'{
23-
"test_project": $projects,
24-
"framework": $frameworks
25-
}')
26-
echo "matrix=$(echo $MATRIX | jq -c .)" >> $GITHUB_OUTPUT
27-
shell: bash
28-
299
tests:
30-
needs: prepare
31-
runs-on: ubuntu-latest
32-
name: ${{ matrix.test_project }} ${{ matrix.framework }}
33-
strategy:
34-
matrix:
35-
test_project: ${{fromJson(needs.prepare.outputs.matrix).test_project}}
36-
framework: ${{fromJson(needs.prepare.outputs.matrix).framework}}
37-
fail-fast: false
38-
steps:
39-
- name: Checkout code
40-
uses: actions/checkout@v2
41-
42-
- name: Setup .NET
43-
uses: actions/setup-dotnet@v4
44-
with:
45-
dotnet-version: |
46-
8
47-
9
48-
10
49-
50-
- name: Restore tools
51-
run: dotnet tool restore
52-
shell: bash
53-
54-
- name: Build and Test
55-
run: |
56-
PROJECT_PATH=$(find . -name "${{ matrix.test_project }}.csproj")
57-
dotnet test "$PROJECT_PATH" -c Debug -f "${{ matrix.framework }}"
58-
shell: bash
59-
10+
uses: ./.github/workflows/test-matrix.yml
11+
with:
12+
include_docker_info: false
6013
release:
6114
needs: tests
6215
runs-on: ubuntu-latest

.github/workflows/test-matrix.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Run Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
include_docker_info:
7+
description: 'Whether to include Docker information step'
8+
required: false
9+
type: boolean
10+
default: false
11+
12+
jobs:
13+
prepare:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
matrix: ${{ steps.set-matrix.outputs.matrix }}
17+
steps:
18+
- uses: actions/checkout@v2
19+
- id: set-matrix
20+
run: |
21+
PROJECTS=$(find . -name '*.Tests.csproj' | sed 's|.*/\([^/]*\)\.csproj|\1|' | jq -R -s -c 'split("\n")[:-1]')
22+
FRAMEWORKS='["net8.0", "net9.0","net10.0"]'
23+
MATRIX=$(jq -n \
24+
--argjson projects "$PROJECTS" \
25+
--argjson frameworks "$FRAMEWORKS" \
26+
'{
27+
"test_project": $projects,
28+
"framework": $frameworks
29+
}')
30+
echo "matrix=$(echo $MATRIX | jq -c .)" >> $GITHUB_OUTPUT
31+
shell: bash
32+
33+
tests:
34+
needs: prepare
35+
runs-on: ubuntu-latest
36+
name: ${{ matrix.test_project }} ${{ matrix.framework }}
37+
strategy:
38+
matrix:
39+
test_project: ${{fromJson(needs.prepare.outputs.matrix).test_project}}
40+
framework: ${{fromJson(needs.prepare.outputs.matrix).framework}}
41+
fail-fast: false
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v2
45+
46+
- name: Setup .NET
47+
uses: actions/setup-dotnet@v4
48+
with:
49+
dotnet-version: |
50+
8
51+
9
52+
10
53+
54+
- name: Docker Information
55+
if: ${{ inputs.include_docker_info }}
56+
run: |
57+
echo -e "\n\033[0;34mDocker System Info \033[0m"
58+
docker system info
59+
echo -e "\n\033[0;34mDocker Containers \033[0m"
60+
docker ps -a
61+
shell: bash
62+
63+
- name: Restore tools
64+
run: dotnet tool restore
65+
shell: bash
66+
67+
- name: Build project
68+
run: |
69+
PROJECT_PATH=$(find . -name "${{ matrix.test_project }}.csproj")
70+
dotnet build "$PROJECT_PATH" -c Debug /p:WarningLevel=0 -f "${{ matrix.framework }}"
71+
shell: bash
72+
73+
- name: Run tests
74+
run: |
75+
PROJECT_PATH=$(find . -name "${{ matrix.test_project }}.csproj")
76+
echo -e "\n\033[0;34mTesting ${{ matrix.test_project }} (${{ matrix.framework }})\033[0m\n"
77+
dotnet test "$PROJECT_PATH" -c Debug --no-build -f "${{ matrix.framework }}" -p:"CollectCoverage=true" -p:"Exclude=[xunit.*]*" -p:"CoverletOutputFormat=opencover"
78+
shell: bash

0 commit comments

Comments
 (0)