From 1c8773a352294a1e9aa9a2b771cec03813c9a609 Mon Sep 17 00:00:00 2001 From: sitaowang1998 Date: Fri, 6 Dec 2024 14:52:22 -0500 Subject: [PATCH] ci: Add tasks to run unit tests and GitHub workflow to run non-storage unit tests. (#30) Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> --- .github/workflows/code-linting-checks.yaml | 10 +---- .github/workflows/unit-tests.yaml | 45 ++++++++++++++++++++++ README.md | 2 +- build-tasks.yaml | 21 ++++++++++ docs/testing.md | 28 ++++++++------ lint-tasks.yaml | 6 ++- taskfile.yaml | 4 +- test-tasks.yaml | 30 +++++++++++++++ 8 files changed, 122 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/unit-tests.yaml create mode 100644 build-tasks.yaml create mode 100644 test-tasks.yaml diff --git a/.github/workflows/code-linting-checks.yaml b/.github/workflows/code-linting-checks.yaml index d4bb15e..e02e147 100644 --- a/.github/workflows/code-linting-checks.yaml +++ b/.github/workflows/code-linting-checks.yaml @@ -18,10 +18,7 @@ concurrency: jobs: lint: - strategy: - matrix: - os: ["ubuntu-latest"] - runs-on: "${{matrix.os}}" + runs-on: "ubuntu-latest" steps: - uses: "actions/checkout@v4" with: @@ -34,10 +31,6 @@ jobs: - name: "Install task" run: "npm install -g @go-task/cli" - - if: "matrix.os == 'macos-latest'" - name: "Install coreutils (for md5sum)" - run: "brew install coreutils" - - name: "Log tool versions" run: |- md5sum --version @@ -47,7 +40,6 @@ jobs: - name: "Install project dependencies " timeout-minutes: 10 - continue-on-error: false run: "task deps:lib_install" - run: "task lint:check" diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml new file mode 100644 index 0000000..98702da --- /dev/null +++ b/.github/workflows/unit-tests.yaml @@ -0,0 +1,45 @@ +name: "unit-tests" + +on: + pull_request: + push: + schedule: + # Run daily at 00:15 UTC (the 15 is to avoid periods of high load) + - cron: "15 0 * * *" + workflow_dispatch: + +permissions: {} + +concurrency: + group: "${{github.workflow}}-${{github.ref}}" + + # Cancel in-progress jobs for efficiency + cancel-in-progress: true + +jobs: + non-storage-unit-tests: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v4" + with: + submodules: "recursive" + + - uses: "actions/setup-python@v5" + with: + python-version: "3.10" + + - name: "Install task" + run: "npm install -g @go-task/cli" + + - name: "Log tool versions" + run: |- + md5sum --version + python --version + tar --version + task --version + + - name: "Install project dependencies " + timeout-minutes: 10 + run: "task deps:lib_install" + + - run: "task test:non-storage-unit-tests" diff --git a/README.md b/README.md index 89c7724..b4434f3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Follow the steps below to develop and contribute to the project. ## Requirements * Python 3.10 or higher -* [Task] 3.38.0 or higher +* [Task] 3.40.0 or higher ## Set up Initialize and update submodules: diff --git a/build-tasks.yaml b/build-tasks.yaml new file mode 100644 index 0000000..666576f --- /dev/null +++ b/build-tasks.yaml @@ -0,0 +1,21 @@ +version: "3" + +tasks: + target: + internal: true + vars: + TARGETS: + ref: "default (list \"all\") .TARGETS" + deps: [":config-cmake-project"] + cmds: + - >- + cmake + --build "{{.G_BUILD_SPIDER_DIR}}" + --parallel {{numCPU}} + --target {{range .TARGETS}}{{.}} {{end}} + + clean: + internal: true + deps: [":config-cmake-project"] + cmds: + - "cmake --build {{.G_BUILD_SPIDER_DIR}} --target clean --parallel {{numCPU}}" diff --git a/docs/testing.md b/docs/testing.md index f574dee..46a63d3 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -23,20 +23,26 @@ require this storage backend. 4. Set the `cStorageUrl` in `tests/storage/StorageTestHelper.hpp` to `jdbc:mariadb://localhost:3306/?user=&password=`. -## Build and run unit tests +## Running tests -To build and run the unit tests, run the following commands in project root directory. +You can use the following tasks to run the set of unit tests that's appropriate. -```shell -cmake -S . -B build -cmake --build build --target unitTest --parallel -./build/tests/unitTest -``` +| Task | Description | +|-------------------------------|-------------------------------------------------------------------| +| `test:all` | Runs all unit tests. | +| `test:non-storage-unit-tests` | Runs all unit tests which don't require a storage backend to run. | +| `test:storage-unit-tests` | Runs all unit tests which require a storage backend to run. | -If the tests show error messages for connection functions below, -revisit [Setup storage backend](#setup-storage-backend) section and double check if `cStorageUrl` is -set correctly. +If any tests show error messages for the connection function below, revisit the +[setup section](#set-up-mysql-as-storage-backend) and verify that `cStorageUrl` was set correctly. ```c++ REQUIRE( storage->connect(spider::test::cStorageUrl).success() ) -``` \ No newline at end of file +``` + +## GitHub unit test workflow + +The [unit_tests.yaml][gh-workflow-unit-tests] GitHub workflow runs the unit tests on push, +pull requests, and daily. Currently, it only runs unit tests that don't require a storage backend. + +[gh-workflow-unit-tests]: ../.github/workflows/unit-tests.yaml diff --git a/lint-tasks.yaml b/lint-tasks.yaml index 554f1f8..13db6cc 100644 --- a/lint-tasks.yaml +++ b/lint-tasks.yaml @@ -115,9 +115,11 @@ tasks: --strict \ .gersemirc \ .github/ \ - lint-tasks.yaml \ + build-tasks.yaml \ dep-tasks.yaml \ - taskfile.yaml + lint-tasks.yaml \ + taskfile.yaml \ + test-tasks.yaml clang-format: internal: true diff --git a/taskfile.yaml b/taskfile.yaml index 14e33cb..19e722d 100644 --- a/taskfile.yaml +++ b/taskfile.yaml @@ -1,8 +1,10 @@ version: "3" includes: - lint: "lint-tasks.yaml" deps: "dep-tasks.yaml" + build: "build-tasks.yaml" + lint: "lint-tasks.yaml" + test: "test-tasks.yaml" utils: "tools/yscope-dev-utils/taskfiles/utils.yml" vars: diff --git a/test-tasks.yaml b/test-tasks.yaml new file mode 100644 index 0000000..a38fb12 --- /dev/null +++ b/test-tasks.yaml @@ -0,0 +1,30 @@ +version: "3" + +vars: + G_TEST_BINARY: "{{.G_BUILD_SPIDER_DIR}}/tests/unitTest" + +tasks: + non-storage-unit-tests: + deps: + - "build-unit-test" + cmds: + - "{{.G_TEST_BINARY}} \"~[storage]\"" + + storage-unit-tests: + deps: + - "build-unit-test" + cmds: + - "{{.G_TEST_BINARY}} \"[storage]\"" + + all: + deps: + - "build-unit-test" + cmds: + - "{{.G_TEST_BINARY}}" + + build-unit-test: + internal: true + deps: + - task: ":build:target" + vars: + TARGETS: ["spider_task_executor", "unitTest", "worker_test"]