From c909eec369bd356e24d0c024a533491aa40a1bf0 Mon Sep 17 00:00:00 2001 From: ES-Alexander Date: Wed, 12 Jun 2024 23:57:34 +1000 Subject: [PATCH] auto-generate MAVLink messages files --- .github/workflows/deploy.yaml | 6 ++--- .../{run_param_parse.py => run_parsers.py} | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) rename scripts/{run_param_parse.py => run_parsers.py} (83%) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index ab5c90e..ea51a24 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -20,16 +20,16 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.8' # Set the Python version you need + python-version: '3.11' # Set the Python version you need - name: Install dependencies run: | - python -m pip install --upgrade pip GitPython packaging lxml emit xmltodict + python -m pip install --upgrade pip GitPython packaging lxml emit xmltodict pymavlink # Add any other dependencies here - name: Run Python script run: | - python scripts/run_param_parse.py + python scripts/run_parsers.py python scripts/json_from_xml.py - name: Commit and push if changed diff --git a/scripts/run_param_parse.py b/scripts/run_parsers.py similarity index 83% rename from scripts/run_param_parse.py rename to scripts/run_parsers.py index 3fe9f71..5ed5e77 100755 --- a/scripts/run_param_parse.py +++ b/scripts/run_parsers.py @@ -70,6 +70,9 @@ def run(self): tag_names = [tag.path[len('refs/tags/'):] for tag in self.repository.tags] last_ground_change = Groundskeeper.get_last_ground_change(git.Repo(Path(__file__).parent.parent)) + # Prepare for MAVLink parsing - always use the latest script (since it might cover new messages) + shutil.copy(f'{self.repository_path}/Tools/scripts/mavlink_parse.py', self.temp_folder) + # Get only valid tag names tags = [ { @@ -123,11 +126,14 @@ def run(self): print("Ignoring old version") continue - self.repository.git.checkout(tag_reference) + # Ignore local changes (they're automated anyway) + self.repository.git.checkout(tag_reference, force=True) tag_date = Groundskeeper.get_last_ground_change(self.repository) if last_ground_change > tag_date: print(f"Version already generated for {tag_date}") continue + + # Run parameters parser try: subprocess.run([f'{self.repository_path}/Tools/autotest/param_metadata/param_parse.py', '--vehicle', vehicle_type], cwd=self.repository_path) except Exception as exception: @@ -146,7 +152,19 @@ def run(self): shutil.copy2(data, dest) os.remove(data) + # Run MAVLink messages parser + vehicle = f'{"Ardu" if vehicle_type != "Rover" else ""}{vehicle_type}' + try: + # The parser expects to be run from its normal place in the repository + script_folder = f'{self.repository_path}/Tools/scripts/' + script_file = script_folder + 'mavlink_parse.py' + shutil.copy(f'{self.temp_folder}/mavlink_parse.py', script_file) + subprocess.run([script_file, '-cguq', '--header', 'ardupilot_wiki', '--format', 'rst', + '--filename', f'{dest}/MAVLinkMessages.rst', '--branch', folder_name, '--vehicle', vehicle], + cwd=script_folder) + except Exception as exception: + print(exception) G = Groundskeeper() -G.run() \ No newline at end of file +G.run()