diff --git a/.github/workflows/_get_app_metadata.yml b/.github/workflows/_get_app_metadata.yml new file mode 100644 index 000000000..c37a42ae9 --- /dev/null +++ b/.github/workflows/_get_app_metadata.yml @@ -0,0 +1,125 @@ +name: Output metadata on the application, inferred from the local 'ledger_app.toml' manifest or not + +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 + 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", "flex"]). + 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-22.04 + + steps: + - name: Clone app repository + uses: actions/checkout@v4 + with: + repository: ${{ inputs.app_repository }} + ref: ${{ inputs.app_branch_name }} + submodules: recursive + + - 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 + >&2 echo "/!\ No $APP_MANIFEST manifest detected!" + >&2 echo "This file is mandatory, please add it on your repository" + >&2 echo "Documentation here: /~https://github.com/LedgerHQ/ledgered/blob/master/doc/utils/manifest.md" + exit 1 + fi + + # 'ledger_app.toml' exists + echo "Manifest detected." + # checking the manifest with the repo + ledger-manifest --check . "$APP_MANIFEST" + + # build directory + echo "build_directory=$(ledger-manifest --output-build-directory "$APP_MANIFEST")" >> "$GITHUB_OUTPUT" + + # get device list as a single line json formatted value + compatible_devices="$(ledger-manifest --output-devices "$APP_MANIFEST" -j | jq -rc '.devices')" + if [[ '${{ inputs.compatible_devices }}' != 'None' ]]; + then + # in case classic manifest with devices, the input takes precedence on it + compatible_devices='${{ inputs.compatible_devices }}' + fi + echo "compatible_devices=${compatible_devices}" | sed 's/+/p/' >> "$GITHUB_OUTPUT" + + # pytest_directory (if any) + set +e # when [tests.pytest_directory] is not set, ledger-manifest fails. We don't want that + if temp="$(ledger-manifest --output-tests-pytest-directory "$APP_MANIFEST")"; + then + pytest_directory="${temp}" + fi + set -e + echo "pytest_directory=${pytest_directory}" >> "$GITHUB_OUTPUT" + + # SDK language + if [[ "$(ledger-manifest --output-sdk "$APP_MANIFEST")" == "rust" ]]; + then + echo "is_rust=true" >> "$GITHUB_OUTPUT" + else + echo "is_rust=false" >> "$GITHUB_OUTPUT" + fi + + 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 }}