Skip to content

Commit

Permalink
Make changes to CI so Docker image is reused. (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenroche5 authored Sep 28, 2023
1 parent 3fc70ec commit 55c21dd
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

// Set *default* container specific settings.json values on container create.
"settings": {},
Expand Down
17 changes: 0 additions & 17 deletions .github/actions/compile-examples/action.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/actions/load-ci-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Load note-arduino CI Docker image'
runs:
using: 'composite'
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Download image artifact
uses: actions/download-artifact@v2
with:
name: note_arduino_ci_image
path: /tmp

- name: Load Docker image
shell: bash
run: |
docker load --input /tmp/note_arduino_ci_image.tar
27 changes: 0 additions & 27 deletions .github/actions/run-tests-in-container/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions .github/actions/run-tests-in-container/action.yml

This file was deleted.

141 changes: 121 additions & 20 deletions .github/workflows/note-arduino-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,92 @@ on:
branches: [ master ]

jobs:
validate_library: # job id
check_dockerfile_changed:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.filter.outputs.changed }}

steps:
- name: Checkout Code
id: checkout
- name: Checkout code
uses: actions/checkout@v3
- name: Run Tests In Container
id: containerized_tests
uses: ./.github/actions/run-tests-in-container
- name: Coveralls Action Bug Workaround
id: coveralls_bug_workaround
run: sudo sed -i 's/github\/workspace/home\/runner\/work\/note-arduino\/note-arduino/g' ./coverage/lcov.info
- name: Publish Test Coverage
id: publish_coverage

# TODO: This is a 3rd party GitHub action from some dude. Ideally, we'd
# use something more "official".
- name: Check if Dockerfile changed
uses: dorny/paths-filter@v2
id: filter
with:
base: 'master'
filters: |
changed:
- 'Dockerfile'
build_ci_docker_image:
runs-on: ubuntu-latest
needs: [check_dockerfile_changed]
if: ${{ needs.check_dockerfile_changed.outputs.changed == 'true' }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Rebuild image
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: ghcr.io/blues/note_arduino_ci:latest
outputs: type=docker,dest=/tmp/note_arduino_ci_image.tar

- name: Upload image artifact
uses: actions/upload-artifact@v3
with:
name: note_arduino_ci_image
path: /tmp/note_arduino_ci_image.tar

run_tests:
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [build_ci_docker_image]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Load CI Docker image
if: ${{ needs.build_ci_docker_image.result == 'success' }}
uses: ./.github/actions/load-ci-image

- name: Run tests
run: |
docker run --rm --volume $(pwd):/note-arduino/ \
--workdir /note-arduino/ \
--entrypoint ./test/run_all_tests.sh \
--user root \
ghcr.io/blues/note_arduino_ci:latest
- name: Adjust lcov source file paths for Coveralls
run: sudo sed -i 's/\/note-arduino\///g' ./coverage/lcov.info

- name: Publish test coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
validate_examples: # job id
path-to-lcov: ./coverage/lcov.info

build_examples:
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [build_ci_docker_image]
continue-on-error: true
strategy:
matrix:
Expand All @@ -38,26 +105,60 @@ jobs:
- ./examples/Example5_UsingTemplates/Example5_UsingTemplates.ino
- ./examples/Example6_SensorTutorial/Example6_SensorTutorial.ino
- ./examples/Example7_PowerControl/Example7_PowerControl.ino
- ./examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino
- ./examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino
# TODO: Uncomment these once note-c is updated with the necessary NoteBinary* functions.
# - ./examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino
# - ./examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino
fully-qualified-board-name:
- STMicroelectronics:stm32:BluesW:pnum=SWAN_R5
- esp32:esp32:featheresp32
- adafruit:samd:adafruit_feather_m4
- STMicroelectronics:stm32:GenF4:pnum=FEATHER_F405
- arduino:mbed_nano:nano33ble
# TODO: Fix this. May require upstream fix.
# - arduino:mbed_nano:nano33ble
- SparkFun:apollo3:sfe_artemis_thing_plus
- STMicroelectronics:stm32:Nucleo_32:pnum=NUCLEO_L432KC
- adafruit:nrf52:feather52840:softdevice=s140v6
- rp2040:rp2040:rpipico
- arduino:avr:uno

steps:
- name: Checkout Code
- name: Checkout code
id: checkout
uses: actions/checkout@v3

- name: Load CI docker image
if: ${{ needs.build_ci_docker_image.result == 'success' }}
uses: ./.github/actions/load-ci-image

- name: Compile Examples
id: compile_examples
uses: ./.github/actions/compile-examples
run: |
docker run --rm --volume $(pwd):/note-arduino/ \
--workdir /note-arduino/ \
--entrypoint ./examples/build_example.sh \
ghcr.io/blues/note_arduino_ci:latest \
${{ matrix.fully-qualified-board-name }} \
${{ matrix.example-sketch }}
publish_ci_image:
runs-on: ubuntu-latest
# Make sure tests passed and examples built successfully before publishing.
needs: [build_ci_docker_image, run_tests, build_examples]
# Only publish the image if this is a push event and the Docker image was rebuilt.
if: ${{ github.event_name == 'push' && needs.build_ci_docker_image.result == 'success' }}

steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Push image to registry
uses: docker/build-push-action@v4
with:
example-sketch: ${{ matrix.example-sketch }}
fully-qualified-board-name: ${{ matrix.fully-qualified-board-name }}
push: true
tags: ghcr.io/blues/note_arduino_ci:latest
18 changes: 8 additions & 10 deletions .github/actions/compile-examples/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Blues Inc. All rights reserved.
# Copyright 2023 Blues Inc. All rights reserved.
# Use of this source code is governed by licenses granted by the
# copyright holder including that found in the LICENSE file.

Expand All @@ -15,7 +15,7 @@ ARG UID=1000
ARG USER="blues"

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

# Import global arguments
ARG ARDUINO_CLI_VERSION
Expand Down Expand Up @@ -55,14 +55,20 @@ RUN ["dash", "-c", "\
bash-completion \
ca-certificates \
curl \
g++ \
gdb \
gzip \
lcov \
python-is-python3 \
python3 \
python3-pip \
ssh \
tree \
valgrind \
&& pip install \
adafruit-nrfutil \
pyserial \
--break-system-packages \
&& apt-get clean \
&& apt-get purge \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
Expand Down Expand Up @@ -104,11 +110,3 @@ RUN ["dash", "-c", "\
&& arduino-cli core install STMicroelectronics:stm32 \
&& arduino-cli lib install \"Blues Wireless Notecard Pseudo Sensor\" \
"]

# Set Execution Environment
USER root
WORKDIR /host-volume

ENTRYPOINT ["arduino-cli"]

CMD ["help"]
19 changes: 19 additions & 0 deletions examples/build_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
NOTE_ARDUINO_DIR="$SCRIPT_DIR/.."

# If this is being run inside a Docker container (i.e. for GitHub actions CI),
# copy the latest note-arduino code into the appropriate place so that it can
# be consumed when building the example.
if grep -sq 'docker\|lxc' /proc/1/cgroup; then
cp -r $NOTE_ARDUINO_DIR $HOME/Arduino/libraries/Blues_Wireless_Notecard
fi

arduino-cli compile \
--build-property compiler.cpp.extra_flags='-Wno-unused-parameter -Werror' \
--fqbn $1 \
--log-level trace \
--verbose \
--warnings all \
$2
11 changes: 8 additions & 3 deletions test/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ DEFAULT='\x1B[0;0m'

all_tests_result=0

# This fixes a problem when running valgrind in a Docker container when the
# host machine is running Fedora. See https://stackoverflow.com/a/75293014.
ulimit -n 1024

if [ 0 -eq $all_tests_result ]; then
echo && echo -e "${YELLOW}Compiling and running Notecard Test Suite...${DEFAULT}"
g++ -fprofile-arcs -ftest-coverage -Wall -Wextra -Werror -Wpedantic -std=c++11 -O0 -g \
Expand Down Expand Up @@ -164,20 +168,21 @@ if [ 0 -eq ${all_tests_result} ]; then

# Run coverage if available
if [ $(which lcov) ]; then
rm mock-*.gc?? *_Mock.gc?? *test.gc?? \
&& gcov --version \
rm -f mock-*.gc?? *_Mock.gc?? *test.gc??
gcov --version \
&& lcov --version \
&& mkdir -p ./coverage \
&& lcov --capture \
--directory . \
--no-external \
--exclude '/note-arduino/test/*' \
--output-file ./coverage/lcov.info \
--rc lcov_branch_coverage=1
if [ ! -f "./coverage/lcov.info" ]; then
echo -e "${YELLOW}COVERAGE REPORT NOT PRODUCED!!!${DEFAULT}";
all_tests_result=998
else
lcov --summary ./coverage/lcov.info
lcov --summary --rc lcov_branch_coverage=1 ./coverage/lcov.info
fi
fi
rm -f failed_test_run
Expand Down

0 comments on commit 55c21dd

Please sign in to comment.