Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools: Automate the creation of apm.pdef.xml files #29242

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/create_apm_pdef_xml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run generate_pdef.xml_metadata.py

# Whenever a tag is pushed, create the corresponding parameter metadata documentation
# apm.pdef.xml file on the https://autotest.ardupilot.org/Parameters/versioned/ URL

on:
push:
tags:
- '*'

jobs:
run-script:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install rsync
run: sudo apt-get update && sudo apt-get install -y rsync

- name: Run generate_pdef.xml_metadata.py
env:
RSYNC_USERNAME: ${{ secrets.RSYNC_USERNAME }}
RSYNC_PASSWORD: ${{ secrets.RSYNC_PASSWORD }}
run: python Tools/scripts/generate_pdef.xml_metadata.py
34 changes: 18 additions & 16 deletions Tools/scripts/generate_pdef.xml_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
import subprocess

VEHICLE_TYPES = ["Copter", "Plane", "Rover", "ArduSub", "Tracker"] # Add future vehicle types here
RSYNC_USERNAME = 'amilcar'

RSYNC_USERNAME = os.environ.get('RSYNC_USERNAME')
if not RSYNC_USERNAME:
raise ValueError("RSYNC_USERNAME environment variable not set")

RSYNC_PASSWORD = os.environ.get('RSYNC_PASSWORD')
if not RSYNC_PASSWORD:
raise ValueError("RSYNC_PASSWORD environment variable not set")

# Store the current working directory
old_cwd = os.getcwd()
Expand All @@ -27,8 +34,6 @@ def get_vehicle_tags(vehicle_type):
Returns a list of tag names.
"""
try:
# Change to the ArduPilot directory
os.chdir('../ardupilot/')
tags_output = subprocess.check_output(['git', 'tag', '--list', f'{vehicle_type}-[0-9]\\.[0-9]\\.[0-9]'], text=True)
return tags_output.splitlines()
except Exception as e: # pylint: disable=broad-exception-caught
Expand All @@ -49,43 +54,40 @@ def generate_vehicle_versions():
return vehicle_versions

def create_one_pdef_xml_file(vehicle_type: str, dst_dir: str, git_tag: str):
os.chdir('../ardupilot')
subprocess.run(['git', 'checkout', git_tag], check=True)
# subprocess.run(['git', 'pull'], check=True)
subprocess.run(['Tools/autotest/param_metadata/param_parse.py', '--vehicle', vehicle_type, '--format', 'xml'], check=True)
# Return to the old working directory
os.chdir(old_cwd)

if not os.path.exists(dst_dir):
os.makedirs(dst_dir)

# Insert an XML comment on line 3 in the ../ardupilot/apm.pdef.xml file to indicate
# the tag used to generate the file and the current date
with open('../ardupilot/apm.pdef.xml', 'r', encoding='utf-8') as f:
with open('apm.pdef.xml', 'r', encoding='utf-8') as f:
lines = f.readlines()

# Insert an XML comment on line 3 in the apm.pdef.xml file
# with the tag used to generate the file and the current date
lines.insert(2, f'<!-- Generated from git tag {git_tag} on {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")} -->\n')
with open('../ardupilot/apm.pdef.xml', 'w', encoding='utf-8') as f:

with open('apm.pdef.xml', 'w', encoding='utf-8') as f:
f.writelines(lines)
shutil.copy('../ardupilot/apm.pdef.xml', f'{dst_dir}/apm.pdef.xml')
shutil.copy('apm.pdef.xml', f'{dst_dir}/apm.pdef.xml')

# Function to sync files using rsync
def sync_to_remote(vehicle_dir: str) -> None:
src_dir = f'{vehicle_dir}/'
dst_user = RSYNC_USERNAME
dst_host = 'firmware.ardupilot.org'
dst_path = f'param_versioned/{vehicle_dir}/'

# Construct the rsync command
# Construct the rsync command with rsync:// URL format
rsync_cmd = [
'rsync',
'-avz',
'--progress',
'--password-file=.rsync_pass',
src_dir,
f'{dst_user}@{dst_host}::{dst_path}'
f'rsync://{RSYNC_USERNAME}@{dst_host}/{dst_path}'
]

print(f'Synchronizing {src_dir} to {dst_path}...')
# RSYNC_PASSWORD environment variable will be automatically used by rsync
print(rsync_cmd)
subprocess.run(rsync_cmd, check=True)

Expand Down
Loading