Skip to content

Commit d9d6ff1

Browse files
BoernsmanBoernsman
authored andcommitted
Fix version check, add flash script
1 parent 083d9fe commit d9d6ff1

File tree

6 files changed

+54
-17
lines changed

6 files changed

+54
-17
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,26 @@ jobs:
1919
steps:
2020
- name: Checkout code
2121
uses: actions/checkout@v4
22-
22+
with:
23+
fetch-depth: 0
24+
fetch-tags: true
25+
2326
- name: Prepare environment
2427
run: |
2528
mkdir -p $HOME/.local/bin
2629
echo "$HOME/.local/bin" >> $GITHUB_PATH
27-
echo "git_hash=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_ENV
28-
echo "version=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
29-
echo "Building firmware with version: ${{ env.version }} and git hash: ${{ env.git_hash }}"
30+
GIT_HASH="\"$(git rev-parse --short $GITHUB_SHA)\""
31+
echo "Git hash: $GIT_HASH"
32+
echo "git_hash=$GIT_HASH" >> $GITHUB_ENV
33+
VERSION="\"$(git describe --tags --abbrev=0)\""
34+
echo "Version: $VERSION"
35+
echo "version=$VERSION" >> $GITHUB_ENV
3036
3137
- name: Compile
3238
uses: arduino/compile-sketches@v1
3339
with:
3440
fqbn: ${{ matrix.board.fqbn }}
41+
verbose: true
3542
sketch-paths: |
3643
- ./firmware/
3744
libraries: |
@@ -40,7 +47,7 @@ jobs:
4047
cli-compile-flags: |
4148
- --export-binaries
4249
- --build-property
43-
- build.extra_flags="-DVERSION=${{ env.version }} -DGIT_HASH=${{ env.git_hash }}"
50+
- build.extra_flags="-DVERSION=${{ env.version }}" "-DGIT_HASH=${{ env.git_hash }}"
4451
4552
- name: Upload build artifacts
4653
uses: actions/upload-artifact@v4
@@ -62,6 +69,9 @@ jobs:
6269
steps:
6370
- name: Checkout code
6471
uses: actions/checkout@v4
72+
with:
73+
fetch-depth: 0
74+
fetch-tags: true
6575

6676
- name: Download build artifacts
6777
uses: actions/download-artifact@v4

firmware/firmware.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
#include <ArduinoJson.h>
66

77
// Git version hash (replace with actual hash during build process)
8+
#ifndef VERSION
89
#define VERSION "0.0.0"
10+
#endif
11+
12+
#ifndef GIT_HASH
913
#define GIT_HASH "00000000"
14+
#endif
1015

1116
// Define the LED pin and state
1217
const int ledPin = 13; // Pin connected to the onboard LED

scripts/build_firmware.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# Copyright © 2024 Bitcrush Testing
44

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

77
if [ -z "$VERSION" ]; then
88
echo "Error: VERSION is empty"
99
exit 1
1010
fi
1111

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

@@ -20,7 +20,7 @@ arduino-cli core install arduino:renesas_uno
2020

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

2626
echo "-------- DONE ---------"

scripts/flash_firmware.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# Copyright © 2024 Bitcrush Testing
4+
5+
BOARDS=("arduino:avr:uno" "arduino:renesas_uno:minima")
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
BUILD_DIR="$SCRIPT_DIR/../firmware/build"
8+
9+
if [ ! -e "$BUILD_DIR" ]; then
10+
echo "Build the firmware first"
11+
exit 1
12+
fi
13+
14+
for BOARD in "${BOARDS[@]}"; do
15+
PORT=$(python3 ./find_board_port.py "$BOARD")
16+
echo "Flashing $BOARD on port $PORT"
17+
INPUT_DIR=$BUILD_DIR/$(echo "$BOARD" | tr ':' '.')
18+
arduino-cli upload -p "${PORT}" --fqbn "${BOARD}" --input-dir "${INPUT_DIR}" --verify --verbose
19+
done
20+
21+
echo "-------- DONE ---------"

scripts/install_agent_node_dependencies.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ check_raspberry_pi() {
1717
prompt_for_input() {
1818
local prompt_message="$1"
1919
local input_variable_name="$2"
20-
read -p "$prompt_message: " $input_variable_name
20+
# shellcheck disable=SC2229
21+
read -rp "$prompt_message: " "$input_variable_name"
2122
}
2223

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

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

5152
case $yn in
5253
yes ) echo "Ok, proceeding";;
@@ -56,8 +57,8 @@ install_github_runner() {
5657
return;;
5758
esac
5859
fi
59-
rm -rf ${RUNNER_DIR}
60-
mkdir -p ${RUNNER_DIR} && cd ${RUNNER_DIR}
60+
rm -rf "${RUNNER_DIR}"
61+
mkdir -p "${RUNNER_DIR}" && cd "${RUNNER_DIR}"
6162
echo "Install folder: ${RUNNER_DIR}"
6263
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
6364
echo "7e8e2095d2c30bbaa3d2ef03505622b883d9cb985add6596dbe2f234ece308f3 actions-runner-linux-arm64-2.317.0.tar.gz" | shasum -a 256 -c
@@ -74,7 +75,7 @@ install_github_runner() {
7475

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

120121
# Main script execution
121122
set -e
122-
user_id=`id -u`
123+
USER_ID=$(id -u)
123124

124-
if [ $user_id -eq 0 -a -z "$RUNNER_ALLOW_RUNASROOT" ]; then
125+
if [[ "$USER_ID" -eq 0 ]] && [[ -z "$RUNNER_ALLOW_RUNASROOT" ]]; then
125126
echo "Must not run with sudo"
126127
exit 1
127128
fi

tests/test_arduino.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_git_hash(short=True):
2222

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

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

0 commit comments

Comments
 (0)