From f22cb9ff1b47f7bb61483c167288fb94ea89b397 Mon Sep 17 00:00:00 2001 From: vidplace7 Date: Wed, 16 Oct 2024 00:14:45 -0400 Subject: [PATCH] Move config common to arch into yaml Keep this much simpler --- .vscode/launch.json | 1 - Containerfile | 1 + README.md | 7 ----- action.yml | 21 -------------- conf/arch_common.yaml | 26 ++++++++++++++++++ entrypoint.py | 64 +++++++++++++++++++++---------------------- requirements.txt | 1 + 7 files changed, 60 insertions(+), 61 deletions(-) create mode 100644 conf/arch_common.yaml diff --git a/.vscode/launch.json b/.vscode/launch.json index b19a8fc..14c4790 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,6 @@ "${command:pickArgs}", "--arch", "nrf52840", "--board", "xiao_ble", - "--build_script_path", "bin/build-nrf52.sh", ] } ] diff --git a/Containerfile b/Containerfile index 2030006..713c41a 100755 --- a/Containerfile +++ b/Containerfile @@ -19,6 +19,7 @@ RUN python -m pip install --upgrade pip && \ # Upgrade PlatformIO RUN pio upgrade +COPY conf /conf COPY entrypoint.py /entrypoint.py ENTRYPOINT [ "/entrypoint.py" ] CMD [ "master" ] \ No newline at end of file diff --git a/README.md b/README.md index cf2b227..959fc3e 100755 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ with: git-ref: master arch: nrf52840 board: xiao_ble - build-script-path: bin/build-nrf52.sh ``` ## Inputs @@ -19,12 +18,6 @@ with: | `git-ref` | True | `master` | The git ref (tag/branch) of the meshtastic firmware to checkout | | `arch` | True | `esp32` | | | `board` | True | _None_ | | -| `build-script-path` | True | _None_ | | -| `remove-debug-flags` | False | `""` | | -| `ota-firmware-source` | False | `""` | | -| `ota-firmware-target` | False | `""` | | -| `include-web-ui` | False | `"false"` | | - ## Outputs diff --git a/action.yml b/action.yml index 0d3a0ea..caf285b 100755 --- a/action.yml +++ b/action.yml @@ -13,25 +13,6 @@ inputs: board: description: The board to build for required: true - build-script-path: - description: Path to the build script - required: true - remove-debug-flags: - description: A space separated list of files to remove debug flags from - required: false - default: "" - ota-firmware-source: - description: The OTA firmware file to pull - required: false - default: "" - ota-firmware-target: - description: The target path to store the OTA firmware file - required: false - default: "" - include-web-ui: - description: Include the web UI in the build - required: false - default: "false" outputs: version: @@ -46,5 +27,3 @@ runs: - ${{ inputs.arch }} - --board - ${{ inputs.board }} - - --build_script_path - - ${{ inputs.build-script-path }} diff --git a/conf/arch_common.yaml b/conf/arch_common.yaml new file mode 100644 index 0000000..ffe03f7 --- /dev/null +++ b/conf/arch_common.yaml @@ -0,0 +1,26 @@ +--- +esp32s3: + remove-debug-flags: + - ./arch/esp32/esp32.ini + - ./arch/esp32/esp32s2.ini + - ./arch/esp32/esp32s3.ini + - ./arch/esp32/esp32c3.ini + build-script-path: bin/build-esp32.sh + ota-firmware-source: firmware-s3.bin + ota-firmware-target: release/bleota-s3.bin + artifact-paths: | + release/*.bin + release/*.elf + include-web-ui: true +nrf52840: + build-script-path: bin/build-nrf52.sh + artifact-paths: | + release/*.hex + release/*.uf2 + release/*.elf + release/*.zip +rp2040: + build-script-path: bin/build-rpi2040.sh + artifact-paths: | + release/*.uf2 + release/*.elf diff --git a/entrypoint.py b/entrypoint.py index 6b349a1..9cab559 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -7,6 +7,7 @@ import sys import shutil import argparse +import yaml from git import Repo @@ -25,20 +26,6 @@ help='The architecture to build for.') parser.add_argument('--board', type=str, required=True, help='The board to build for.') -parser.add_argument('--build_script_path', type=str, required=True, - help='The path to the build script.') -parser.add_argument('--remove_debug_flags', type=list, required=False, - default=str(os.getenv('INPUT_REMOVE-DEBUG-FLAGS', '')).split(), - help='The debug flags to remove from the build.') -parser.add_argument('--ota_firmware_source', type=str, required=False, - default=os.getenv('INPUT_OTA-FIRMWARE-SOURCE', ''), - help='The source path to download the OTA firmware.') -parser.add_argument('--ota_firmware_target', type=str, required=False, - default=os.getenv('INPUT_OTA-FIRMWARE-TARGET', ''), - help='The target path to save the OTA firmware.') -parser.add_argument('--include_web_ui', type=bool, required=False, - default=bool(os.getenv('INPUT_INCLUDE-WEB-UI', False)), - help='Whether to include the web UI in the build.') args = parser.parse_args() env = { @@ -46,6 +33,10 @@ 'XDG_CACHE_HOME': os.path.normpath(os.getenv('XDG_CACHE_HOME', '')) } +with open('/conf/arch_common.yaml', 'r') as arch_file: + arch_common = yaml.safe_load(arch_file) +arch_conf = arch_common[args.arch] + def gh_latest_release(owner, repo): r = requests.get(f"https://api.github.com/repos/{owner}/{repo}/releases/latest") r_j = r.json() @@ -96,19 +87,25 @@ def extract_tar(tar_file, extract_to, remove_src=False): os.system("git config --system --add safe.directory /github/workspace") # Web UI -if args.include_web_ui == True: - mt_web = gh_latest_release('meshtastic', 'web') - for asset in mt_web['assets']: - if asset['name'] == 'build.tar': - # Download build.tar - download_file(asset['browser_download_url'], 'build.tar') - # Extract build.tar - extract_tar('build.tar','data/static', remove_src=True) +try: + if arch_conf['include-web-ui'] == True: + mt_web = gh_latest_release('meshtastic', 'web') + for asset in mt_web['assets']: + if asset['name'] == 'build.tar': + # Download build.tar + download_file(asset['browser_download_url'], 'build.tar') + # Extract build.tar + extract_tar('build.tar','data/static', remove_src=True) +except KeyError: + pass # No web UI to download # Remove debug flags for release -if len(args.remove_debug_flags) > 0: - for flag in args.remove_debug_flags: - os.system(f"sed -i /DDEBUG_HEAP/d {flag}") +try: + if len(arch_conf['remove-debug-flags']) > 0: + for flag in arch_conf['remove-debug-flags']: + os.system(f"sed -i /DDEBUG_HEAP/d {flag}") +except KeyError: + pass # No debug flags to remove # Apply custom changes (if any) if os.path.exists('.custom'): @@ -117,18 +114,21 @@ def extract_tar(tar_file, extract_to, remove_src=False): # Run the Build sys.stdout.flush() # Fix subprocess output buffering issue -build_abspath = os.path.abspath(os.path.join(args.git_dir, args.build_script_path)) +build_abspath = os.path.abspath(os.path.join(args.git_dir, arch_conf['build-script-path'])) r_build = subprocess.run( [build_abspath, args.board], cwd=args.git_dir, check=True) # Pull OTA firmware -if args.ota_firmware_source != '' and args.ota_firmware_target != '': - ota_fw = gh_latest_release('meshtastic', 'firmware-ota') - for asset in ota_fw['assets']: - if asset['name'] == args.ota_firmware_source: - # Download firmware.bin - download_file(asset['browser_download_url'], args.ota_firmware_target) +try: + if arch_conf['ota-firmware-source'] != '' and arch_conf['ota-firmware-target'] != '': + ota_fw = gh_latest_release('meshtastic', 'firmware-ota') + for asset in ota_fw['assets']: + if asset['name'] == arch_conf['ota-firmware-source']: + # Download firmware.bin + download_file(asset['browser_download_url'], arch_conf['ota-firmware-target']) +except KeyError: + pass # No OTA firmware to download # When running in GitHub Actions if env['GITHUB_ACTIONS']: diff --git a/requirements.txt b/requirements.txt index fef41ca..7cf229e 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ requests GitPython platformio +PyYaml