Skip to content

Commit c38f347

Browse files
committed
Refactor GitHub Actions workflow to add dynamic matrix configuration for test projects and frameworks
1 parent 4e1d916 commit c38f347

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

.github/workflows/release.yml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,28 @@ on:
66
- "*"
77

88
jobs:
9-
release:
9+
prepare:
1010
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
1128

29+
release:
30+
runs-on: ubuntu-latest
1231
steps:
1332
- name: Checkout code
1433
uses: actions/checkout@v2
@@ -21,24 +40,32 @@ jobs:
2140
nuget_api_key: ${{ secrets.NUGET_API_KEY }}
2241
enable_push: 'yes'
2342

24-
sonar:
43+
tests:
44+
needs: prepare
2545
runs-on: ubuntu-latest
46+
name: ${{ matrix.test_project }} ${{ matrix.framework }}
47+
strategy:
48+
matrix:
49+
test_project: ${{fromJson(needs.prepare.outputs.matrix).test_project}}
50+
framework: ${{fromJson(needs.prepare.outputs.matrix).framework}}
51+
fail-fast: false
2652
steps:
2753
- name: Checkout code
2854
uses: actions/checkout@v2
55+
2956
- name: Setup .NET
3057
uses: actions/setup-dotnet@v4
3158
with:
3259
dotnet-version: |
3360
8
3461
9
62+
3563
- name: Restore tools
3664
run: dotnet tool restore
37-
- name: Build, Test and Sonar
38-
uses: swisslife-oss/actions/release-sonar@main
39-
with:
40-
tag: ${{ github.ref_name }}
41-
sonar_token: ${{ secrets.SONAR_TOKEN }}
42-
sonar_project_key: 'SwissLife-OSS_Squadron'
43-
sonar_project_name: "squadron"
44-
sonar_exclusions: ${{ vars.SONAR_EXCLUSIONS }}
65+
shell: bash
66+
67+
- name: Build and Test
68+
run: |
69+
PROJECT_PATH=$(find . -name "${{ matrix.test_project }}.csproj")
70+
dotnet test "$PROJECT_PATH" -c Release -f "${{ matrix.framework }}"
71+
shell: bash

0 commit comments

Comments
 (0)