Skip to content

Commit

Permalink
Move config common to arch into yaml
Browse files Browse the repository at this point in the history
Keep this much simpler
  • Loading branch information
vidplace7 committed Oct 16, 2024
1 parent 83d695e commit 33285cd
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 54 deletions.
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"${command:pickArgs}",
"--arch", "nrf52840",
"--board", "xiao_ble",
"--build_script_path", "bin/build-nrf52.sh",
]
}
]
Expand Down
1 change: 1 addition & 0 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
42 changes: 21 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ 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"
# 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:
Expand All @@ -46,5 +46,5 @@ runs:
- ${{ inputs.arch }}
- --board
- ${{ inputs.board }}
- --build_script_path
- ${{ inputs.build-script-path }}
# - --build_script_path
# - ${{ inputs.build-script-path }}
26 changes: 26 additions & 0 deletions conf/arch_common.yaml
Original file line number Diff line number Diff line change
@@ -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
78 changes: 46 additions & 32 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import shutil
import argparse
import yaml

from git import Repo

Expand All @@ -25,27 +26,31 @@
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.')
# 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 = {
'GITHUB_ACTIONS': bool(os.getenv('GITHUB_ACTIONS')),
'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()
Expand Down Expand Up @@ -96,19 +101,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 args.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'):
Expand All @@ -117,18 +128,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']:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests
GitPython
platformio
PyYaml

0 comments on commit 33285cd

Please sign in to comment.