|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +# PREREQUISITES FOR PUSH-BACK OF TEST RESULTS |
| 4 | +# Please note: test project usually required nuget package JUnitTestLogger |
| 5 | +# to be able to provide JUnit compatible test results XML file (required |
| 6 | +# for pushing back details on succeeded/failed tests) |
| 7 | +# |
| 8 | +# NuGet install command: |
| 9 | +# - Install-Package JUnitTestLogger |
| 10 | + |
| 11 | +# Controls when the action will run. |
| 12 | +on: |
| 13 | + # Triggers the workflow on push or pull request events but only for the master branch |
| 14 | + push: |
| 15 | + branches: [main] |
| 16 | + pull_request: |
| 17 | + branches: [main] |
| 18 | + |
| 19 | + # Allows you to run this workflow manually from the Actions tab |
| 20 | + workflow_dispatch: |
| 21 | + |
| 22 | +env: |
| 23 | + # Path to the solution file relative to the root of the project |
| 24 | + SOLUTION_FILE_PATH: . |
| 25 | + |
| 26 | + # Configuration type to build |
| 27 | + BUILD_CONFIGURATION: Debug |
| 28 | + |
| 29 | + BUILD_OUTPUT: CompuMaster.Access/bin/Debug |
| 30 | + BUILD_OUTPUT_TEST: CompuMaster.Test.MsAccess/bin/Debug |
| 31 | + |
| 32 | +jobs: |
| 33 | + |
| 34 | + test: |
| 35 | + #needs: build |
| 36 | + runs-on: ${{ matrix.os }} |
| 37 | + |
| 38 | + strategy: |
| 39 | + fail-fast: false |
| 40 | + matrix: |
| 41 | + os: [windows-latest, ubuntu-latest, macos-latest] |
| 42 | + include: |
| 43 | + - os: macos-latest |
| 44 | + runNetExe: mono |
| 45 | + |
| 46 | + # the build-and-test job might be skipped, we don't need to run this job then |
| 47 | + #if: success() || failure() |
| 48 | + |
| 49 | + env: |
| 50 | + RESULTS_PATH: TestResults.xml |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Checkout |
| 54 | + uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Setup .NET Core |
| 57 | + uses: actions/setup-dotnet@v4 |
| 58 | + with: |
| 59 | + dotnet-version: 8.0.x |
| 60 | + |
| 61 | + - name: Dir Listing (Win) |
| 62 | + if: startsWith(matrix.os, 'windows') |
| 63 | + run: dir |
| 64 | + - name: Dir Listing (Linux/Mac) |
| 65 | + if: (!startsWith(matrix.os, 'windows')) |
| 66 | + run: ls -la |
| 67 | + |
| 68 | + - name: Install dependencies |
| 69 | + run: dotnet restore |
| 70 | + |
| 71 | + - name: Build |
| 72 | + run: dotnet build --configuration=${{env.BUILD_CONFIGURATION}} --no-restore |
| 73 | + |
| 74 | + - name: Run Unit Tests |
| 75 | + run: dotnet test --framework net8.0 --results-directory test-results --logger junit --configuration=${{env.BUILD_CONFIGURATION}} --no-restore |
| 76 | + |
| 77 | + - name: Dir Listing (Win) test-results |
| 78 | + if: startsWith(matrix.os, 'windows') |
| 79 | + run: dir test-results |
| 80 | + - name: Dir Listing (Linux/Mac) test-results |
| 81 | + if: (!startsWith(matrix.os, 'windows')) |
| 82 | + run: ls -la test-results |
| 83 | + |
| 84 | + #Following lines maybe required again after test&dev?! |
| 85 | + # # the action is useless on pull_request events |
| 86 | + # # (it can not create check runs or pull request comments) |
| 87 | + # if: always() #&& startsWith(matrix.os, 'ubuntu') #&& github.event_name != 'pull_request' |
| 88 | + |
| 89 | + - name: Unit Test Results (Linux) |
| 90 | + uses: EnricoMi/publish-unit-test-result-action@v2 |
| 91 | + if: always() && startsWith(matrix.os, 'ubuntu') |
| 92 | + with: |
| 93 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + files: "test-results/TestResults.xml" |
| 95 | + check_run_annotations: all tests |
| 96 | + comment_title: Unit Test Statistics (${{matrix.os}}) |
| 97 | + check_name: Unit Test Results (${{matrix.os}}) |
| 98 | + report_individual_runs: true |
| 99 | + |
| 100 | + - name: Unit Test Results (Win/Mac) |
| 101 | + uses: EnricoMi/publish-unit-test-result-action/composite@v2 |
| 102 | + if: always() && (!(startsWith(matrix.os, 'ubuntu'))) |
| 103 | + with: |
| 104 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + files: "test-results/TestResults.xml" |
| 106 | + check_run_annotations: all tests |
| 107 | + comment_title: Unit Test Statistics (${{matrix.os}}) |
| 108 | + check_name: Unit Test Results (${{matrix.os}}) |
| 109 | + report_individual_runs: true |
| 110 | + |
| 111 | + - name: Publish Unit Test Results |
| 112 | + uses: actions/upload-artifact@v4 |
| 113 | + if: always() |
| 114 | + with: |
| 115 | + name: NUnit Test Results ${{ matrix.os }} |
| 116 | + path: test-results/TestResults.xml |
| 117 | + |
0 commit comments