diff --git a/.github/workflows/test-self-hosted.yml b/.github/workflows/test-self-hosted.yml index 3b8663d79..4918fb802 100644 --- a/.github/workflows/test-self-hosted.yml +++ b/.github/workflows/test-self-hosted.yml @@ -5,34 +5,79 @@ on: workflow_dispatch: jobs: - test-self-hosted-build: - runs-on: self-hosted - - steps: + test-self-hosted-setup: + runs-on: self-hosted + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Build for cli + - name: Set up Python + uses: action/setup-python@v4 + with: + python-version: '3.x' + + - name: Generate Matrix + id: generate-matrix run: | - cd firmware - make PROJECT=Demo/Blink PLATFORM=cli build + python generate_matrix.py firmware/projects + echo "::set-output name=matrix::$(cat matrix.json)" + + test-self-hosted-build: + runs-on: self-hosted + needs: test-self-hosted-setup + strategy: + matrix: ${{fromJson(needs.test-self-hosted-setup.outputs.matrix)}} + steps: + - name: Checkout repository + uses: actions/checkout@v4 - - name: Build for stm32f767 + - name: Build ${{ matrix.project }} for ${{ matrix.platform }} run: | cd firmware - make PROJECT=Demo/Blink PLATFORM=stm32f767 build + make PROJECT=${{ matrix.project }} PLATFORM=${{ matrix.platform }} build - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: Test Build Artifact - path: firmware/build/ + # - name: Upload artifacts + # uses: actions/upload-artifact@v4 + # with: + # name: Test Build Artifact + + # test-self-hosted-build: + # runs-on: self-hosted + + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Build for cli + # run: | + # cd firmware + # make PROJECT=Demo/Blink PLATFORM=cli build + + # - name: Build for stm32f767 + # run: | + # cd firmware + # make PROJECT=Demo/Blink PLATFORM=stm32f767 build + + # - name: Upload artifacts + # uses: actions/upload-artifact@v4 + # with: + # name: Test Build Artifact + # path: firmware/build/ + + # test-self-hosted-deploy: + # needs: test-self-hosted-build + # runs-on: self-hosted + # # environment: test-deploy - test-self-hosted-deploy: - needs: test-self-hosted-build - runs-on: self-hosted - environment: test-deploy + # steps: + # - name: Download artifacts + # uses: actions/download-artifact@v4 + # with: + # name: Test Build Artifact - steps: - - name: Test Deploy - run: echo "Deploying to test environment" + # - name: Deploy to Raspberry Pi + # run: | + # echo "Deploying to Raspberry Pi" + # scp -r 'Test Build Deploy' macformula@100.73.87.83: \ No newline at end of file diff --git a/scripts/actions/generate_matrix.py b/scripts/actions/generate_matrix.py new file mode 100644 index 000000000..b3f3bdf53 --- /dev/null +++ b/scripts/actions/generate_matrix.py @@ -0,0 +1,43 @@ +import json +import os +import sys + +def generate_matrix(projects_dir): + """ + Generates a matrix by recursively scanning for 'platforms' directories. + """ + matrix = [] + + # Walk through the projects directory + for root, dirs, files in os.walk(projects_dir): + if "platforms" in dirs: # Check if 'platforms' directory exists + project_name = os.path.basename(root) # Get the project name + platforms_dir = os.path.join(root, "platforms") + platforms = [ + platform for platform in os.listdir(platforms_dir) + if os.path.isdir(os.path.join(platforms_dir, platform)) + ] + for platform in platforms: + print(f"Found platform: {platform} in project: {project_name}") + matrix.append({"project": project_name, "platform": platform}) + + return matrix + + +if __name__ == "__main__": + print("Generating matrix for projects") + + if len(sys.argv) < 2: + print("Usage: python generate_matrix.py ") + sys.exit(1) + + projects_dir = sys.argv[1] + if not os.path.isdir(projects_dir): + print(f"Error: {projects_dir} is not a directory") + sys.exit(1) + + matrix = generate_matrix(projects_dir) + print(json.dumps(matrix, indent=4)) + + # Save the matrix to a file + with open("matrix.json", "w") as f: json.dump(matrix, f, indent=4) \ No newline at end of file