-
Notifications
You must be signed in to change notification settings - Fork 21
/
build_parallel_workflow.py
93 lines (71 loc) · 2.87 KB
/
build_parallel_workflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
WORKFLOW_TEMPLATE = """
# This is a faster workflow that parallelizes the jobs in a matrix so
# we can get faster results than waiting for the standard build_all_frc_projects
# powershell script
name: Build all FRC Projects
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
strategy:
fail-fast: false
matrix:
include:{projects_as_matrix}
# The type of runner that the job will run on
runs-on: ubuntu-latest
# This grabs the WPILib docker container
container: wpilib/roborio-cross-ubuntu:2024-22.04
steps:
- uses: actions/checkout@v4
# Grant execute permission for gradlew
- name: Grant execute permission for gradlew
run: cd "${{{{ matrix.directory }}}}" && chmod +x gradlew
# Runs a single command using the runners shell
- name: Compile and run tests on robot code for project ${{{{ matrix.project-name }}}}
run: cd "${{{{ matrix.directory }}}}" && ./gradlew build
build-python:
strategy:
fail-fast: false
matrix:
python_version: ['3.9', '3.10', '3.11']
os: ['ubuntu-22.04', 'macos-12', 'windows-2022']
project-name: [{python_projects}]
runs-on: ${{{{ matrix.os }}}}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{{{ matrix.python_version }}}}
- name: Install python dependencies
run: |
pip install -U pip
pip install 'robotpy' phoenix6
- name: Test ${{{{ matrix.project-name }}}}
run: |
cd "python/${{{{ matrix.project-name }}}}" && python3 -m robotpy test
"""
PROJECT_MATRIX_TEMPLATE = """
- project-name: '{project_name}'
directory: '{project_dir}'"""
MATRIX_TEMPLATE = "'{project_name}'"
PROJECTS_TO_SEARCH = ["cpp", "java"]
PYTHON_PROJECTS_TO_SEARCH = ["python"]
project_matrix = []
for project_dir in PROJECTS_TO_SEARCH:
# Find every project in here and build up an array of strings to generate the workflow file
for project in os.listdir(project_dir):
project_matrix.append(PROJECT_MATRIX_TEMPLATE.format(project_name=project, project_dir=f"{project_dir}/{project}"))
python_project_matrix = []
for project_dir in PYTHON_PROJECTS_TO_SEARCH:
# Find every project in here and build up an array of strings to generate the workflow file
for project in os.listdir(project_dir):
python_project_matrix.append(MATRIX_TEMPLATE.format(project_name=project))
with open(".github/workflows/build-all-parallel.yml", "w", encoding="utf-8") as workflow_file:
workflow_file.write(WORKFLOW_TEMPLATE.format(projects_as_matrix="".join(project_matrix),
python_projects=", ".join(python_project_matrix)))