Skip to content

Commit 3d697a1

Browse files
authored
ci: enable test assets and cache them (#64)
* ci: pass --build-config to ctest It's required when using multi-config generators like MSVC on Windows * Do not download git-lfs files by default The test file is really big, and downloading it by default may create issues with users on a slow network. Use a .lfsconfig file to disable LFS downloads. This way, LFS files can be explicitly downloaded via git lfs pull --exclude='' --include='*' * build: use Git LFS test data * ci: enable test assets and cache them * ci: limit runs to the master branch This avoids duplicated runs on merge requests
1 parent dda8ec0 commit 3d697a1

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

.github/workflows/build.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ name: build
55

66
on:
77
push:
8+
branches:
9+
- master
810
pull_request:
11+
branches:
12+
- master
913
workflow_dispatch:
1014

1115
permissions:
@@ -22,12 +26,26 @@ jobs:
2226
steps:
2327
- uses: actions/checkout@v4
2428

29+
- name: Cache test assets
30+
uses: actions/cache@v4
31+
with:
32+
path: build/teaklite2_tests_result.bin
33+
enableCrossOsArchive: true
34+
key: 'baffcd4f805a7480d969401792443a34aa39f813b4f0ae49c6365f1d1f3ce120'
35+
36+
- name: Download test assets
37+
if: "!hashFiles('build/teaklite2_tests_result.bin')"
38+
run: |
39+
git lfs pull --exclude='' --include='*'
40+
mkdir -p build
41+
mv src/test_verifier/data/teaklite2_tests_result.bin build/teaklite2_tests_result.bin
42+
2543
- name: Configure
26-
run: cmake -B build
44+
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug -DTEAKRA_RUN_TESTS=ON -DTEAKRA_TEST_ASSETS_DIR="$PWD/build"
2745

2846
- name: Build
29-
run: cmake --build build --parallel
47+
run: cmake --build build --config Debug --parallel
3048

3149
- name: Test
3250
working-directory: build
33-
run: ctest --verbose
51+
run: ctest --build-config Debug --verbose

.lfsconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[lfs]
2+
fetchexclude = *

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
8282
find_package(Threads REQUIRED)
8383

8484
if (NOT TEAKRA_TEST_ASSETS_DIR)
85-
set(TEAKRA_TEST_ASSETS_DIR "${CMAKE_CURRENT_BINARY_DIR}")
85+
set(TEAKRA_TEST_ASSETS_DIR "${PROJECT_SOURCE_DIR}/src/test_verifier/data")
8686
endif()
8787

8888
# External libraries

src/test_verifier/CMakeLists.txt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,13 @@ target_compile_options(test_verifier PRIVATE ${TEAKRA_CXX_FLAGS})
1414
set(ASSET_SHA256SUM "baffcd4f805a7480d969401792443a34aa39f813b4f0ae49c6365f1d1f3ce120")
1515
if(TEAKRA_RUN_TESTS)
1616
message(STATUS "Will run Teakra accuracy tests")
17-
# download fixtures if there is none
18-
if(NOT EXISTS "${TEAKRA_TEST_ASSETS_DIR}/teaklite2_tests_result")
19-
message(STATUS "Downloading required samples...")
20-
file(DOWNLOAD
21-
"https://liushuyu.b-cdn.net/teaklite2_tests_result_20181208"
22-
"${TEAKRA_TEST_ASSETS_DIR}/teaklite2_tests_result"
23-
EXPECTED_HASH SHA256=${ASSET_SHA256SUM}
24-
SHOW_PROGRESS
25-
)
17+
# check if provided fixtures are good
18+
file(SHA256 "${TEAKRA_TEST_ASSETS_DIR}/teaklite2_tests_result.bin" ASSET_CHECKSUM)
19+
if(ASSET_SHA256SUM STREQUAL ASSET_CHECKSUM)
20+
message(STATUS "Unit test sample looks good.")
2621
else()
27-
# check if provided fixtures are good
28-
file(SHA256 "${TEAKRA_TEST_ASSETS_DIR}/teaklite2_tests_result" ASSET_CHECKSUM)
29-
if(ASSET_SHA256SUM STREQUAL ASSET_CHECKSUM)
30-
message(STATUS "Unit test sample looks good.")
31-
else()
32-
message(FATAL_ERROR "Unit test sample broken. Please remove the file and re-run CMake.")
33-
endif()
22+
message(FATAL_ERROR "Unit test sample broken. Please download the file using: git lfs pull --exclude='' --include='*'")
3423
endif()
3524

36-
add_test(NAME tests COMMAND test_verifier "${TEAKRA_TEST_ASSETS_DIR}/teaklite2_tests_result")
25+
add_test(NAME tests COMMAND test_verifier "${TEAKRA_TEST_ASSETS_DIR}/teaklite2_tests_result.bin")
3726
endif(TEAKRA_RUN_TESTS)

0 commit comments

Comments
 (0)