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 12, 2024
1 parent 083d9fe commit d9d6ff1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 17 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
6 changes: 3 additions & 3 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 All @@ -20,7 +20,7 @@ arduino-cli core install arduino:renesas_uno

for BOARD in "${BOARDS[@]}"; do
echo "Building $BOARD"
arduino-cli compile --fqbn ${BOARD} --build-property build.extra_flags="-DVERSION=${VERSION} -DGIT_HASH=${GIT_HASH}" ${SCRIPT_DIR}/../firmware --export-binaries
arduino-cli compile --fqbn "${BOARD}" --build-property build.extra_flags="-DVERSION=${VERSION} -DGIT_HASH=${GIT_HASH}" "${SCRIPT_DIR}/../firmware" --export-binaries
done

echo "-------- DONE ---------"
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 ---------"
17 changes: 9 additions & 8 deletions scripts/install_agent_node_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ check_raspberry_pi() {
prompt_for_input() {
local prompt_message="$1"
local input_variable_name="$2"
read -p "$prompt_message: " $input_variable_name
# shellcheck disable=SC2229
read -rp "$prompt_message: " "$input_variable_name"
}

# Function to check if arduino-cli is installed
Expand All @@ -43,10 +44,10 @@ install_github_runner() {
echo "Installing GitHub runner..."
RUNNER_DIR=${HOME}/actions-runner

if [ -d ${RUNNER_DIR} ]
if [ -d "${RUNNER_DIR}" ]
then
echo "GitHub runner is already installed."
read -p "Do you want to overwrite it? (yes/no) " yn
read -rp "Do you want to overwrite it? (yes/no) " yn

case $yn in
yes ) echo "Ok, proceeding";;
Expand All @@ -56,8 +57,8 @@ install_github_runner() {
return;;
esac
fi
rm -rf ${RUNNER_DIR}
mkdir -p ${RUNNER_DIR} && cd ${RUNNER_DIR}
rm -rf "${RUNNER_DIR}"
mkdir -p "${RUNNER_DIR}" && cd "${RUNNER_DIR}"
echo "Install folder: ${RUNNER_DIR}"
curl -o actions-runner-linux-arm64-2.317.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.317.0/actions-runner-linux-arm64-2.317.0.tar.gz
echo "7e8e2095d2c30bbaa3d2ef03505622b883d9cb985add6596dbe2f234ece308f3 actions-runner-linux-arm64-2.317.0.tar.gz" | shasum -a 256 -c
Expand All @@ -74,7 +75,7 @@ install_github_runner() {

# Create the systemd service file
SERVICE_FILE="/etc/systemd/system/github-runner.service"
sudo rm -f ${SERVICE_FILE}
sudo rm -f "${SERVICE_FILE}"
sudo bash -c "cat > $SERVICE_FILE" <<EOL
[Unit]
Description=GitHub Actions Runner
Expand Down Expand Up @@ -119,9 +120,9 @@ install_python() {

# Main script execution
set -e
user_id=`id -u`
USER_ID=$(id -u)

if [ $user_id -eq 0 -a -z "$RUNNER_ALLOW_RUNASROOT" ]; then
if [[ "$USER_ID" -eq 0 ]] && [[ -z "$RUNNER_ALLOW_RUNASROOT" ]]; then
echo "Must not run with sudo"
exit 1
fi
Expand Down
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 d9d6ff1

Please sign in to comment.