Skip to content

Commit

Permalink
Fix version check, add flash script
Browse files Browse the repository at this point in the history
  • Loading branch information
Boernsman authored and Boernsman committed Aug 7, 2024
1 parent 083d9fe commit 4a8cc99
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

with:
fetch-depth: 0
fetch-tags: true

- name: Prepare environment
run: |
mkdir -p $HOME/.local/bin
echo "$HOME/.local/bin" >> $GITHUB_PATH
echo "git_hash=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_ENV
echo "version=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "Building firmware with version: ${{ env.version }} and git hash: ${{ env.git_hash }}"
GIT_HASH="\"$(git rev-parse --short $GITHUB_SHA)\""
echo "Git hash: $GIT_HASH"
echo "git_hash=$GIT_HASH" >> $GITHUB_ENV
VERSION="\"$(git describe --tags --abbrev=0)\""
echo "Version: $VERSION"
echo "version=$VERSION" >> $GITHUB_ENV
- name: Compile
uses: arduino/compile-sketches@v1
with:
fqbn: ${{ matrix.board.fqbn }}
verbose: true
sketch-paths: |
- ./firmware/
libraries: |
Expand All @@ -40,7 +47,7 @@ jobs:
cli-compile-flags: |
- --export-binaries
- --build-property
- build.extra_flags="-DVERSION=${{ env.version }} -DGIT_HASH=${{ env.git_hash }}"
- build.extra_flags="-DVERSION=${{ env.version }}" "-DGIT_HASH=${{ env.git_hash }}"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
Expand All @@ -62,6 +69,9 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Download build artifacts
uses: actions/download-artifact@v4
Expand Down
5 changes: 5 additions & 0 deletions firmware/firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
#include <ArduinoJson.h>

// Git version hash (replace with actual hash during build process)
#ifndef VERSION
#define VERSION "0.0.0"
#endif

#ifndef GIT_HASH
#define GIT_HASH "00000000"
#endif

// Define the LED pin and state
const int ledPin = 13; // Pin connected to the onboard LED
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_firmware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

# Copyright © 2024 Bitcrush Testing

VERSION=$(git describe --tags --abbrev=0)
VERSION="\"$(git describe --tags --abbrev=0)\""

if [ -z "$VERSION" ]; then
echo "Error: VERSION is empty"
exit 1
fi

GIT_HASH=$(git rev-parse --short HEAD)
GIT_HASH="\"$(git rev-parse --short HEAD)\""
BOARDS=("arduino:avr:uno" "arduino:renesas_uno:minima")
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

Expand Down
21 changes: 21 additions & 0 deletions scripts/flash_firmware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Copyright © 2024 Bitcrush Testing

BOARDS=("arduino:avr:uno" "arduino:renesas_uno:minima")
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$SCRIPT_DIR/../firmware/build"

if [ ! -e "$BUILD_DIR" ]; then
echo "Build the firmware first"
exit 1
fi

for BOARD in "${BOARDS[@]}"; do
PORT=$(python3 ./find_board_port.py $BOARD)
echo "Flashing $BOARD on port $PORT"
INPUT_DIR=$BUILD_DIR/$(echo "$BOARD" | tr ':' '.')
arduino-cli upload -p ${PORT} --fqbn ${BOARD} --input-dir ${INPUT_DIR} --verify --verbose
done

echo "-------- DONE ---------"
2 changes: 1 addition & 1 deletion tests/test_arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_git_hash(short=True):

try:
# Command to get the Git hash
cmd = ['git', 'rev-parse', '--short' if short else 'HEAD']
cmd = ['git', 'rev-parse', '--short', 'HEAD']

# Execute the command and get the output
git_hash = subprocess.check_output(cmd).decode('utf-8').strip()
Expand Down

0 comments on commit 4a8cc99

Please sign in to comment.