From b04a9adc14f3a594d62c3cf4ec6732f1b58dc85c Mon Sep 17 00:00:00 2001 From: Loki077 Date: Tue, 31 Dec 2024 10:21:39 +1100 Subject: [PATCH 1/6] CarbonixCommon: Add status in aircraft config file This will help to identify the status of the aircraft configuration file whether it is in active or depericated state. If the status is 'depericated' then the CI won't build the firmware for that aircraft configuration. --- .../hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_2.xml | 1 + .../hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_1.xml | 1 + .../hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_2.xml | 1 + .../hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_3.xml | 1 + 4 files changed, 4 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_2.xml b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_2.xml index c565c47b38..df3fa23a7e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_2.xml +++ b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_2.xml @@ -17,6 +17,7 @@ CAN Airspeed, CAN Battery Monitor + active 1 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_1.xml b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_1.xml index 8b3697f4a0..ef82c1b7ed 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_1.xml +++ b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_1.xml @@ -13,6 +13,7 @@ Non Crystal CPNs, CAN Airspeed + active 1 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_2.xml b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_2.xml index a762c47472..882ed542ad 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_2.xml +++ b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_2.xml @@ -14,6 +14,7 @@ CAN GPS, CAN Airspeed + active 1 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_3.xml b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_3.xml index c334ec568a..6fa557e2af 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_3.xml +++ b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Volanti_AC_3.xml @@ -14,6 +14,7 @@ CAN GPS, CAN Airspeed + active 1 From c8793cc39256a30457aa68e60593c9d19f964db8 Mon Sep 17 00:00:00 2001 From: Loki077 Date: Tue, 31 Dec 2024 10:24:18 +1100 Subject: [PATCH 2/6] CarbonixCommon: Deprecated Ottano_AC_1. --- .../hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_1.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_1.xml b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_1.xml index 8f441aceb1..56f6c30bc1 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_1.xml +++ b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/Ottano_AC_1.xml @@ -17,6 +17,7 @@ CAN Airspeed, CAN Battery Monitor + deprecated 1 From a36f2c6878214f315dc969c7f6ba3c69ba8fd944 Mon Sep 17 00:00:00 2001 From: Loki077 Date: Tue, 31 Dec 2024 10:25:28 +1100 Subject: [PATCH 3/6] Tools: aircraft_config.py add status check. This will only process file with status 'active'. --- Tools/Carbonix_scripts/aircraft_config.py | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tools/Carbonix_scripts/aircraft_config.py b/Tools/Carbonix_scripts/aircraft_config.py index 0dae0d95fe..91404862d5 100644 --- a/Tools/Carbonix_scripts/aircraft_config.py +++ b/Tools/Carbonix_scripts/aircraft_config.py @@ -231,6 +231,28 @@ def build_flight_controller_firmware(board_name : str) -> None: raise RuntimeError(f"Error building firmware for {board_name}") +def check_config_status(xml_file : str) -> bool: + """Check the status of the aircraft configuration. + + Args: + xml_file (str): Path to the XML file. + Returns: + bool: False if the configuration is deprecated, True otherwise. + """ + tree = ET.parse(xml_file) + root = tree.getroot() + + aircraft = root.find('aircraft') + if aircraft is None: + raise AssertionError(f"'aircraft' element not found in {xml_file}") + + status = aircraft.find('status') + if status is None: + raise AssertionError(f"'status' element not found in the 'aircraft' element of {xml_file}") + + return status.text == 'active' + + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('xml_file', help='Path to the XML file') @@ -241,6 +263,10 @@ def build_flight_controller_firmware(board_name : str) -> None: print('XML file:', args.xml_file) print('Commit ID:', args.commit_id) + if not check_config_status(args.xml_file): + print('Aircraft configuration is deprecated. No further action needed.') + exit(0) + xml_file = copy_configuration_file(args.xml_file, args.commit_id) copy_lua_scripts(xml_file) fc_board_name = get_flight_controller_board_name(xml_file) From c845db8273a667088303c53fd3966e2a1ebe3683 Mon Sep 17 00:00:00 2001 From: Loki077 Date: Tue, 31 Dec 2024 10:28:02 +1100 Subject: [PATCH 4/6] Ci: carbonix_build.yml fix job name. Previously in job name the complete path was being used, which was causing issues to see the job name in the github actions. This commit fixes the job name to only show the Aircraft name. --- .github/workflows/carbonix_build.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/carbonix_build.yml b/.github/workflows/carbonix_build.yml index c48f7a245c..587ab973ff 100644 --- a/.github/workflows/carbonix_build.yml +++ b/.github/workflows/carbonix_build.yml @@ -265,7 +265,10 @@ jobs: - name: Collect XML files id: collect run: | - xml_files=$(find libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration -name "*.xml" -print0 | xargs -0 echo | tr -d '\n' | jq -R -s -c 'split(" ")') + xml_files=$(find libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration -name "*.xml" -print0 | \ + xargs -0 -n 1 basename | \ + sed 's/.xml$//' | \ + jq -R -s -c 'split("\n")[:-1]') echo "aircraft-config-files=$xml_files" >> $GITHUB_OUTPUT process-ac: @@ -317,8 +320,7 @@ jobs: - name: Run aircraft_config.py run: | - python Tools/Carbonix_scripts/aircraft_config.py ${{ matrix.xml_file }} ${{ env.commit_id }} - ls -la final-output/*/ || echo "No files found" + python Tools/Carbonix_scripts/aircraft_config.py "libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/${{ matrix.xml_file }}.xml" "${{ env.commit_id }}" - name: Install AWS CLI run: | From 6a99f2ea4f9e3521f7bb03c3e9c3b7f91ca060ee Mon Sep 17 00:00:00 2001 From: Loki077 Date: Tue, 31 Dec 2024 10:29:51 +1100 Subject: [PATCH 5/6] Ci: carbonix_build.yml only process active AC. As the python script won't generate an output if the aircraft config status is deprecated. Adding cecking for final-output directory before AWS CLI installation and S3 upload to avoid unnecessary steps. --- .github/workflows/carbonix_build.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/carbonix_build.yml b/.github/workflows/carbonix_build.yml index 587ab973ff..3e2f12ef01 100644 --- a/.github/workflows/carbonix_build.yml +++ b/.github/workflows/carbonix_build.yml @@ -319,10 +319,19 @@ jobs: shell: sh -e {0} - name: Run aircraft_config.py + id: aircraft_config run: | python Tools/Carbonix_scripts/aircraft_config.py "libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/aircraft_configuration/${{ matrix.xml_file }}.xml" "${{ env.commit_id }}" + if [ -d "final-output" ]; then + echo "exists=true" >> $GITHUB_ENV + echo "Found final-output directory" + else + echo "exists=false" >> $GITHUB_ENV + echo "No final-output directory found" + fi - name: Install AWS CLI + if: ${{ env.exists == 'true' }} run: | apt-get update -y DEBIAN_FRONTEND=noninteractive apt-get install -y curl unzip @@ -331,6 +340,7 @@ jobs: ./aws/install --update - name: Configure AWS credentials + if: ${{ env.exists == 'true' }} uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} @@ -338,6 +348,7 @@ jobs: aws-region: us-east-1 - name: Upload to S3 + if: ${{ env.exists == 'true' }} run: | PATH_TO_S3=${{ needs.setup-s3-path.outputs.s3_path }} echo "Uploading Artifacts to: $PATH_TO_S3" From 7ff704a0ef627eb8813f6cc717e2239a698ec2e9 Mon Sep 17 00:00:00 2001 From: Loki077 Date: Tue, 31 Dec 2024 10:31:54 +1100 Subject: [PATCH 6/6] Ci: carbonix_build.yml to upload 7zip folder. This filters the correct folders and 7zips them to be uploaded to S3. --- .github/workflows/carbonix_build.yml | 89 ++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/.github/workflows/carbonix_build.yml b/.github/workflows/carbonix_build.yml index 3e2f12ef01..ebaa3cea7b 100644 --- a/.github/workflows/carbonix_build.yml +++ b/.github/workflows/carbonix_build.yml @@ -354,6 +354,14 @@ jobs: echo "Uploading Artifacts to: $PATH_TO_S3" aws s3 cp final-output/ $PATH_TO_S3 --recursive + - name: Upload build artifacts + if: ${{ env.exists == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.xml_file }} + path: final-output/${{ matrix.xml_file }}/ + + build-sitl: runs-on: 'windows-latest' if: ${{ !contains(github.event.pull_request.labels.*.name, 'SKIP_BUILD') }} @@ -459,3 +467,84 @@ jobs: $env:PATH_TO_S3 = '${{ needs.setup-s3-path.outputs.s3_path }}' echo "Uploading to: $env:PATH_TO_S3" aws s3 cp temp/ $env:PATH_TO_S3 --recursive + + build-upload-zip: + runs-on: ubuntu-22.04 + if: ${{ !contains(github.event.pull_request.labels.*.name, 'SKIP_BUILD') }} + needs: [process-ac, build-sitl, setup-s3-path] + steps: + - name: Extract folder name from s3_path + id: extract-folder-name + run: | + s3_path="${{ needs.setup-s3-path.outputs.s3_path }}" + folder_name=$(basename "$s3_path") + echo "folder_name=$folder_name" >> $GITHUB_ENV + + - name: Create folder from s3_path + run: mkdir -p aircraft_zip + + - name: List available artifacts + id: list-artifacts + uses: actions/github-script@v6 + with: + script: | + const artifacts = await github.rest.actions.listArtifactsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + return artifacts.data.artifacts.map(artifact => artifact.name); + + - name: Filter artifacts + id: filter-artifacts + run: | + echo "Filtered artifacts:" > filtered_artifacts.txt + for artifact in ${{ steps.list-artifacts.outputs.result }}; do + if [[ $artifact =~ .*_AC_.*[0-9]+(\.[0-9]+)? ]]; then + echo $artifact >> filtered_artifacts.txt + fi + done + echo "sitl" >> filtered_artifacts.txt + cat filtered_artifacts.txt + + - name: Download filtered artifacts + uses: actions/download-artifact@v4 + with: + name: ${{ steps.filter-artifacts.outputs.result }} + path: aircraft_zip/ + + - name: Delete unnecessary folders + run: | + rm -rf aircraft_zip/build-periph-* + + - name: List downloaded files + run: ls -R aircraft_zip/ + + - name: Install p7zip + run: sudo apt-get install -y p7zip-full + + - name: 7zip the folder + run: | + cd aircraft_zip + 7z a ../${{ env.folder_name }}.7z . + + - name: Upload 7z folder to artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ env.folder_name }} + path: ${{ env.folder_name }}.7z + retention-days: 15 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Upload 7z folder to S3 + run: | + PATH_TO_S3=${{ needs.setup-s3-path.outputs.s3_path }} + # Remove trailing slash if it exists + PATH_TO_S3=${PATH_TO_S3%/} + echo "Uploading to: $PATH_TO_S3" + aws s3 cp ${{ env.folder_name }}.7z $PATH_TO_S3/${{ env.folder_name }}.7z