|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + path: |
| 7 | + description: The path to look for a Visual Studio Solution file (without a trailing slash). |
| 8 | + type: string |
| 9 | + required: false |
| 10 | + default: '' |
| 11 | + |
| 12 | +env: |
| 13 | + BUILD_CONFIG: Debug |
| 14 | + DOTNET_GLOBAL_JSON: ${{ inputs.path != '' && format('{0}/global.json', inputs.path) || 'global.json' }} |
| 15 | + RESTORE_PATTERN: ${{ inputs.path != '' && format('{0}/**/packages.lock.json', inputs.path) || '**/packages.lock.json' }} |
| 16 | + TESTS_PATTERN: ${{ inputs.path != '' && format('{0}/**/*.Test*.csproj', inputs.path) || '**/*.Test*.csproj' }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + lint: |
| 20 | + name: Lint |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + # Retrieve the preceding commit to enable 'changed-files' to create a diff. |
| 27 | + fetch-depth: 2 |
| 28 | + |
| 29 | + - name: .NET Setup |
| 30 | + uses: zyactions/dotnet-setup@v1 |
| 31 | + with: |
| 32 | + global-json-file: ${{ env.DOTNET_GLOBAL_JSON }} |
| 33 | + problem-matcher: false |
| 34 | + |
| 35 | + - name: Install latest .NET Format tool |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + dotnet tool install -g dotnet-format --version "8.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json |
| 39 | +
|
| 40 | + - name: Get Changed Files |
| 41 | + id: changed-files |
| 42 | + uses: tj-actions/changed-files@729c70475c2976c3d4ca8897d34d9df975a4d05c |
| 43 | + with: |
| 44 | + files: ${{ inputs.path != '' && format('{0}/**', inputs.path) || '' }} |
| 45 | + |
| 46 | + - name: .NET Cache Packages |
| 47 | + uses: actions/cache@v4 |
| 48 | + with: |
| 49 | + path: ~/.nuget/packages |
| 50 | + key: ${{ runner.os }}-nuget-${{ hashFiles(env.RESTORE_PATTERN) }} |
| 51 | + restore-keys: ${{ runner.os }}-nuget- |
| 52 | + |
| 53 | + - name: .NET Restore |
| 54 | + uses: zyactions/dotnet-restore@v1 |
| 55 | + with: |
| 56 | + working-directory: ${{ inputs.path }} |
| 57 | + |
| 58 | + # TODO: Add additional generic '.editorconfig' linting, e.g. for `*.csproj` files |
| 59 | + # TODO: Always lint all files, if '.editorconfig' has changed |
| 60 | + |
| 61 | + - name: .NET Lint |
| 62 | + uses: zyactions/dotnet-lint@v1 |
| 63 | + with: |
| 64 | + working-directory: ${{ inputs.path }} |
| 65 | + # This list is empty for the initial commit. NET Lint will lint all files in this case. |
| 66 | + include: ${{ steps.changed-files.outputs.all_changed_files }} |
| 67 | + use-standalone-tool: true |
| 68 | + |
| 69 | + test: |
| 70 | + name: Run Tests |
| 71 | + runs-on: ubuntu-latest |
| 72 | + env: |
| 73 | + FILTERED_SOLUTION: ${{ inputs.path != '' && format('{0}/Tests.slnf', inputs.path) || 'Tests.slnf' }} |
| 74 | + steps: |
| 75 | + - name: Checkout |
| 76 | + uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Find Solution |
| 79 | + id: find |
| 80 | + uses: flobernd/actions/dotnet/find-solution@master |
| 81 | + with: |
| 82 | + directory: ${{ inputs.path }} |
| 83 | + |
| 84 | + - name: Filter Solution |
| 85 | + uses: flobernd/actions/dotnet/filter-solution@master |
| 86 | + with: |
| 87 | + solution: ${{ steps.find.outputs.solution }} |
| 88 | + # This pattern is relative to the solution file and does not need to be prefixed with |
| 89 | + # the 'directory' input value |
| 90 | + pattern: '**/*.Test*.csproj' |
| 91 | + output: ${{ env.FILTERED_SOLUTION }} |
| 92 | + |
| 93 | + - name: .NET Setup |
| 94 | + uses: zyactions/dotnet-setup@v1 |
| 95 | + with: |
| 96 | + global-json-file: ${{ env.DOTNET_GLOBAL_JSON }} |
| 97 | + problem-matcher: false |
| 98 | + |
| 99 | + - name: .NET Cache Packages |
| 100 | + uses: actions/cache@v4 |
| 101 | + with: |
| 102 | + path: ~/.nuget/packages |
| 103 | + key: ${{ runner.os }}-nuget-${{ hashFiles(env.RESTORE_PATTERN) }} |
| 104 | + restore-keys: ${{ runner.os }}-nuget- |
| 105 | + |
| 106 | + - name: .NET Restore |
| 107 | + uses: zyactions/dotnet-restore@v1 |
| 108 | + with: |
| 109 | + workspace: ${{ env.FILTERED_SOLUTION }} |
| 110 | + |
| 111 | + - name: .NET Build |
| 112 | + uses: flobernd/actions/dotnet/build@master |
| 113 | + with: |
| 114 | + workspace: ${{ env.FILTERED_SOLUTION }} |
| 115 | + configuration: ${{ env.BUILD_CONFIG }} |
| 116 | + |
| 117 | + # - name: .NET Test |
| 118 | + # uses: flobernd/actions/dotnet/test@master |
| 119 | + # with: |
| 120 | + # projects: ${{ env.TESTS_PATTERN }} |
| 121 | + # fail-on-error: false |
| 122 | + # log-results: true |
| 123 | + # collect-coverage: false |
| 124 | + # maxdop: 4 |
| 125 | + |
| 126 | + # - name: Generate Test Report |
| 127 | + # uses: zyactions/test-reporter@main |
| 128 | + # with: |
| 129 | + # name: Test Results |
| 130 | + # path: ${{ inputs.path != '' && format('{0}/**/TestResults/*.trx', inputs.path) || '**/TestResults/*.trx' }} |
| 131 | + # reporter: dotnet-trx |
| 132 | + # fail-on-error: true |
| 133 | + # only-summary: false |
| 134 | + # max-annotations: 30 |
0 commit comments