-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from LedgerHQ/lp/manifest
Implementing #41
- Loading branch information
Showing
5 changed files
with
233 additions
and
104 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
name: Output metadata on the application, inferred from the local 'ledger_app.toml' manifest or not | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
relative_app_directory: | ||
description: | | ||
The relative path in the repository where the application is built from (defaults to "."). | ||
If the application is configured with a 'ledger_app.toml' manifest at its root, this | ||
parameter is ignored. | ||
required: false | ||
default: . | ||
type: string | ||
compatible_devices: | ||
description: | | ||
The list of device(s) the CI will run on. | ||
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"]). | ||
required: false | ||
default: 'None' | ||
type: string | ||
pytest_directory: | ||
description: | | ||
The directory where the Python tests are stored (a `conftest.py` file is expected there). | ||
If the application is configured with a 'ledger_app.toml' manifest at its root with a | ||
'tests.pytest_directory' field, this parameter is ignored. | ||
required: false | ||
default: 'None' | ||
type: string | ||
outputs: | ||
is_rust: | ||
description: Returns "true" if the app is using Rust SDK, else returns "false" | ||
value: ${{ jobs.fetch_metadata.outputs.is_rust }} | ||
build_directory: | ||
description: | | ||
Returns the relative 'build_directory' path, i.e the repository directory where can be | ||
found either the root 'Makefile' of a C app, or the Cargo.toml of a Rust app. | ||
value: ${{ jobs.fetch_metadata.outputs.build_directory }} | ||
compatible_devices: | ||
description: | ||
The list of device(s) supported by the application. | ||
value: ${{ jobs.fetch_metadata.outputs.compatible_devices }} | ||
pytest_directory: | ||
description: | | ||
The directory where the Python tests are stored (a `conftest.py` file is expected there). | ||
value: ${{ jobs.fetch_metadata.outputs.pytest_directory }} | ||
|
||
env: | ||
APP_MANIFEST: "ledger_app.toml" | ||
|
||
jobs: | ||
fetch_metadata: | ||
name: Retrieve application metadata | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Clone app repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies | ||
run: pip install ledgered | ||
|
||
- name: Gather application metadata, from inputs or 'ledger_app.toml' | ||
id: fetch_metadata | ||
run: | | ||
pytest_directory='${{ inputs.pytest_directory }}'; | ||
if [[ -f "$APP_MANIFEST" ]]; | ||
then | ||
# 'ledger_app.toml' exists | ||
if grep -q 'rust-app' "$APP_MANIFEST"; | ||
then | ||
# legacy manifest -> Rust application | ||
echo "Legacy manifest detected. Please update your manifest to the newest version"; | ||
# checking the manifest with the repo | ||
ledger-manifest --legacy --check . "$APP_MANIFEST"; | ||
echo "build_directory=$(ledger-manifest --legacy --output-build-directory "$APP_MANIFEST")" >> "$GITHUB_OUTPUT"; | ||
compatible_devices='${{ inputs.compatible_devices }}'; | ||
echo "is_rust=true" >> "$GITHUB_OUTPUT"; | ||
else | ||
# classic manifest -> can be either C or Rust | ||
echo "Manifest detected."; | ||
# checking the manifest with the repo | ||
ledger-manifest --check . "$APP_MANIFEST"; | ||
echo "build_directory=$(ledger-manifest --output-build-directory "$APP_MANIFEST")" >> "$GITHUB_OUTPUT"; | ||
compatible_devices="$(ledger-manifest --output-devices "$APP_MANIFEST")"; | ||
set +e # when [tests.pytest_directory] is not set, ledger-manifest fails | ||
if temp="$(ledger-manifest --output-pytest-directory "$APP_MANIFEST")"; | ||
then | ||
pytest_directory="${temp}"; | ||
fi | ||
set -e | ||
if [[ "$(ledger-manifest --output-sdk "$APP_MANIFEST")" == "rust" ]]; | ||
then | ||
echo "is_rust=true" >> "$GITHUB_OUTPUT"; | ||
else | ||
echo "is_rust=false" >> "$GITHUB_OUTPUT"; | ||
fi | ||
fi | ||
else | ||
# No 'ledger_app.toml' -> C application | ||
echo "No manifest detected."; | ||
echo "build_directory=${{ inputs.relative_app_directory }}" >> "$GITHUB_OUTPUT"; | ||
compatible_devices='${{ inputs.compatible_devices }}'; | ||
echo "is_rust=false" >> "$GITHUB_OUTPUT"; | ||
fi | ||
if [[ "${compatible_devices}" == 'None' ]]; | ||
then | ||
# no inputs and no classic manifest | ||
compatible_devices='["nanos", "nanosp", "nanox", "stax"]'; | ||
else | ||
if [[ '${{ inputs.compatible_devices }}' != 'None' ]]; | ||
then | ||
# in case classic manifest with devices, the input takes precedence on it | ||
compatible_devices='${{ inputs.compatible_devices }}'; | ||
fi | ||
fi | ||
echo "compatible_devices=${compatible_devices}" | sed 's/+/p/' >> "$GITHUB_OUTPUT"; | ||
echo "pytest_directory=${pytest_directory}" >> "$GITHUB_OUTPUT"; | ||
echo "Inferred metadata:" | ||
cat "$GITHUB_OUTPUT" | ||
outputs: | ||
is_rust: ${{ steps.fetch_metadata.outputs.is_rust }} | ||
compatible_devices: ${{ steps.fetch_metadata.outputs.compatible_devices }} | ||
build_directory: ${{ steps.fetch_metadata.outputs.build_directory }} | ||
pytest_directory: ${{ steps.fetch_metadata.outputs.pytest_directory }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.