Skip to content

Commit

Permalink
chore: add build_and_test.yml (#3)
Browse files Browse the repository at this point in the history
Fixes #1.

Needs #2.

Any remarks and suggestions are welcome! The workflow can be triggered
manually and will be triggered on every push to main.
  • Loading branch information
vil02 authored Oct 18, 2024
1 parent 1c8f934 commit 2ec0049
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: ubuntu_build

'on':
pull_request:
push:
branches:
- main
workflow_dispatch:

env:
build_path: ${{github.workspace}}/build

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create Build Environment
run: cmake -E make_directory ${{env.build_path}}

- name: Configure CMake
working-directory: ${{env.build_path}}
run: cmake ../

- name: Build
working-directory: ${{env.build_path}}
run: cmake --build .

- name: Test
working-directory: ${{env.build_path}}
run: ctest
...
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,82 @@
# hello-ctest

## Running build and test locally

In order to build and test this project locally, you need to follow 4 steps:

1. **Create the _Build environment_**

Create a directory for all of the _generated_ files (e.g. make files, object files, executables etc.) will be located.
This can be done by running the command like:
```shell
cmake -E make_directory my_build_directory
```
or something system specific like:
```shell
mkdir -p my_build_directory
```

2. **Configure CMake**

This step _generates_ all of the files needed for the build.
Navigate to `my_build_directory` and run:
```shell
cmake ../
```
Expected output:
```
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CTEST_RESOURCE_SPEC_FILE = some_path/hello-ctest/test-resource-spec.json
-- CMAKE_INSTALL_PREFIX = some_path/hello-ctest/my_build_directory/install/hello-ctest -- Use the cmake --install-prefix arg to override.
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: some_path/hello-ctest/my_build_directory
```

3. **Build the project**

Navigate to `my_build_directory` and run:
```shell
cmake --build .
```
The output should look like:
```
[ 50%] Building CXX object src/CMakeFiles/hello-ctest.dir/main.cpp.o
[100%] Linking CXX executable hello-ctest
[100%] Built target hello-ctest
```

4. **Execute the tests using `ctest`**

Tests in this project are expresed using [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html).
To execute all of them navigate to `my_build_directory` and run:
```
ctest
```
The output should look like:
```
Test project some_path/hello-ctest/my_build_directory
Start 1: run_hello-ctest
1/6 Test #1: run_hello-ctest .................. Passed 0.00 sec
Start 2: Hello_One
2/6 Test #2: Hello_One ........................ Passed 0.00 sec
Start 3: Hello_Two
3/6 Test #3: Hello_Two ........................ Passed 0.00 sec
Start 4: Hello_Three
4/6 Test #4: Hello_Three ...................... Passed 0.00 sec
Start 5: Hello_Four
5/6 Test #5: Hello_Four ....................... Passed 0.00 sec
Start 6: Hello_Five
6/6 Test #6: Hello_Five ....................... Passed 0.00 sec

100% tests passed, 0 tests failed out of 6

Total Test time (real) = 0.02 sec
```

These steps are reflected in [`build_and_test.yml`](.github/workflows/build_and_test.yml) workflow.

0 comments on commit 2ec0049

Please sign in to comment.