Skip to content

Commit 55c21dd

Browse files
authored
Make changes to CI so Docker image is reused. (#110)
1 parent 3fc70ec commit 55c21dd

File tree

9 files changed

+174
-84
lines changed

9 files changed

+174
-84
lines changed

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
1010
//"dockerFile": "../.github/actions/compile-examples/Dockerfile",
11-
"dockerFile": "../.github/actions/run-tests-in-container/Dockerfile",
11+
"dockerFile": "../Dockerfile",
1212

1313
// Set *default* container specific settings.json values on container create.
1414
"settings": {},

.github/actions/compile-examples/action.yml

-17
This file was deleted.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Load note-arduino CI Docker image'
2+
runs:
3+
using: 'composite'
4+
steps:
5+
- name: Set up Docker Buildx
6+
uses: docker/setup-buildx-action@v2
7+
8+
- name: Download image artifact
9+
uses: actions/download-artifact@v2
10+
with:
11+
name: note_arduino_ci_image
12+
path: /tmp
13+
14+
- name: Load Docker image
15+
shell: bash
16+
run: |
17+
docker load --input /tmp/note_arduino_ci_image.tar

.github/actions/run-tests-in-container/Dockerfile

-27
This file was deleted.

.github/actions/run-tests-in-container/action.yml

-6
This file was deleted.

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

+121-20
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,92 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
validate_library: # job id
10+
check_dockerfile_changed:
1111
runs-on: ubuntu-latest
12+
outputs:
13+
changed: ${{ steps.filter.outputs.changed }}
14+
1215
steps:
13-
- name: Checkout Code
14-
id: checkout
16+
- name: Checkout code
1517
uses: actions/checkout@v3
16-
- name: Run Tests In Container
17-
id: containerized_tests
18-
uses: ./.github/actions/run-tests-in-container
19-
- name: Coveralls Action Bug Workaround
20-
id: coveralls_bug_workaround
21-
run: sudo sed -i 's/github\/workspace/home\/runner\/work\/note-arduino\/note-arduino/g' ./coverage/lcov.info
22-
- name: Publish Test Coverage
23-
id: publish_coverage
18+
19+
# TODO: This is a 3rd party GitHub action from some dude. Ideally, we'd
20+
# use something more "official".
21+
- name: Check if Dockerfile changed
22+
uses: dorny/paths-filter@v2
23+
id: filter
24+
with:
25+
base: 'master'
26+
filters: |
27+
changed:
28+
- 'Dockerfile'
29+
build_ci_docker_image:
30+
runs-on: ubuntu-latest
31+
needs: [check_dockerfile_changed]
32+
if: ${{ needs.check_dockerfile_changed.outputs.changed == 'true' }}
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v3
37+
38+
- name: Login to GitHub Container Registry
39+
uses: docker/login-action@v2
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v2
47+
48+
- name: Rebuild image
49+
uses: docker/build-push-action@v4
50+
with:
51+
context: .
52+
load: true
53+
tags: ghcr.io/blues/note_arduino_ci:latest
54+
outputs: type=docker,dest=/tmp/note_arduino_ci_image.tar
55+
56+
- name: Upload image artifact
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: note_arduino_ci_image
60+
path: /tmp/note_arduino_ci_image.tar
61+
62+
run_tests:
63+
runs-on: ubuntu-latest
64+
if: ${{ always() }}
65+
needs: [build_ci_docker_image]
66+
67+
steps:
68+
- name: Checkout code
69+
uses: actions/checkout@v3
70+
71+
- name: Load CI Docker image
72+
if: ${{ needs.build_ci_docker_image.result == 'success' }}
73+
uses: ./.github/actions/load-ci-image
74+
75+
- name: Run tests
76+
run: |
77+
docker run --rm --volume $(pwd):/note-arduino/ \
78+
--workdir /note-arduino/ \
79+
--entrypoint ./test/run_all_tests.sh \
80+
--user root \
81+
ghcr.io/blues/note_arduino_ci:latest
82+
83+
- name: Adjust lcov source file paths for Coveralls
84+
run: sudo sed -i 's/\/note-arduino\///g' ./coverage/lcov.info
85+
86+
- name: Publish test coverage
2487
uses: coverallsapp/github-action@master
2588
with:
2689
github-token: ${{ secrets.GITHUB_TOKEN }}
27-
validate_examples: # job id
90+
path-to-lcov: ./coverage/lcov.info
91+
92+
build_examples:
2893
runs-on: ubuntu-latest
94+
if: ${{ always() }}
95+
needs: [build_ci_docker_image]
2996
continue-on-error: true
3097
strategy:
3198
matrix:
@@ -38,26 +105,60 @@ jobs:
38105
- ./examples/Example5_UsingTemplates/Example5_UsingTemplates.ino
39106
- ./examples/Example6_SensorTutorial/Example6_SensorTutorial.ino
40107
- ./examples/Example7_PowerControl/Example7_PowerControl.ino
41-
- ./examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino
42-
- ./examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino
108+
# TODO: Uncomment these once note-c is updated with the necessary NoteBinary* functions.
109+
# - ./examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino
110+
# - ./examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino
43111
fully-qualified-board-name:
44112
- STMicroelectronics:stm32:BluesW:pnum=SWAN_R5
45113
- esp32:esp32:featheresp32
46114
- adafruit:samd:adafruit_feather_m4
47115
- STMicroelectronics:stm32:GenF4:pnum=FEATHER_F405
48-
- arduino:mbed_nano:nano33ble
116+
# TODO: Fix this. May require upstream fix.
117+
# - arduino:mbed_nano:nano33ble
49118
- SparkFun:apollo3:sfe_artemis_thing_plus
50119
- STMicroelectronics:stm32:Nucleo_32:pnum=NUCLEO_L432KC
51120
- adafruit:nrf52:feather52840:softdevice=s140v6
52121
- rp2040:rp2040:rpipico
53122
- arduino:avr:uno
123+
54124
steps:
55-
- name: Checkout Code
125+
- name: Checkout code
56126
id: checkout
57127
uses: actions/checkout@v3
128+
129+
- name: Load CI docker image
130+
if: ${{ needs.build_ci_docker_image.result == 'success' }}
131+
uses: ./.github/actions/load-ci-image
132+
58133
- name: Compile Examples
59-
id: compile_examples
60-
uses: ./.github/actions/compile-examples
134+
run: |
135+
docker run --rm --volume $(pwd):/note-arduino/ \
136+
--workdir /note-arduino/ \
137+
--entrypoint ./examples/build_example.sh \
138+
ghcr.io/blues/note_arduino_ci:latest \
139+
${{ matrix.fully-qualified-board-name }} \
140+
${{ matrix.example-sketch }}
141+
142+
publish_ci_image:
143+
runs-on: ubuntu-latest
144+
# Make sure tests passed and examples built successfully before publishing.
145+
needs: [build_ci_docker_image, run_tests, build_examples]
146+
# Only publish the image if this is a push event and the Docker image was rebuilt.
147+
if: ${{ github.event_name == 'push' && needs.build_ci_docker_image.result == 'success' }}
148+
149+
steps:
150+
- name: Login to GitHub Container Registry
151+
uses: docker/login-action@v2
152+
with:
153+
registry: ghcr.io
154+
username: ${{ github.actor }}
155+
password: ${{ secrets.GITHUB_TOKEN }}
156+
157+
- name: Set up Docker Buildx
158+
uses: docker/setup-buildx-action@v2
159+
160+
- name: Push image to registry
161+
uses: docker/build-push-action@v4
61162
with:
62-
example-sketch: ${{ matrix.example-sketch }}
63-
fully-qualified-board-name: ${{ matrix.fully-qualified-board-name }}
163+
push: true
164+
tags: ghcr.io/blues/note_arduino_ci:latest

.github/actions/compile-examples/Dockerfile renamed to Dockerfile

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Blues Inc. All rights reserved.
1+
# Copyright 2023 Blues Inc. All rights reserved.
22
# Use of this source code is governed by licenses granted by the
33
# copyright holder including that found in the LICENSE file.
44

@@ -15,7 +15,7 @@ ARG UID=1000
1515
ARG USER="blues"
1616

1717
# POSIX compatible (Linux/Unix) base image
18-
FROM debian:bullseye-slim
18+
FROM debian:bookworm-slim
1919

2020
# Import global arguments
2121
ARG ARDUINO_CLI_VERSION
@@ -55,14 +55,20 @@ RUN ["dash", "-c", "\
5555
bash-completion \
5656
ca-certificates \
5757
curl \
58+
g++ \
59+
gdb \
60+
gzip \
61+
lcov \
5862
python-is-python3 \
5963
python3 \
6064
python3-pip \
6165
ssh \
6266
tree \
67+
valgrind \
6368
&& pip install \
6469
adafruit-nrfutil \
6570
pyserial \
71+
--break-system-packages \
6672
&& apt-get clean \
6773
&& apt-get purge \
6874
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
@@ -104,11 +110,3 @@ RUN ["dash", "-c", "\
104110
&& arduino-cli core install STMicroelectronics:stm32 \
105111
&& arduino-cli lib install \"Blues Wireless Notecard Pseudo Sensor\" \
106112
"]
107-
108-
# Set Execution Environment
109-
USER root
110-
WORKDIR /host-volume
111-
112-
ENTRYPOINT ["arduino-cli"]
113-
114-
CMD ["help"]

examples/build_example.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
4+
NOTE_ARDUINO_DIR="$SCRIPT_DIR/.."
5+
6+
# If this is being run inside a Docker container (i.e. for GitHub actions CI),
7+
# copy the latest note-arduino code into the appropriate place so that it can
8+
# be consumed when building the example.
9+
if grep -sq 'docker\|lxc' /proc/1/cgroup; then
10+
cp -r $NOTE_ARDUINO_DIR $HOME/Arduino/libraries/Blues_Wireless_Notecard
11+
fi
12+
13+
arduino-cli compile \
14+
--build-property compiler.cpp.extra_flags='-Wno-unused-parameter -Werror' \
15+
--fqbn $1 \
16+
--log-level trace \
17+
--verbose \
18+
--warnings all \
19+
$2

test/run_all_tests.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ DEFAULT='\x1B[0;0m'
77

88
all_tests_result=0
99

10+
# This fixes a problem when running valgrind in a Docker container when the
11+
# host machine is running Fedora. See https://stackoverflow.com/a/75293014.
12+
ulimit -n 1024
13+
1014
if [ 0 -eq $all_tests_result ]; then
1115
echo && echo -e "${YELLOW}Compiling and running Notecard Test Suite...${DEFAULT}"
1216
g++ -fprofile-arcs -ftest-coverage -Wall -Wextra -Werror -Wpedantic -std=c++11 -O0 -g \
@@ -164,20 +168,21 @@ if [ 0 -eq ${all_tests_result} ]; then
164168

165169
# Run coverage if available
166170
if [ $(which lcov) ]; then
167-
rm mock-*.gc?? *_Mock.gc?? *test.gc?? \
168-
&& gcov --version \
171+
rm -f mock-*.gc?? *_Mock.gc?? *test.gc??
172+
gcov --version \
169173
&& lcov --version \
170174
&& mkdir -p ./coverage \
171175
&& lcov --capture \
172176
--directory . \
177+
--no-external \
173178
--exclude '/note-arduino/test/*' \
174179
--output-file ./coverage/lcov.info \
175180
--rc lcov_branch_coverage=1
176181
if [ ! -f "./coverage/lcov.info" ]; then
177182
echo -e "${YELLOW}COVERAGE REPORT NOT PRODUCED!!!${DEFAULT}";
178183
all_tests_result=998
179184
else
180-
lcov --summary ./coverage/lcov.info
185+
lcov --summary --rc lcov_branch_coverage=1 ./coverage/lcov.info
181186
fi
182187
fi
183188
rm -f failed_test_run

0 commit comments

Comments
 (0)