Skip to content

Commit 25162d3

Browse files
wip
1 parent ebd5ece commit 25162d3

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Output metadata on the application, inferred from the local 'ledger_app.toml' manifest or not
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
app_repository:
7+
description: 'The GIT repository to build (defaults to `github.repository`)'
8+
required: false
9+
default: ${{ github.repository }}
10+
type: string
11+
app_branch_name:
12+
description: 'The GIT branch to build (defaults to `github.ref`)'
13+
required: false
14+
default: ${{ github.ref }}
15+
type: string
16+
compatible_devices:
17+
description: |
18+
The list of device(s) the CI will run on.
19+
20+
Defaults to the full list of device(s) supported by the application as configured in the
21+
'ledger_app.toml' manifest.
22+
If the manifest is missing, defaults to ALL (["nanos", "nanox", "nanosp", "stax", "flex"]).
23+
required: false
24+
default: 'None'
25+
type: string
26+
pytest_directory:
27+
description: |
28+
The directory where the Python tests are stored (a `conftest.py` file is expected there).
29+
30+
If the application is configured with a 'ledger_app.toml' manifest at its root with a
31+
'tests.pytest_directory' field, this parameter is ignored.
32+
required: false
33+
default: 'None'
34+
type: string
35+
outputs:
36+
is_rust:
37+
description: Returns "true" if the app is using Rust SDK, else returns "false"
38+
value: ${{ jobs.fetch_metadata.outputs.is_rust }}
39+
build_directory:
40+
description: |
41+
Returns the relative 'build_directory' path, i.e the repository directory where can be
42+
found either the root 'Makefile' of a C app, or the Cargo.toml of a Rust app.
43+
value: ${{ jobs.fetch_metadata.outputs.build_directory }}
44+
compatible_devices:
45+
description:
46+
The list of device(s) supported by the application.
47+
value: ${{ jobs.fetch_metadata.outputs.compatible_devices }}
48+
pytest_directory:
49+
description: |
50+
The directory where the Python tests are stored (a `conftest.py` file is expected there).
51+
value: ${{ jobs.fetch_metadata.outputs.pytest_directory }}
52+
53+
env:
54+
APP_MANIFEST: "ledger_app.toml"
55+
56+
jobs:
57+
fetch_metadata:
58+
name: Retrieve application metadata
59+
runs-on: ubuntu-22.04
60+
61+
steps:
62+
- name: Clone app repository
63+
uses: actions/checkout@v4
64+
with:
65+
repository: ${{ inputs.app_repository }}
66+
ref: ${{ inputs.app_branch_name }}
67+
submodules: recursive
68+
69+
- name: Install dependencies
70+
run: pip install ledgered
71+
72+
- name: Gather application metadata, from inputs or 'ledger_app.toml'
73+
id: fetch_metadata
74+
run: |
75+
pytest_directory='${{ inputs.pytest_directory }}'
76+
if [[ ! -f "$APP_MANIFEST" ]];
77+
then
78+
>&2 echo "/!\ No $APP_MANIFEST manifest detected!"
79+
>&2 echo "This file is mandatory, please add it on your repository"
80+
>&2 echo "Documentation here: https://github.com/LedgerHQ/ledgered/blob/master/doc/utils/manifest.md"
81+
exit 1
82+
fi
83+
84+
# 'ledger_app.toml' exists
85+
echo "Manifest detected."
86+
# checking the manifest with the repo
87+
ledger-manifest --check . "$APP_MANIFEST"
88+
89+
# build directory
90+
echo "build_directory=$(ledger-manifest --output-build-directory "$APP_MANIFEST")" >> "$GITHUB_OUTPUT"
91+
92+
# get device list as a single line json formatted value
93+
compatible_devices="$(ledger-manifest --output-devices "$APP_MANIFEST" -j | jq -rc '.devices')"
94+
if [[ '${{ inputs.compatible_devices }}' != 'None' ]];
95+
then
96+
# in case classic manifest with devices, the input takes precedence on it
97+
compatible_devices='${{ inputs.compatible_devices }}'
98+
fi
99+
echo "compatible_devices=${compatible_devices}" | sed 's/+/p/' >> "$GITHUB_OUTPUT"
100+
101+
# pytest_directory (if any)
102+
set +e # when [tests.pytest_directory] is not set, ledger-manifest fails. We don't want that
103+
if temp="$(ledger-manifest --output-tests-pytest-directory "$APP_MANIFEST")";
104+
then
105+
pytest_directory="${temp}"
106+
fi
107+
set -e
108+
echo "pytest_directory=${pytest_directory}" >> "$GITHUB_OUTPUT"
109+
110+
# SDK language
111+
if [[ "$(ledger-manifest --output-sdk "$APP_MANIFEST")" == "rust" ]];
112+
then
113+
echo "is_rust=true" >> "$GITHUB_OUTPUT"
114+
else
115+
echo "is_rust=false" >> "$GITHUB_OUTPUT"
116+
fi
117+
118+
echo "Inferred metadata:"
119+
cat "$GITHUB_OUTPUT"
120+
121+
outputs:
122+
is_rust: ${{ steps.fetch_metadata.outputs.is_rust }}
123+
compatible_devices: ${{ steps.fetch_metadata.outputs.compatible_devices }}
124+
build_directory: ${{ steps.fetch_metadata.outputs.build_directory }}
125+
pytest_directory: ${{ steps.fetch_metadata.outputs.pytest_directory }}

0 commit comments

Comments
 (0)