Skip to content

Commit 26beb0e

Browse files
committed
Add GitHub Actions build test workflow
1 parent 657c600 commit 26beb0e

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

.github/workflows/BuildTest.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# GitHub Actions workflow to build the Arduino sketch for a compile-time test
2+
# Author: Jorge Rivera
3+
# Repository: https://github.com/latchdevel/C_ESR_METER
4+
# Created: September 2025
5+
6+
# Name displayed for this workflow in GitHub UI
7+
name: Build Test
8+
9+
# Define target board and platform for Arduino build
10+
env:
11+
ARDUINO_BOARD: Arduino Nano
12+
ARDUINO_PLATFORM: arduino:avr
13+
ARDUINO_FQBN: arduino:avr:nano
14+
ARDUINO_ADDITIONAL_URL:
15+
16+
# Trigger the workflow when modifying the source or workflow files
17+
on:
18+
push:
19+
paths:
20+
- '**/*.h'
21+
- '**/*.hpp'
22+
- '**/*.cpp'
23+
- '**/*.ino'
24+
- '.github/workflows/*.yml'
25+
pull_request:
26+
paths:
27+
- '**/*.h'
28+
- '**/*.hpp'
29+
- '**/*.cpp'
30+
- '**/*.ino'
31+
- '.github/workflows/*.yml'
32+
33+
# Scheduled run: this workflow will execute monthly on the 1st at 00:00 UTC
34+
schedule:
35+
- cron: '0 0 1 * *'
36+
37+
# Allows you to run this workflow manually from the Actions tab
38+
workflow_dispatch:
39+
40+
# Allows external systems to trigger this workflow via GitHub API
41+
repository_dispatch:
42+
43+
jobs:
44+
build:
45+
name: Compile Test
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
# Retrieve repository contents for workflow execution
50+
- name: Checkout repository
51+
uses: actions/checkout@v5
52+
53+
# Extract repository name for artifact naming
54+
- name: Get repository name
55+
run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV
56+
57+
# Extract short commit hash for artifact naming
58+
- name: Get short commit hash
59+
run: |
60+
COMMIT_SHORT_SHA=$(git rev-parse --short HEAD)
61+
echo "COMMIT_SHORT_SHA=$COMMIT_SHORT_SHA" >> $GITHUB_ENV
62+
echo -e "\033[34;1mUsing commit hash: $COMMIT_SHORT_SHA\033[0m"
63+
64+
# Run Arduino Lint to validate sketch structure and compliance
65+
- name: Arduino Lint
66+
uses: arduino/arduino-lint-action@v2
67+
with:
68+
library-manager: false
69+
project-type: sketch
70+
recursive: true
71+
compliance: strict
72+
73+
# Setup Arduino CLI environment for build process
74+
- name: Setup Arduino CLI
75+
uses: arduino/setup-arduino-cli@v2
76+
77+
# Install Arduino CLI platform core for selected board
78+
- name: Install platform for ${{ env.ARDUINO_BOARD }}
79+
run: |
80+
arduino-cli config init -v ${{ env.ARDUINO_ADDITIONAL_URL }}
81+
arduino-cli core update-index -v
82+
arduino-cli core install -v ${{ env.ARDUINO_PLATFORM }} --run-post-install
83+
84+
# Install LiquidCrystal_I2C library from Arduino library manager
85+
- name: Install LiquidCrystal_I2C library
86+
run: |
87+
arduino-cli lib update-index
88+
arduino-cli lib install LiquidCrystal_I2C
89+
90+
# Compile the Arduino sketch with full verbosity and all warnings enabled
91+
- name: Compile Sketch
92+
run: |
93+
arduino-cli compile --fqbn ${{ env.ARDUINO_FQBN }} -v --warnings all --export-binaries --no-color | tee build-${{ env.COMMIT_SHORT_SHA }}-log.txt
94+
EXIT_CODE=${PIPESTATUS[0]}
95+
exit $EXIT_CODE
96+
97+
# Upload compiled firmware and build log as single artifact
98+
- name: Upload compiled firmware and build log
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: "Firmware ${{ env.REPO_NAME }} commit #${{ env.COMMIT_SHORT_SHA }} for ${{ env.ARDUINO_BOARD }}"
102+
path: |
103+
build-${{ env.COMMIT_SHORT_SHA }}-log.txt
104+
build/**

0 commit comments

Comments
 (0)