Skip to content

Commit 4376c0c

Browse files
authored
Merge pull request #250 from LedgerHQ/y333/update_ci
Update CI
2 parents 30ceeec + 473daad commit 4376c0c

File tree

3 files changed

+187
-119
lines changed

3 files changed

+187
-119
lines changed

.github/workflows/build_all_apps.yml

Lines changed: 0 additions & 119 deletions
This file was deleted.

.github/workflows/get_rust_apps.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from ledgered.github import GitHubLedgerHQ, NoManifestException, Condition
2+
from github.GithubException import GithubException
3+
4+
import sys
5+
import json
6+
7+
if len(sys.argv) != 2:
8+
print("Usage: get_rust_apps.py <github_token>")
9+
sys.exit(1)
10+
11+
# Excluded Rust apps
12+
# app-kadena-legacy: has been replaced by app-kadena
13+
# app-pocket: does not build (Obsidians' Alamgu issue)
14+
excluded_apps = ["app-kadena-legacy", "app-pocket"]
15+
16+
# Retrieve all public apps on LedgerHQ GitHub organization
17+
token = sys.argv[1]
18+
gh = GitHubLedgerHQ(token)
19+
apps=gh.apps.filter(private=Condition.WITHOUT, archived=Condition.WITHOUT)
20+
21+
rust_apps = []
22+
exclude_apps = []
23+
# loop all apps in gh.apps
24+
for app in apps:
25+
try:
26+
manifest = app.manifest
27+
except NoManifestException as e:
28+
pass
29+
except GithubException as e:
30+
pass
31+
else:
32+
# Filter out apps that are Rust based
33+
if manifest.app.sdk == "rust":
34+
if app.name not in excluded_apps:
35+
for d in manifest.app.devices:
36+
rust_apps.append({"app-name": app.name, "device": d})
37+
38+
# save the list of (apps, device) pairs to build in a json format:
39+
with open("rust_apps.json", "w") as f:
40+
f.write(json.dumps(rust_apps))
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Build all Rust apps
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
c_sdk_branch:
7+
required: false
8+
default: ''
9+
type: string
10+
workflow_dispatch:
11+
pull_request:
12+
13+
env:
14+
C_SDK_URL: 'https://github.com/LedgerHQ/ledger-secure-sdk.git'
15+
16+
jobs:
17+
how-workflow-is-called:
18+
name: Determine how the workflow is called
19+
runs-on: ubuntu-latest
20+
outputs:
21+
repository: ${{ steps.get_repo_and_branch.outputs.repo }}
22+
branch: ${{ steps.get_repo_and_branch.outputs.branch }}
23+
steps:
24+
- name: Get repository and branch
25+
id: get_repo_and_branch
26+
run: |
27+
if [ -n "${{ inputs.c_sdk_branch }}" ]; then
28+
echo "repo=LedgerHQ/ledger-device-rust-sdk" >> $GITHUB_OUTPUT
29+
echo "branch=master" >> $GITHUB_OUTPUT
30+
else
31+
echo "repo=${{ github.repository}}" >> $GITHUB_OUTPUT
32+
echo "branch=${{ github.ref }}" >> $GITHUB_OUTPUT
33+
fi
34+
retrieve-rust-apps:
35+
name: Retrieve Rust Apps
36+
runs-on: ubuntu-latest
37+
needs: how-workflow-is-called
38+
outputs:
39+
rust_apps: ${{ steps.get_rust_apps.outputs.rust_apps }}
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
with:
44+
repository: ${{ needs.how-workflow-is-called.outputs.repository }}
45+
ref: ${{ needs.how-workflow-is-called.outputs.branch }}
46+
- name: Set up Python
47+
uses: actions/setup-python@v4
48+
with:
49+
python-version: '3.x'
50+
- name: Install ledgered
51+
run: pip install ledgered
52+
- name: Get all rust apps
53+
id: get_rust_apps
54+
run: |
55+
python .github/workflows/get_rust_apps.py ${{ secrets.GITHUB_TOKEN }}
56+
echo "rust_apps=$(cat rust_apps.json)" >> $GITHUB_OUTPUT
57+
58+
display-rust-apps:
59+
name: Display Rust Apps
60+
runs-on: ubuntu-latest
61+
needs: retrieve-rust-apps
62+
steps:
63+
- name: Display Rust Apps
64+
run: |
65+
echo "Rust apps: ${{ needs.retrieve-rust-apps.outputs.rust_apps }}"
66+
67+
test-build:
68+
name: Build for all targets
69+
needs: [retrieve-rust-apps, how-workflow-is-called]
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
app-name: ["app-boilerplate-rust"]
74+
device: ["nanos+", "nanox", "stax", "flex"]
75+
include: ${{ fromJSON(needs.retrieve-rust-apps.outputs.rust_apps) }}
76+
runs-on: ubuntu-latest
77+
container:
78+
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
79+
steps:
80+
- name: Install ledgered
81+
run: pip install ledgered
82+
- name: Clone SDK
83+
uses: actions/checkout@v4
84+
with:
85+
path: sdk
86+
repository: ${{ needs.how-workflow-is-called.outputs.repository }}
87+
ref: ${{ needs.how-workflow-is-called.outputs.branch }}
88+
- name: Clone App
89+
uses: actions/checkout@v4
90+
with:
91+
repository: LedgerHQ/${{ matrix.app-name }}
92+
submodules: true
93+
path: ${{ matrix.app-name }}
94+
- name: Patch Cargo.toml
95+
continue-on-error: false
96+
run: |
97+
cd ${{ matrix.app-name }}
98+
build_directory=$(ledger-manifest --output-build-directory ledger_app.toml)
99+
cd $build_directory
100+
workspace_root=$(cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root')
101+
cargo_toml_path="$workspace_root/Cargo.toml"
102+
103+
# Patch ledger_device_sdk
104+
echo "" >> $cargo_toml_path
105+
echo "[patch.crates-io.ledger_device_sdk]" >> $cargo_toml_path
106+
path=\"$GITHUB_WORKSPACE/sdk/ledger_device_sdk\"
107+
echo "path=$path" >> $cargo_toml_path
108+
echo "Patch added to Cargo.toml"
109+
110+
# Patch ledger_secure_sdk_sys
111+
echo "" >> $cargo_toml_path
112+
echo "[patch.crates-io.ledger_secure_sdk_sys]" >> $cargo_toml_path
113+
path=\"$GITHUB_WORKSPACE/sdk/ledger_secure_sdk_sys\"
114+
echo "path=$path" >> $cargo_toml_path
115+
echo "Patch added to Cargo.toml"
116+
117+
# Patch include_gif
118+
echo "" >> $cargo_toml_path
119+
echo "[patch.crates-io.include_gif]" >> $cargo_toml_path
120+
path=\"$GITHUB_WORKSPACE/sdk/include_gif\"
121+
echo "path=$path" >> $cargo_toml_path
122+
echo "Patch added to Cargo.toml"
123+
124+
# Print Cargo.toml
125+
echo "Cargo.toml:"
126+
cat $cargo_toml_path
127+
128+
- name: Build
129+
run: |
130+
# Clone C SDK if provided
131+
if [ -n "${{ inputs.c_sdk_branch }}" ]; then
132+
git clone $C_SDK_URL --branch ${{ inputs.c_sdk_branch }} --single-branch c_sdk
133+
echo "setting LEDGER_SDK_PATH to $(realpath c_sdk)"
134+
LEDGER_SDK_PATH=$(realpath c_sdk)
135+
else
136+
echo "using C SDK from ledger-app-builder"
137+
fi
138+
cd ${{ matrix.app-name }}
139+
build_directory=$(ledger-manifest --output-build-directory ledger_app.toml)
140+
cd $build_directory
141+
# Required as patch has a different version from what is locked in Cargo.lock
142+
cargo +$RUST_NIGHTLY update include_gif
143+
cargo +$RUST_NIGHTLY update ledger_secure_sdk_sys
144+
cargo +$RUST_NIGHTLY update ledger_device_sdk
145+
device=$(echo ${{ matrix.device }} | sed 's/+/plus/')
146+
echo "Build for "$device
147+
cargo ledger build $device

0 commit comments

Comments
 (0)