-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add matrix generation and workflow usage
- Loading branch information
1 parent
c92fa06
commit 491c0a5
Showing
2 changed files
with
109 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' [email protected]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <projects_dir>") | ||
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) |