Skip to content

Commit

Permalink
ci: simplify unit tests workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
raczu committed Mar 31, 2024
1 parent a3c17e9 commit 0db3d74
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
name: unit tests

on: [push]

env:
DOTNET_MINIMUM_TEST_COVERAGE: 0

jobs:
tests:
dotnet-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./Server/ReasnAPI
steps:
- uses: actions/checkout@v4
- name: Determine ReasnAPI solution
run: echo SOLUTION_FILE=$(realpath ./Server/ReasnAPI/ReasnAPI.sln) >> $GITHUB_ENV


- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
Expand All @@ -19,26 +22,31 @@ jobs:
run: dotnet tool install -g coverlet.console

- name: Install dependencies
run: dotnet restore ${{ env.SOLUTION_FILE }}
run: dotnet restore

- name: Build solution
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore
run: dotnet build --no-restore

- name: Test with dotnet
run: |
RESULTS_FILENAME=results-$(date +"%Y-%m-%d_%H_%M_%S")
dotnet test ${{ env.SOLUTION_FILE }} --logger "trx;logfilename=$RESULTS_FILENAME.trx" --logger "html;logfilename=$RESULTS_FILENAME.html" --no-build --results-directory "TestResults-${{ github.sha }}"
run: >
dotnet test
--no-build
--verbosity normal
--logger "trx;logfilename=commit-${{ github.sha }}.trx"
--results-directory "TestResults-commit-${{ github.sha }}"
- name: Run coverlet
run: |
TEST_ASSEMBLY=$(find ./Server/ReasnAPI/ReasnAPI.Tests/bin/ -name "ReasnAPI.Tests.dll")
coverlet "$TEST_ASSEMBLY" --target "dotnet" --targetargs "test ${{ env.SOLUTION_FILE }} --no-build"
run: >
coverlet .
--target "dotnet"
--targetargs "test --no-build"
--threshold ${{ env.DOTNET_MINIMUM_TEST_COVERAGE }}
- name: Upload dotnet test results
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: dotnet-results-${{ github.sha }}
path: TestResults-${{ github.sha }}
name: dotnet-results-commit-${{ github.sha }}
path: TestResults-commit-${{ github.sha }}
retention-days: 14

0 comments on commit 0db3d74

Please sign in to comment.