forked from LedgerHQ/ledger-app-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (131 loc) · 5.86 KB
/
reusable_build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Build the application for all devices and upload the artifact
on:
workflow_call:
inputs:
app_repository:
description: 'The GIT repository to build (defaults to `github.repository`)'
required: false
default: ${{ github.repository }}
type: string
app_branch_name:
description: 'The GIT branch to build (defaults to `github.ref`)'
required: false
default: ${{ github.ref }}
type: string
flags:
description: "Additional compilation flags (default to none)"
required: false
default: ''
type: string
upload_app_binaries_artifact:
description: "The name of the artifact containing the built application binary file(s) to be tested"
required: false
default: ''
type: string
upload_as_lib_artifact:
description: "If non-empty, prefixes the built application binary file(s) with this string (default to none)"
required: false
default: ''
type: string
run_for_devices:
description: |
The list of device(s) on which the CI will run.
Defaults to the full list of device(s) supported by the application as configured in the
'ledger_app.toml' manifest.
If the manifest is missing, defaults to ALL (["nanos", "nanox", "nanosp", "stax", "flex"]).
required: false
default: 'None'
type: string
builder:
description: "The docker image to build the application in (defaults to ledger-app-builder-lite)"
required: false
default: 'ledger-app-builder-lite'
type: string
builder_tag:
description: "The tag of the docker image to build the application in (defaults to latest)"
required: false
default: 'latest'
type: string
jobs:
call_get_app_metadata:
# This job digests inputs and repository metadata provided by the `ledger_app.toml` manifest
# file, in order to output relevant directories, compatible devices, and other variables needed
# by following jobs.
name: Retrieve application metadata
uses: ./.github/workflows/_get_app_metadata.yml
with:
app_repository: ${{ inputs.app_repository }}
app_branch_name: ${{ inputs.app_branch_name }}
compatible_devices: ${{ inputs.run_for_devices }}
build:
name: Build application for NanoS, X, S+, and Stax
needs: call_get_app_metadata
strategy:
fail-fast: false
matrix:
device: ${{ fromJSON(needs.call_get_app_metadata.outputs.compatible_devices) }}
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/${{ inputs.builder }}:${{ inputs.builder_tag }}
steps:
- name: Clone
uses: actions/checkout@v4
with:
repository: ${{ inputs.app_repository }}
ref: ${{ inputs.app_branch_name }}
submodules: recursive
- name: Build application
id: "build"
shell: bash
run: |
if [[ "${{ needs.call_get_app_metadata.outputs.is_rust }}" == "true" ]];
then
BUILD_DEVICE_NAME="$(echo ${{ matrix.device }} | sed 's/nanosp/nanosplus/')" && \
cd ${{ needs.call_get_app_metadata.outputs.build_directory }} && \
cargo +$RUST_NIGHTLY update include_gif && \
cargo +$RUST_NIGHTLY update ledger_secure_sdk_sys && \
cargo +$RUST_NIGHTLY update ledger_device_sdk && \
cargo ledger build ${BUILD_DEVICE_NAME} && \
echo "binary_path=${{ needs.call_get_app_metadata.outputs.build_directory }}/target/*" >> $GITHUB_OUTPUT && \
echo "Build complete"
else
eval "BOLOS_SDK=\$$(echo ${{ matrix.device }} | tr [:lower:] [:upper:])_SDK" && \
echo "BOLOS_SDK value will be: ${BOLOS_SDK}" && \
make -C ${{ needs.call_get_app_metadata.outputs.build_directory }} -j ${{ inputs.flags }} BOLOS_SDK=${BOLOS_SDK} && \
echo "binary_path=${{ needs.call_get_app_metadata.outputs.build_directory }}/build/*" >> $GITHUB_OUTPUT
echo "Build complete"
fi
- name: Remove build artifacts before upload
run: |
if [[ "${{ needs.call_get_app_metadata.outputs.is_rust }}" == "true" ]];
then
find ${{ needs.call_get_app_metadata.outputs.build_directory }}/target -mindepth 3 -maxdepth 3 -type d -exec rm -rf {} +
else
find ${{ needs.call_get_app_metadata.outputs.build_directory }}/build/ -mindepth 2 -maxdepth 2 -type d ! -name 'bin' -exec rm -r {} +
fi
- name: Prepare to upload as lib
if: ${{ inputs.upload_as_lib_artifact != '' }}
shell: bash
run: |
DEVICE_NAME="$(echo ${{ matrix.device }} | tr nanosp nanos2)" && \
find ${{ needs.call_get_app_metadata.outputs.build_directory }}/build/${DEVICE_NAME}/ -type f -name 'app.elf' -exec mv {} ${{ inputs.upload_as_lib_artifact }}_${DEVICE_NAME}.elf \; && \
rm -r ${{ needs.call_get_app_metadata.outputs.build_directory }}/build/* && \
mv ${{ inputs.upload_as_lib_artifact }}_${DEVICE_NAME}.elf ${{ needs.call_get_app_metadata.outputs.build_directory }}/build/
- name: Upload app binary
if: ${{ inputs.upload_app_binaries_artifact != '' }}
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.upload_app_binaries_artifact }}-${{ matrix.device }}
path: ${{ steps.build.outputs.binary_path }}
if-no-files-found: error
merge_artifacts:
name: Merge build artifacts
needs: build
runs-on: ubuntu-latest
if: ${{ inputs.upload_app_binaries_artifact != '' }}
steps:
- uses: actions/upload-artifact/merge@v4
with:
name: ${{ inputs.upload_app_binaries_artifact }}
pattern: ${{ inputs.upload_app_binaries_artifact }}-*
delete-merged: true