Skip to content

Commit f60d073

Browse files
authored
Merge pull request #128 from LedgerHQ/y333/manage_several_pytest_directories
Y333/manage several pytest directories
2 parents 136f57c + 3450f0a commit f60d073

File tree

4 files changed

+149
-34
lines changed

4 files changed

+149
-34
lines changed

.github/workflows/_get_app_metadata.yml

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ on:
2727
required: false
2828
default: 'None'
2929
type: string
30-
pytest_directory:
31-
description: |
32-
The directory where the Python tests are stored (a `conftest.py` file is expected there).
33-
34-
If the application is configured with a 'ledger_app.toml' manifest at its root with a
35-
'tests.pytest_directory' field, this parameter is ignored.
30+
flags:
31+
description: "Additional compilation flags (default to none)"
3632
required: false
37-
default: 'None'
33+
default: ''
34+
type: string
35+
use_case:
36+
description: "The use case to build the application for. Ignored if 'flags' is set"
37+
required: false
38+
default: ''
3839
type: string
3940
outputs:
4041
is_rust:
@@ -49,10 +50,10 @@ on:
4950
description:
5051
The list of device(s) supported by the application.
5152
value: ${{ jobs.fetch_metadata.outputs.compatible_devices }}
52-
pytest_directory:
53+
flags:
5354
description: |
54-
The directory where the Python tests are stored (a `conftest.py` file is expected there).
55-
value: ${{ jobs.fetch_metadata.outputs.pytest_directory }}
55+
The additional compilation flags to use when building the application.
56+
value: ${{ jobs.fetch_metadata.outputs.flags }}
5657

5758
env:
5859
APP_MANIFEST: "ledger_app.toml"
@@ -72,7 +73,8 @@ jobs:
7273
token: ${{ secrets.token && secrets.token || github.token }}
7374

7475
- name: Install dependencies
75-
run: pip install ledgered
76+
run: |
77+
pip install ledgered
7678
7779
- name: Gather application metadata, from inputs or 'ledger_app.toml'
7880
id: fetch_metadata
@@ -103,15 +105,6 @@ jobs:
103105
fi
104106
echo "compatible_devices=${compatible_devices}" | sed 's/+/p/' >> "$GITHUB_OUTPUT"
105107
106-
# pytest_directory (if any)
107-
set +e # when [tests.pytest_directory] is not set, ledger-manifest fails. We don't want that
108-
if temp="$(ledger-manifest --output-tests-pytest-directory "$APP_MANIFEST")";
109-
then
110-
pytest_directory="${temp}"
111-
fi
112-
set -e
113-
echo "pytest_directory=${pytest_directory}" >> "$GITHUB_OUTPUT"
114-
115108
# SDK language
116109
if [ "$(ledger-manifest --output-sdk "$APP_MANIFEST")" = "rust" ];
117110
then
@@ -120,11 +113,23 @@ jobs:
120113
echo "is_rust=false" >> "$GITHUB_OUTPUT"
121114
fi
122115
116+
# Compilation flags
117+
if [ -n "${{ inputs.flags }}" ]; then
118+
echo "flags=${{ inputs.flags }}" >> "$GITHUB_OUTPUT"
119+
elif [ -n "${{ inputs.use_case }}" ]; then
120+
# if a use case is provided, we use the one from the manifest
121+
use_case=${{ inputs.use_case }}
122+
echo "use_case is set to '${use_case}'"
123+
echo "flags=$(ledger-manifest "$APP_MANIFEST" --output-use-cases ${use_case})" >> "$GITHUB_OUTPUT"
124+
else
125+
echo "flags=" >> "$GITHUB_OUTPUT"
126+
fi
127+
123128
echo "Inferred metadata:"
124129
cat "$GITHUB_OUTPUT"
125130
126131
outputs:
127132
is_rust: ${{ steps.fetch_metadata.outputs.is_rust }}
128133
compatible_devices: ${{ steps.fetch_metadata.outputs.compatible_devices }}
129134
build_directory: ${{ steps.fetch_metadata.outputs.build_directory }}
130-
pytest_directory: ${{ steps.fetch_metadata.outputs.pytest_directory }}
135+
flags: ${{ steps.fetch_metadata.outputs.flags }}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Output metadata on the application, inferred from the local 'ledger_app.toml' manifest or not
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
token:
7+
description: 'A token passed from the caller workflow'
8+
required: false
9+
inputs:
10+
app_repository:
11+
description: 'The GIT repository to build (defaults to `github.repository`)'
12+
required: false
13+
default: ${{ github.repository }}
14+
type: string
15+
app_branch_name:
16+
description: 'The GIT branch to build (defaults to `github.ref`)'
17+
required: false
18+
default: ${{ github.ref }}
19+
type: string
20+
pytest_directory:
21+
description: |
22+
The directory where the Python tests are stored (a `conftest.py` file is expected inside).
23+
required: false
24+
default: 'None'
25+
type: string
26+
outputs:
27+
pytest_directory:
28+
description: |
29+
The directory where the Python tests are stored (a `conftest.py` file is expected inside).
30+
value: ${{ jobs.fetch_metadata.outputs.pytest_directory }}
31+
32+
env:
33+
APP_MANIFEST: "ledger_app.toml"
34+
35+
jobs:
36+
fetch_metadata:
37+
name: Retrieve tests metadata
38+
runs-on: ubuntu-22.04
39+
40+
steps:
41+
- name: Clone app repository
42+
uses: actions/checkout@v4
43+
with:
44+
repository: ${{ inputs.app_repository }}
45+
ref: ${{ inputs.app_branch_name }}
46+
submodules: recursive
47+
token: ${{ secrets.token && secrets.token || github.token }}
48+
49+
- name: Install dependencies
50+
run: |
51+
pip install ledgered
52+
53+
- name: Gather application metadata, from inputs or 'ledger_app.toml'
54+
id: fetch_metadata
55+
run: |
56+
if [ ! -f "$APP_MANIFEST" ];
57+
then
58+
>&2 echo "/!\ No $APP_MANIFEST manifest detected!"
59+
>&2 echo "This file is mandatory, please add it on your repository"
60+
>&2 echo "Documentation here: https://github.com/LedgerHQ/ledgered/blob/master/doc/utils/manifest.md"
61+
exit 1
62+
fi
63+
64+
# 'ledger_app.toml' exists
65+
echo "Manifest detected."
66+
# checking the manifest with the repo
67+
ledger-manifest --check . "$APP_MANIFEST"
68+
69+
set +e
70+
temp="$(ledger-manifest --output-tests-pytest-directory "$APP_MANIFEST")"
71+
status=$?
72+
set -e
73+
# catch the error if the manifest does not contain the pytest_directory
74+
if [ $status -ne 0 ]; then
75+
>&2 echo "This is a v2 manifest"
76+
pytest_directory=""
77+
temp="$(ledger-manifest --output-pytest-directories -j -- "$APP_MANIFEST")"
78+
for dir in $(echo "$temp" | jq -r '.pytest_directories[]'); do
79+
echo "Found in Manifest pytest directory: $dir"
80+
echo "Searching for '${{ inputs.pytest_directory }}'"
81+
# if the dir is the same as input.pytest_directory, we keep it
82+
if [ "$dir" = "${{ inputs.pytest_directory }}" ]; then
83+
pytest_directory="$dir"
84+
break
85+
fi
86+
done
87+
else
88+
pytest_directory="${temp}"
89+
fi
90+
echo "pytest_directory=${pytest_directory}" >> "$GITHUB_OUTPUT"
91+
92+
echo "Inferred test metadata:"
93+
cat "$GITHUB_OUTPUT"
94+
95+
outputs:
96+
pytest_directory: ${{ steps.fetch_metadata.outputs.pytest_directory }}

.github/workflows/reusable_build.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ on:
2222
required: false
2323
default: ''
2424
type: string
25+
use_case:
26+
description: "The use case to build the application for. Ignored if 'flags' is set"
27+
required: false
28+
default: ''
29+
type: string
2530
upload_app_binaries_artifact:
2631
description: "The name of the artifact containing the built application binary file(s) to be tested"
2732
required: false
@@ -74,6 +79,8 @@ jobs:
7479
app_repository: ${{ inputs.app_repository }}
7580
app_branch_name: ${{ inputs.app_branch_name }}
7681
compatible_devices: ${{ inputs.run_for_devices }}
82+
flags: ${{ inputs.flags }}
83+
use_case: ${{ inputs.use_case }}
7784
secrets:
7885
token: ${{ secrets.token }}
7986

@@ -127,7 +134,7 @@ jobs:
127134
ADDITIONAL_ARGS="TARGET=${{ matrix.device }}"
128135
fi
129136
echo "Compiling..."
130-
make -C ${{ needs.call_get_app_metadata.outputs.build_directory }} -j ${{ inputs.flags }} ${ADDITIONAL_ARGS} BOLOS_SDK=${BOLOS_SDK}
137+
make -C ${{ needs.call_get_app_metadata.outputs.build_directory }} -j ${{ needs.call_get_app_metadata.outputs.flags }} ${ADDITIONAL_ARGS} BOLOS_SDK=${BOLOS_SDK}
131138
echo "binary_path=${{ needs.call_get_app_metadata.outputs.build_directory }}/build/*" >> $GITHUB_OUTPUT
132139
echo "Build complete"
133140
fi

.github/workflows/reusable_ragger_tests.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,18 @@ jobs:
9494
app_repository: ${{ inputs.app_repository }}
9595
app_branch_name: ${{ inputs.app_branch_name }}
9696
compatible_devices: ${{ inputs.run_for_devices }}
97+
98+
call_get_test_metadata:
99+
name: Retrieve test metadata
100+
uses: ./.github/workflows/_get_test_metadata.yml
101+
with:
102+
app_repository: ${{ inputs.app_repository }}
103+
app_branch_name: ${{ inputs.app_branch_name }}
97104
pytest_directory: ${{ inputs.test_dir }}
98105

99106
ragger_tests:
100107
name: Functional tests with Ragger
101-
needs: call_get_app_metadata
108+
needs: [call_get_app_metadata, call_get_test_metadata]
102109
strategy:
103110
fail-fast: false
104111
matrix:
@@ -109,7 +116,7 @@ jobs:
109116
steps:
110117
- name: Check metadata
111118
run: |
112-
if [ '${{ needs.call_get_app_metadata.outputs.pytest_directory }}' = 'None' ]; then
119+
if [ '${{ needs.call_get_test_metadata.outputs.pytest_directory }}' = 'None' ]; then
113120
>&2 echo "ERROR: This workflow either needs a 'ledger_app.toml' manifest with a 'tests.pytest_directory' section, or be configured with a valid 'test_dir' parameter"
114121
exit 1
115122
fi
@@ -164,32 +171,32 @@ jobs:
164171
uses: actions/download-artifact@v4
165172
with:
166173
name: ${{ inputs.lib_binaries_artifact }}
167-
path: ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/lib_binaries/
174+
path: ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/lib_binaries/
168175

169176
- name: Display structure of downloaded files
170177
if: ${{ inputs.lib_binaries_artifact != '' }}
171-
run: ls -R ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/lib_binaries/
178+
run: ls -R ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/lib_binaries/
172179

173180
- name: Install tests dependencies
174181
run: |
175182
sudo apt-get update && sudo apt-get install -y qemu-user-static tesseract-ocr libtesseract-dev
176183
pip install -U pip packaging setuptools
177-
pip install -r "${{ needs.call_get_app_metadata.outputs.pytest_directory }}/requirements.txt"
178-
if [ -f ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/setup_script.sh ]; then
179-
./${{ needs.call_get_app_metadata.outputs.pytest_directory }}/setup_script.sh
184+
pip install -r "${{ needs.call_get_test_metadata.outputs.pytest_directory }}/requirements.txt"
185+
if [ -f ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/setup_script.sh ]; then
186+
./${{ needs.call_get_test_metadata.outputs.pytest_directory }}/setup_script.sh
180187
fi
181188
182189
- name: Clear legacy snapshots
183190
if: ${{ inputs.regenerate_snapshots == true }}
184191
run: |
185-
rm -rf ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots
192+
rm -rf ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots
186193
187194
- name: Run test
188195
env:
189196
CTEST_OUTPUT_ON_FAILURE: 1
190197
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python
191198
run: |
192-
pytest ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/ \
199+
pytest ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/ \
193200
--tb=short -v \
194201
--device ${{ matrix.device }} \
195202
-k ${{ inputs.test_filter }} \
@@ -203,14 +210,14 @@ jobs:
203210
with:
204211
# Make the artifact name unique to allow running this job in parallel
205212
name: tests_snapshots${{ inputs.test_options }}-${{ matrix.device }}
206-
path: ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots-tmp
213+
path: ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots-tmp
207214

208215
- name: Upload snapshots on success if needed
209216
if: ${{ inputs.regenerate_snapshots == true }}
210217
uses: actions/upload-artifact@v4
211218
with:
212219
name: tests_snapshots${{ inputs.test_options }}-${{ matrix.device }}
213-
path: ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots-tmp
220+
path: ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots-tmp
214221

215222
- name: Set upload flag
216223
id: upload-flag
@@ -246,4 +253,4 @@ jobs:
246253
app_repository: ${{ inputs.app_repository }}
247254
app_branch_name: ${{ inputs.app_branch_name }}
248255
snapshots_artifact_name: ${{ needs.merge_artifacts_if_needed.outputs.snapshot_artifact_name }}
249-
snapshots_directory: ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots
256+
snapshots_directory: ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots

0 commit comments

Comments
 (0)