From 132390b23e726927ac20d58a6448861af4811c2e Mon Sep 17 00:00:00 2001
From: Cameron Beneteau <cameron.beneteau@gmail.com>
Date: Mon, 2 Dec 2024 01:42:18 -0500
Subject: [PATCH] Create reusable workflow

---
 .github/workflows/build-test-deploy.yml      | 16 ++++---------
 .github/workflows/reusable-build-project.yml | 25 ++++++++++++++++++++
 .github/workflows/test-project-name.yml      | 17 ++++---------
 3 files changed, 35 insertions(+), 23 deletions(-)
 create mode 100644 .github/workflows/reusable-build-project.yml

diff --git a/.github/workflows/build-test-deploy.yml b/.github/workflows/build-test-deploy.yml
index d22196b3f..dc0fc9796 100644
--- a/.github/workflows/build-test-deploy.yml
+++ b/.github/workflows/build-test-deploy.yml
@@ -44,19 +44,13 @@ jobs:
           cd firmware
           make PROJECT=${{ steps.defaults.outputs.project_name }} PLATFORM=${{ steps.defaults.outputs.platform }} build
 
+  deploy:
+    runs-on: self-hosted
+    needs: build
+    environment: deploy
+    steps:
       - name: Upload artifacts
         uses: actions/upload-artifact@v4
         with:
           name: build-artifact-${{ steps.defaults.outputs.sanitized_project_name }}-${{ steps.defaults.outputs.platform }}
           path: firmware/build/${{ steps.defaults.outputs.project_name }}/${{ steps.defaults.outputs.platform }}
-
-#   deploy:
-#     runs-on: self-hosted
-#     needs: build
-#     environment: deploy
-#     steps:
-#       - name: Upload sanitized project artifacts
-#         uses: actions/upload-artifact@v4
-#         with:
-#           path: firmware/build/${{ steps.defaults.outputs.sanitized_project_name }}-${{ steps.defaults.outputs.platform }}
-#           name: build-artifact-${{ steps.defaults.outputs.sanitized_project_name }}-${{ steps.defaults.outputs.platform }}
diff --git a/.github/workflows/reusable-build-project.yml b/.github/workflows/reusable-build-project.yml
new file mode 100644
index 000000000..95ff6f5fe
--- /dev/null
+++ b/.github/workflows/reusable-build-project.yml
@@ -0,0 +1,25 @@
+name: Build Project
+
+on:
+  workflow_call:
+    inputs:
+      project:
+        description: 'Project to build (i.e. Demo/Blink)'
+        required: true
+        type: string
+      platform:
+        description: 'Platform to build for (i.e. cli, stm32f767)'
+        required: true
+        type: string
+
+jobs:
+    build:
+      runs-on: self-hosted
+      steps:
+        - name: Checkout repository
+          uses: actions/checkout@v4
+
+        - name: Build ${{ github.event.inputs.project }} for ${{ github.event.inputs.platform }}
+          run: |
+            cd firmware
+            make PROJECT=${{ github.event.inputs.project }} PLATFORM=${{ github.event.inputs.platform }} build
diff --git a/.github/workflows/test-project-name.yml b/.github/workflows/test-project-name.yml
index 0fd4ca0bb..ddf564209 100644
--- a/.github/workflows/test-project-name.yml
+++ b/.github/workflows/test-project-name.yml
@@ -7,15 +7,8 @@ jobs:
   test-string-replacement:
     runs-on: ubuntu-latest
     steps:
-      - name: Test project name sanitization
-        id: sanitize
-        run: |
-          project_name="Demo/Blink"
-          sanitized_name="${project_name//\//-}"
-          echo "Original project name: $project_name"
-          echo "Sanitized project name: $sanitized_name"
-          echo "::set-output name=sanitized_name::$sanitized_name"
-
-      - name: Display sanitized project name
-        run: |
-          echo "Sanitized project name is: ${{ steps.sanitize.outputs.sanitized_name }}"
\ No newline at end of file
+      - name: Build project
+        uses: ./github-actions/reusable-build-project
+        with:
+          project: Demo/Blink
+          platform: cli
\ No newline at end of file