From 754905f7001052368c1cfb80db47cacfeeb8737b Mon Sep 17 00:00:00 2001 From: Lucas PASCAL Date: Wed, 15 Jan 2025 09:37:13 +0100 Subject: [PATCH] [draft] Fetching & compiling all apps on all devices --- .github/workflows/build_all.yml | 6 +- .github/workflows/build_for_sdks.yml | 113 +++++++++++++++++++++++++++ .github/workflows/refresh_inputs.yml | 6 +- .github/workflows/scan_all.yml | 6 +- .github/workflows/test_all.yml | 6 +- .gitignore | 1 + script.py | 69 ++++++++++++++++ 7 files changed, 195 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/build_for_sdks.yml create mode 100644 script.py diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index f12f06b..d9a5e33 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -1,10 +1,10 @@ name: Build apps on given SDK ref on: - schedule: - - cron: '32 5 * * 1,2,3,4,5' + # schedule: + # - cron: '32 5 * * 1,2,3,4,5' - pull_request: + # pull_request: workflow_dispatch: inputs: diff --git a/.github/workflows/build_for_sdks.yml b/.github/workflows/build_for_sdks.yml new file mode 100644 index 0000000..ad4dff8 --- /dev/null +++ b/.github/workflows/build_for_sdks.yml @@ -0,0 +1,113 @@ +name: APP-TESTER TESTS + +on: + workflow_dispatch: + push: + pull_request: + +jobs: + + define_matrix: + runs-on: ubuntu-latest + outputs: + app_url_by_device: ${{ steps.process_devices.outputs.app_url_by_device }} + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: | + pip install ledgered + - name: Define the list of application to build by device + id: process_devices + run: | + devices=$(python script.py -d all -t ${{ secrets.GITHUB_TOKEN }}) + echo "app_url_by_device=$devices" >> $GITHUB_OUTPUT + + + run_builds_nanos: + runs-on: ubuntu-latest + needs: define_matrix + container: + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest + strategy: + fail-fast: false + matrix: + app_name: ${{ fromJSON(needs.define_matrix.outputs.app_url_by_device)['nanos'] }} + steps: + - uses: actions/checkout@v4 + with: + repository: LedgerHQ/${{ matrix.app_name }} + - name: Build the app + run: | + make BOLOS_SDK=$NANOS_SDK + + + run_builds_nanos_plus: + runs-on: ubuntu-latest + needs: define_matrix + container: + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest + strategy: + fail-fast: false + matrix: + app_name: ${{ fromJSON(needs.define_matrix.outputs.app_url_by_device)['nanos+'] }} + steps: + - uses: actions/checkout@v4 + with: + repository: LedgerHQ/${{ matrix.app_name }} + - name: Build the app + run: | + make BOLOS_SDK=$NANOSP_SDK + + + run_builds_nanox: + runs-on: ubuntu-latest + needs: define_matrix + container: + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest + strategy: + fail-fast: false + matrix: + app_name: ${{ fromJSON(needs.define_matrix.outputs.app_url_by_device)['nanox'] }} + steps: + - uses: actions/checkout@v4 + with: + repository: LedgerHQ/${{ matrix.app_name }} + - name: Build the app + run: | + make BOLOS_SDK=$NANOX_SDK + + + run_builds_flex: + runs-on: ubuntu-latest + needs: define_matrix + container: + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest + strategy: + fail-fast: false + matrix: + app_name: ${{ fromJSON(needs.define_matrix.outputs.app_url_by_device)['flex'] }} + steps: + - uses: actions/checkout@v4 + with: + repository: LedgerHQ/${{ matrix.app_name }} + - name: Build the app + run: | + make BOLOS_SDK=$FLEX_SDK + + + run_builds_staxx: + runs-on: ubuntu-latest + needs: define_matrix + container: + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest + strategy: + fail-fast: false + matrix: + app_name: ${{ fromJSON(needs.define_matrix.outputs.app_url_by_device)['stax'] }} + steps: + - uses: actions/checkout@v4 + with: + repository: LedgerHQ/${{ matrix.app_name }} + - name: Build the app + run: | + make BOLOS_SDK=$STAX_SDK diff --git a/.github/workflows/refresh_inputs.yml b/.github/workflows/refresh_inputs.yml index cce57b2..a1a2d66 100644 --- a/.github/workflows/refresh_inputs.yml +++ b/.github/workflows/refresh_inputs.yml @@ -11,9 +11,9 @@ on: type: boolean required: false default: false - schedule: - - cron: '32 5 * * 3' - pull_request: + # schedule: + # - cron: '32 5 * * 3' + # pull_request: jobs: diff --git a/.github/workflows/scan_all.yml b/.github/workflows/scan_all.yml index 9bf3020..487d28d 100644 --- a/.github/workflows/scan_all.yml +++ b/.github/workflows/scan_all.yml @@ -1,10 +1,10 @@ name: Scan apps on given SDK ref on: - schedule: - - cron: '32 5 * * 1,2,3,4,5' + # schedule: + # - cron: '32 5 * * 1,2,3,4,5' - pull_request: + # pull_request: workflow_dispatch: inputs: diff --git a/.github/workflows/test_all.yml b/.github/workflows/test_all.yml index 868bfc5..8875a98 100644 --- a/.github/workflows/test_all.yml +++ b/.github/workflows/test_all.yml @@ -1,10 +1,10 @@ name: Test apps on given SDK ref on: - schedule: - - cron: '32 5 * * 1' + # schedule: + # - cron: '32 5 * * 1' - pull_request: + # pull_request: workflow_dispatch: inputs: diff --git a/.gitignore b/.gitignore index 68bc17f..deec87f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +*~ # PyInstaller # Usually these files are written by a python script from a template diff --git a/script.py b/script.py new file mode 100644 index 0000000..44c6591 --- /dev/null +++ b/script.py @@ -0,0 +1,69 @@ +import logging +from argparse import ArgumentParser +from collections import defaultdict +from ledgered.github import Condition, GitHubLedgerHQ, GitHubApps, NoManifestException + +LOGGER_FORMAT = "[%(asctime)s][%(levelname)s] %(name)s - %(message)s" +logging.root.handlers.clear() +handler = logging.StreamHandler() +handler.setFormatter(logging.Formatter(LOGGER_FORMAT)) +logging.root.addHandler(handler) +logging.root.setLevel(logging.INFO) + +devices = ["nanos", "nanos+", "nanox", "flex", "stax"] + + +def arg_parse(): + parser = ArgumentParser() + parser.add_argument("-d", "--devices", nargs="+", required=True, + help="Devices to filter on. Accepts several successive values (seperated with space). " + "Valid values are 'nanos', 'nanosp', 'nanos+', 'nanox', 'stax', 'flex', 'all'.") + parser.add_argument("-t", "--github_token", required=False, default="", type=str, + help="A GitHub token to avoid GH API limitation") + + args = parser.parse_args() + + selected_devices = list() + for d in args.devices: + if d.lower() == "nanosp": + d = "nanos+" + if d.lower() in devices: + selected_devices.append(d) + continue + if d.lower() == "all": + selected_devices = devices + break + logging.warning(f"Unkown device target '{d}'. Ignoring.") + args.devices = selected_devices + + return args + + +def main(): + args = arg_parse() + + selected_devices = set(args.devices) + + logging.info("Fetching application repositories from GitHub") + if args.github_token: + gh = GitHubLedgerHQ(args.github_token) + else: + gh = GitHubLedgerHQ() + apps = gh.apps.filter(archived=Condition.WITHOUT, private=Condition.WITHOUT) + + selected_apps = defaultdict(list) + for app in apps: + logging.info(f"Managing app '{app.name}'") + try: + compatible_devices = set(app.manifest.app.devices) + except NoManifestException: + logging.warning(f"Application '{app.name}' has no manifest! Ignoring.") + + for device in selected_devices.intersection(compatible_devices): + selected_apps[device].append(app.name) + + print(dict(selected_apps)) + + +if __name__ == "__main__": + main()