|
| 1 | +name: Pipeline PR push |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + discover-tests: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + outputs: |
| 10 | + testProjects: ${{ steps.set-matrix.outputs.testProjects }} |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Find Test Projects |
| 16 | + id: set-matrix |
| 17 | + run: | |
| 18 | + projects=$(find tests -name '*Tests.csproj' | jq -R -s -c 'split("\n") | map(select(length > 0))') |
| 19 | + echo "Found test projects: $projects" |
| 20 | + echo "testProjects=$projects" >> $GITHUB_OUTPUT |
| 21 | + build-and-test: |
| 22 | + needs: discover-tests |
| 23 | + runs-on: ${{ matrix.os }} |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 27 | + testProject: ${{ fromJson(needs.discover-tests.outputs.testProjects) }} |
| 28 | + name: build-and-test (${{ matrix.os }} | ${{ matrix.testProject }}) |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Cache NuGet packages |
| 36 | + uses: actions/cache@v4 |
| 37 | + with: |
| 38 | + path: ${{ matrix.os == 'windows-latest' && env.USERPROFILE || '~' }}/.nuget/packages |
| 39 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-nuget- |
| 42 | + - name: Setup .NET 8 Environment |
| 43 | + uses: actions/setup-dotnet@v4 |
| 44 | + with: |
| 45 | + dotnet-version: '8.0.x' |
| 46 | + |
| 47 | + - name: Create Config Files |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + echo '${{ secrets.CLIENT_LOCAL_SETTINGS_JSON }}' > src/ByteSync.Client/local.settings.json |
| 51 | + echo '${{ secrets.FUNCTIONS_INTEGRATION_TESTS_LOCAL_SETTINGS_JSON }}' > tests/ByteSync.Functions.IntegrationTests/functions-integration-tests.local.settings.json |
| 52 | + echo '${{ secrets.SERVER_COMMON_TESTS_LOCAL_SETTINGS }}' > tests/ByteSync.ServerCommon.Tests/server-common-tests.local.settings.json |
| 53 | + - run: dotnet restore --locked-mode |
| 54 | + - run: dotnet clean --verbosity quiet |
| 55 | + - run: dotnet build --verbosity quiet /property:WarningLevel=0 |
| 56 | + |
| 57 | + - name: Run Test Project |
| 58 | + run: | |
| 59 | + mkdir -p TestResults |
| 60 | + project="${{ matrix.testProject }}" |
| 61 | + safe_name=$(basename "$project" .csproj) |
| 62 | + echo "Running test project: $project" |
| 63 | + dotnet test "$project" --no-restore --no-build --logger "trx;LogFileName=$safe_name.trx" --results-directory ./TestResults |
| 64 | + shell: bash |
| 65 | + |
| 66 | + - name: Upload Test Results |
| 67 | + uses: actions/upload-artifact@v4 |
| 68 | + with: |
| 69 | + name: PR-test-results-${{ matrix.os }}-${{ hashFiles(matrix.testProject) }} |
| 70 | + path: ./TestResults/ |
| 71 | + |
| 72 | + - name: Show Failed Tests |
| 73 | + if: failure() |
| 74 | + run: echo "Some tests failed. Check uploaded artifacts for detailed logs." |
0 commit comments