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 9af2989
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 100 deletions.
106 changes: 13 additions & 93 deletions .github/workflows/build_for_sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Generate applications list for each device according to manifests
runs-on: ubuntu-latest
outputs:
app_url_by_device: ${{ steps.process_devices.outputs.app_url_by_device }}
apps_config: ${{ steps.process_devices.outputs.apps_config }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies
Expand All @@ -20,100 +20,20 @@ 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 }})
echo "app_url_by_device=$devices" >> $GITHUB_OUTPUT
devices=$(python script.py -l 10 -d all -t ${{ secrets.GITHUB_TOKEN }})
# devices='[{"devices": ["stax", "nanos+", "nanos", "nanox"], "name": "app-u2f", "repository": "LedgerHQ/app-u2f"}, {"devices": ["flex", "nanos+", "nanos", "stax", "nanox"], "name": "app-bitcoin", "repository": "LedgerHQ/app-bitcoin"}, {"devices": ["flex", "nanos+", "nanos", "stax", "nanox"], "name": "app-ethereum", "repository": "LedgerHQ/app-ethereum"}, {"devices": ["stax", "nanos+", "nanos", "nanox"], "name": "app-ssh-agent", "repository": "LedgerHQ/app-ssh-agent"}, {"devices": ["stax", "nanos+", "nanos", "nanox"], "name": "app-passwords", "repository": "LedgerHQ/app-passwords"}, {"devices": ["flex", "nanos+", "nanos", "stax", "nanox"], "name": "app-openpgp", "repository": "LedgerHQ/app-openpgp"}, {"devices": ["nanos+", "nanos", "nanox"], "name": "app-windows-hello", "repository": "LedgerHQ/app-windows-hello"}, {"devices": ["flex", "nanos+", "nanos", "stax", "nanox"], "name": "app-xrp", "repository": "LedgerHQ/app-xrp"}, {"devices": ["flex", "nanos+", "nanos", "stax", "nanox"], "name": "app-monero", "repository": "LedgerHQ/app-monero"}, {"devices": ["nanos+", "nanos", "nanox"], "name": "app-ark", "repository": "LedgerHQ/app-ark"}, {"devices": ["flex", "nanos+", "nanos", "stax", "nanox"], "name": "app-neo", "repository": "LedgerHQ/app-neo"}, {"devices": ["flex", "nanos+", "nanos", "stax", "nanox"], "name": "app-stellar", "repository": "LedgerHQ/app-stellar"}]'
echo "apps_config=$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
build_applications:
name: Build all selected applications using the reusable workflow
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:
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
app: ${{ fromJSON(needs.define_matrix.outputs.apps_config) }}
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
app_repository: ${{ matrix.app.repository }}
run_for_devices: ${{ toJSON(matrix.app.devices) }}
upload_app_binaries_artifact: "compiled_app_binaries"
app_branch_name: develop
31 changes: 24 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,25 @@
devices = ["nanos", "nanos+", "nanox", "flex", "stax"]


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

def __init__(self, app: AppRepository, filtered_devices: set[str]):
compatible_devices = app.manifest.app.devices
self.devices = list(compatible_devices.intersection(filtered_devices))
self.name = app.name
self.repository = f"LedgerHQ/{app.name}"

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 +68,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 9af2989

Please sign in to comment.