From c2294d663cb228ef53bbeada630fde8c31080084 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?=
 <francois.dekeersmaeker@uclouvain.be>
Date: Tue, 9 Jul 2024 15:11:21 +0200
Subject: [PATCH] CI: added build script

---
 .ci_scripts/build.sh              | 45 +++++++++++++++++++++++++++++++
 .github/workflows/unit-tests.yaml |  2 +-
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100755 .ci_scripts/build.sh

diff --git a/.ci_scripts/build.sh b/.ci_scripts/build.sh
new file mode 100755
index 0000000..f308222
--- /dev/null
+++ b/.ci_scripts/build.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# Build the project.
+# Usage: build.sh [-d working_directory] [-t cmake_toolchain_file]
+#   -d working_directory: The directory to build the project in.
+
+# Default values
+WORKING_DIRECTORY=""
+
+# Print usage information
+usage() {
+    echo "Usage: $0 [-d working_directory]" 1>&2
+    exit 1
+}
+
+# Parse command line arguments
+while getopts "d:" opt;
+do
+    case "${opt}" in
+        d)
+            # Working directory
+            WORKING_DIRECTORY="${OPTARG}"
+            echo "Building in directory ${WORKING_DIRECTORY}"
+            ;;
+        *)
+            usage
+            ;;
+    esac
+done
+shift $((OPTIND-1))
+
+# Change to working directory if specified
+if [[ $WORKING_DIRECTORY ]]
+then
+    cd $WORKING_DIRECTORY
+fi
+
+# Clean directory
+rm -rf build bin
+
+# Build project
+mkdir build bin
+cd build
+cmake ..
+cmake --build .
diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml
index 271081c..84dd977 100644
--- a/.github/workflows/unit-tests.yaml
+++ b/.github/workflows/unit-tests.yaml
@@ -15,7 +15,7 @@ jobs:
         run: sudo $GITHUB_WORKSPACE/.ci_scripts/install_packages.sh
 
       - name: Build project with CMake
-        run: $GITHUB_WORKSPACE/build.sh -d $GITHUB_WORKSPACE
+        run: $GITHUB_WORKSPACE/.ci_scripts/build.sh -d $GITHUB_WORKSPACE
 
       - name: Run CUnit tests
         run: $GITHUB_WORKSPACE/.ci_scripts/run_tests.sh
-- 
GitLab