From a38dc7792283afa38524be323c52179e637328c9 Mon Sep 17 00:00:00 2001
From: Cyril Danilevski <cyril.danilevski@xfel.eu>
Date: Tue, 6 Feb 2024 17:50:23 +0100
Subject: [PATCH] Add CI

---
 .gitlab-ci.yml                             | 40 ++++++++++++++++++++++
 .gitlab/merge_request_templates/Default.md | 39 +++++++++++++++++++++
 README.md                                  |  9 ++++-
 3 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 .gitlab/merge_request_templates/Default.md

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..fdf8712
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,40 @@
+build:
+  image: europeanxfel/karabo-ci:ubuntu-22-003
+  script:
+    # Set up Arduino environment
+    - cat /etc/os-release
+    - apt-get install -y wget python3-pip
+    - wget -nv
+      https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz
+    - tar -xf arduino-cli_latest_Linux_64bit.tar.gz
+    - mv arduino-cli /usr/bin/arduino-cli
+
+    # Configure arduino-cli
+    - echo "board_manager:" > arduino-cli.yaml
+    - echo "  additional_urls:" >> arduino-cli.yaml
+    - echo "    - https://dl.espressif.com/dl/package_esp32_index.json" >> arduino-cli.yaml
+    - echo "library:" >> arduino-cli.yaml
+    - echo -n "  enable_unsafe_install:" >> arduino-cli.yaml
+    - echo " true" >> arduino-cli.yaml
+    - cat -E arduino-cli.yaml
+
+    # Set up esp32 support
+    - arduino-cli core update-index --config-file arduino-cli.yaml
+    - arduino-cli core install esp32:esp32
+
+    # Add pyserial for esp32 to chooch
+    - pip3 install pyserial
+
+    # Install dependencies
+    - arduino-cli lib install Ethernet
+    - arduino-cli lib install --git-url https://github.com/patricklaf/SNMP.git --config-file arduino-cli.yaml
+
+    # Compile artifact
+    - arduino-cli compile --fqbn esp32:esp32:esp32wroverkit icbm.ino --output-dir firmware
+    - zip -r firmware.zip firmware
+  artifacts:
+    when: always
+    paths:
+      - firmware.zip
+    expire_in: 1 week
+  interruptible: true
diff --git a/.gitlab/merge_request_templates/Default.md b/.gitlab/merge_request_templates/Default.md
new file mode 100644
index 0000000..20bd45f
--- /dev/null
+++ b/.gitlab/merge_request_templates/Default.md
@@ -0,0 +1,39 @@
+<!--- Provide a general summary of your changes in the Title above.  -->
+
+## Description
+<!--- Why is this change required? What problem does it solve?
+      If it fixes an issue, please link to the issue here. -->
+
+## How Has This Been Tested?
+<!--- Please describe in detail how you tested your changes.
+      Include details of your testing environment, tests ran to see how
+      your change affects other areas of the code, etc. -->
+
+## Relevant Documents (optional)
+<!-- Include any relevant screenshot, elogs, report, if appropriate. -->
+
+## Types of changes
+<!--- What types of changes does your code introduce? Leave lines that apply: -->
+
+- [ ] Bug fix (non-breaking change which fixes an issue)  
+- [ ] New feature (non-breaking change which adds functionality)  
+- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)  
+- [ ] Docs (changes to the documentation)  
+- [ ] Style (formatting changes only, no code changes)  
+- [ ] Refactor (refactoring code with no functionality changes)  
+- [ ] Test (additional or refactored tests)  
+- [ ] Chore (non-code changes, e.g. comments, readme, grammar, etc...)  
+
+## Checklist:
+<!--- Go over all the following points, and check all that apply: -->
+
+- [ ] My code follows the code style of this project.  
+- [ ] My change requires a change to the documentation.  
+- [ ] I have updated the documentation accordingly.  
+- [ ] I added tests where appropriate.  
+
+## Reviewers
+<!--- Specify who is to review the changes -->
+- [ ] I need a review from:  
+- [ ] I have asked Controls for review
+
diff --git a/README.md b/README.md
index 25a1654..e4c58da 100644
--- a/README.md
+++ b/README.md
@@ -53,4 +53,11 @@ The project can be compiled so:
 
 And uploaded so:
 
-    arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:esp32wroverkit .
+    arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:esp32wroverkit
+
+### CI Artefacts
+
+CI artefacts can be uploaded so:
+
+    unzip firmware.zip
+    arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:esp32wroverkit --input-dir firmware
-- 
GitLab