Skip to content

Commit

Permalink
[draft] 2nd version, leveraging the reusable builder workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Jan 15, 2025
1 parent 44c0aeb commit 0bdf843
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 97 deletions.
99 changes: 9 additions & 90 deletions .github/workflows/build_for_sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,100 +20,19 @@ jobs:
- name: Define the list of application to build by device
id: process_devices
run: |
devices=$(python script.py -d all -t ${{ secrets.GITHUB_TOKEN }})
devices=$(python script.py -l 10 -d all -t ${{ secrets.GITHUB_TOKEN }})
echo "app_url_by_device=$devices" >> $GITHUB_OUTPUT
run_builds_nanos:
name: Building NanoS applications
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:
name: Building NanoS+ applications
runs-on: ubuntu-latest
needs: define_matrix
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
build_applications:
name: Build all selected applications using the reusable workflow
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
app_name: ${{ fromJSON(needs.define_matrix.outputs.app_url_by_device) }}

run_builds_nanox:
name: Building NanoX applications
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:
name: Building Flex applications
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_stax:
name: Building Stax applications
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
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
app_repository: matrix.app.repository_url
run_for_devices: matrix.app.devices
upload_app_binaries_artifact: "compiled_app_binaries"
32 changes: 25 additions & 7 deletions script.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json
import logging
from argparse import ArgumentParser
from collections import defaultdict
from ledgered.github import Condition, GitHubLedgerHQ, GitHubApps, NoManifestException
from dataclasses import asdict, dataclass
from ledgered.github import AppRepository, Condition, GitHubLedgerHQ, GitHubApps, \
NoManifestException

LOGGER_FORMAT = "[%(asctime)s][%(levelname)s] %(name)s - %(message)s"
logging.root.handlers.clear()
Expand All @@ -13,11 +16,26 @@
devices = ["nanos", "nanos+", "nanox", "flex", "stax"]


@dataclass
class AppInfo:
name: str
repository_url: str
devices: list[str]

def __init__(self, app: AppRepository, filtered_devices: set[str]):
compatible_devices = app.manifest.app.devices
self.name = app.name
self.repository_url = app.url
self.devices = list(compatible_devices.intersection(filtered_devices))


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("-l", "--limit", required=False, default=0, type=int,
help="Limit the number of application to parse (testing purpose for instance)")
parser.add_argument("-t", "--github_token", required=False, default="", type=str,
help="A GitHub token to avoid GH API limitation")

Expand Down Expand Up @@ -51,18 +69,18 @@ def main():
gh = GitHubLedgerHQ()
apps = gh.apps.filter(archived=Condition.WITHOUT, private=Condition.WITHOUT)

selected_apps = defaultdict(list)
for app in apps:
selected_apps = list()
for index, app in enumerate(apps):
logging.info(f"Managing app '{app.name}'")
try:
compatible_devices = set(app.manifest.app.devices)
selected_apps.append(asdict(AppInfo(app, selected_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)
if args.limit != 0 and index > args.limit:
break

print(dict(selected_apps))
print(json.dumps(selected_apps))


if __name__ == "__main__":
Expand Down

0 comments on commit 0bdf843

Please sign in to comment.