Skip to content

Commit 385b011

Browse files
authored
feat: Incorporate GitHub Actions CI (#53)
* feat: Incorporate GitHub Actions CI
1 parent 06281ae commit 385b011

File tree

5 files changed

+77
-10
lines changed

5 files changed

+77
-10
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Container with dependencies necessary to run unit-tests and code coverage
2+
3+
# Build development environment
4+
# $ docker build . --tag note-arduino-test
5+
6+
# Launch development environment (mount source root as /note-arduino/)
7+
# $ docker run --rm --volume $(pwd)/../../../:/note-arduino/ --workdir /note-arduino/ note-arduino-test
8+
9+
# Base Image
10+
FROM alpine
11+
12+
# Testing Dependencies
13+
RUN ["ash", "-c", "\
14+
apk add --no-cache \
15+
gcovr \
16+
g++ \
17+
valgrind \
18+
"]
19+
20+
ENTRYPOINT ["./test/run_all_tests.sh"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: 'Containerized Test'
2+
author: 'Zachary J. Fields'
3+
description: 'Perform unit-test in containerized environment'
4+
runs:
5+
using: 'docker'
6+
image: 'Dockerfile'

.github/workflows/note-arduino-ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Note Arduino CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
validate_code: # job id
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Code
14+
id: checkout
15+
uses: actions/checkout@v2
16+
with:
17+
submodules: true
18+
- name: Run Tests In Container
19+
id: containerized_tests
20+
uses: ./.github/actions/run-tests-in-container

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,33 @@ For details on contributions we accept and the process for contributing, see our
123123

124124
## Note Arduino Tests
125125

126-
From the `test` directory, execute the `run_tests.sh` script.
127-
128126
### Dependencies
129127

130-
`bash` - the tests scripts are written in `bash` syntax
131-
`valgrind` - required to identify and protect against memory leaks.
128+
The tests are designed to be executed using Docker, and the environment required
129+
by the tests is defined in .github/actions/run-tests-in-container/Dockerfile.
130+
The following directions are provided to aid in executing the tests in
131+
a container.
132+
133+
> _**NOTE:** If you are uncomfortable using Docker, then you may wish to use
134+
the Dockerfile as a guide to install the necessary dependencies and execute
135+
`run_all_tests.sh` locally._
136+
137+
### Invocation
138+
139+
1. From the `note-arduino` folder, build the container with the
140+
following command:
141+
142+
```none
143+
docker build .github/actions/run-tests-in-container/ --tag note-arduino-test
144+
```
145+
146+
1. Execute the tests inside the container using the following command:
147+
148+
```none
149+
docker run --rm --volume $(pwd):/note-arduino/ --workdir /note-arduino/ note-arduino-test
150+
```
151+
152+
1. Similar test results should print to your terminal for review.
132153

133154
### Success
134155

test/run_tests.sh renamed to test/run_all_tests.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
all_tests_result=0
44

5-
g++ -Wall -Wextra -Wpedantic mock/mock-arduino.cpp mock/mock-note-c-note.c ../src/Notecard.cpp ../src/NoteI2c_Arduino.cpp ../src/NoteLog_Arduino.cpp ../src/NoteSerial_Arduino.cpp Notecard.test.cpp -std=c++11 -I. -I../src -DNOTE_MOCK
5+
g++ -Wall -Wextra -Wpedantic src/Notecard.cpp src/NoteI2c_Arduino.cpp src/NoteLog_Arduino.cpp src/NoteSerial_Arduino.cpp test/Notecard.test.cpp test/mock/mock-arduino.cpp test/mock/mock-note-c-note.c -std=c++11 -Isrc -Itest -DNOTE_MOCK
66
if [ 0 -eq $? ] && [ 0 -eq $all_tests_result ]; then
77
echo
88
valgrind --leak-check=full --error-exitcode=66 ./a.out
@@ -17,7 +17,7 @@ else
1717
all_tests_result=999
1818
fi
1919

20-
g++ -Wall -Wextra -Wpedantic mock/mock-arduino.cpp mock/mock-note-c-note.c ../src/NoteI2c_Arduino.cpp NoteI2c_Arduino.test.cpp -std=c++11 -I. -I../src -DNOTE_MOCK
20+
g++ -Wall -Wextra -Wpedantic src/NoteI2c_Arduino.cpp test/NoteI2c_Arduino.test.cpp test/mock/mock-arduino.cpp test/mock/mock-note-c-note.c -std=c++11 -Isrc -Itest -DNOTE_MOCK
2121
if [ 0 -eq $? ] && [ 0 -eq $all_tests_result ]; then
2222
echo
2323
valgrind --leak-check=full --error-exitcode=66 ./a.out
@@ -32,7 +32,7 @@ else
3232
all_tests_result=999
3333
fi
3434

35-
g++ -Wall -Wextra -Wpedantic mock/mock-arduino.cpp mock/mock-note-c-note.c ../src/NoteI2c_Arduino.cpp NoteI2c_Arduino.test.cpp -std=c++11 -I. -I../src -DNOTE_MOCK -DWIRE_HAS_END
35+
g++ -Wall -Wextra -Wpedantic src/NoteI2c_Arduino.cpp test/NoteI2c_Arduino.test.cpp test/mock/mock-arduino.cpp test/mock/mock-note-c-note.c -std=c++11 -Isrc -Itest -DNOTE_MOCK -DWIRE_HAS_END
3636
if [ 0 -eq $? ] && [ 0 -eq $all_tests_result ]; then
3737
echo
3838
valgrind --leak-check=full --error-exitcode=66 ./a.out
@@ -47,7 +47,7 @@ else
4747
all_tests_result=999
4848
fi
4949

50-
g++ -Wall -Wextra -Wpedantic mock/mock-arduino.cpp ../src/NoteLog_Arduino.cpp NoteLog_Arduino.test.cpp -std=c++11 -I. -I../src -DNOTE_MOCK
50+
g++ -Wall -Wextra -Wpedantic src/NoteLog_Arduino.cpp test/NoteLog_Arduino.test.cpp test/mock/mock-arduino.cpp -std=c++11 -Isrc -Itest -DNOTE_MOCK
5151
if [ 0 -eq $? ] && [ 0 -eq $all_tests_result ]; then
5252
echo
5353
valgrind --leak-check=full --error-exitcode=66 ./a.out
@@ -62,7 +62,7 @@ else
6262
all_tests_result=999
6363
fi
6464

65-
g++ -Wall -Wextra -Wpedantic mock/mock-arduino.cpp ../src/NoteSerial_Arduino.cpp NoteSerial_Arduino.test.cpp -std=c++11 -I. -I../src -DNOTE_MOCK
65+
g++ -Wall -Wextra -Wpedantic src/NoteSerial_Arduino.cpp test/NoteSerial_Arduino.test.cpp test/mock/mock-arduino.cpp -std=c++11 -Isrc -Itest -DNOTE_MOCK
6666
if [ 0 -eq $? ] && [ 0 -eq $all_tests_result ]; then
6767
echo
6868
valgrind --leak-check=full --error-exitcode=66 ./a.out

0 commit comments

Comments
 (0)