Bỏ qua để đến nội dung

Tích hợp liên tục

CI của chính db-test chạy bộ kiểm thử tích hợp trên cả ba engine. Đây là job đó, đúng như trong repository. Hãy điều chỉnh cho project của bạn.

.github/workflows/ci.yml
integration:
runs-on: ubuntu-latest
# The integration suite starts a container per engine. Running the three engines as
# separate jobs keeps one engine's failure from hiding the others' results.
strategy:
fail-fast: false
matrix:
engine: [MsSql, PostgreSql, MySql]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
with:
dotnet-version: |
8.0.x
10.0.x
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
# One leg per supported runtime, in one job so the database image is pulled once.
# DBTEST_TIMING turns on the per-test timing file, which is uploaded below.
- name: Integration tests (net8.0)
env:
DBTEST_TIMING: "1"
run: >-
dotnet test tests/DbTest.Integration.Tests
--configuration Release
--no-build
--framework net8.0
--filter "FullyQualifiedName~${{ matrix.engine }}HarnessTests"
- name: Integration tests (net10.0)
env:
DBTEST_TIMING: "1"
run: >-
dotnet test tests/DbTest.Integration.Tests
--configuration Release
--no-build
--framework net10.0
--filter "FullyQualifiedName~${{ matrix.engine }}HarnessTests"
- name: Upload timings
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: timings-${{ matrix.engine }}
path: tests/DbTest.Integration.Tests/bin/Release/*/dbtest-timing.tsv
if-no-files-found: ignore

Mỗi engine một job. Bộ test khởi động một container cho mỗi engine. Chạy các engine thành các nhánh matrix riêng, với fail-fast: false, giúp lỗi của một engine không che mất kết quả của các engine khác.

Docker lấy từ runner. Job không có bước cài Docker: nó dựa vào Docker daemon có sẵn trên runner ubuntu-latest, và Testcontainers giao tiếp với daemon đó.

Chọn nhánh theo tên class. Giá trị matrix là một phần của tên test class, và --filter "FullyQualifiedName~${{ matrix.engine }}HarnessTests" chỉ chạy các class của engine đó: MsSqlHarnessTests, PostgreSqlHarnessTests hoặc MySqlHarnessTests. Hãy đặt tên các class theo từng engine của bạn theo mẫu tương tự để lọc theo cách đó.

Mỗi runtime một bước. Các package có asset net8.0 và net10.0. Job test cả hai bằng --framework, trong cùng một job để image database chỉ được pull một lần, và cài cả hai runtime bằng actions/setup-dotnet.

Thời gian chạy làm artifact. DBTEST_TIMING: "1" bật file thời gian chạy từng test. Bước cuối upload file đó cho từng engine, với if: always() để lần chạy bị fail vẫn báo cáo thời gian.