Skip to content

Commit bf3f9cd

Browse files
committed
Add a new workflow _get_test_metadata that only retrieves tests metadata
1 parent 136f57c commit bf3f9cd

File tree

3 files changed

+164
-36
lines changed

3 files changed

+164
-36
lines changed

.github/workflows/_get_app_metadata.yml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ 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.
36-
required: false
37-
default: 'None'
38-
type: string
3930
outputs:
4031
is_rust:
4132
description: Returns "true" if the app is using Rust SDK, else returns "false"
@@ -49,10 +40,6 @@ on:
4940
description:
5041
The list of device(s) supported by the application.
5142
value: ${{ jobs.fetch_metadata.outputs.compatible_devices }}
52-
pytest_directory:
53-
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 }}
5643

5744
env:
5845
APP_MANIFEST: "ledger_app.toml"
@@ -71,8 +58,22 @@ jobs:
7158
submodules: recursive
7259
token: ${{ secrets.token && secrets.token || github.token }}
7360

61+
# To be suppressed when ledgered for manifest v2 is released
62+
- name: Clone ledgered repository
63+
uses: actions/checkout@v4
64+
with:
65+
repository: LedgerHQ/ledgered
66+
ref: y333/manage_pytest_swap_directory
67+
path: ledgered
68+
token: ${{ secrets.token && secrets.token || github.token }}
69+
7470
- name: Install dependencies
75-
run: pip install ledgered
71+
run: |
72+
# pip install ledgered
73+
# Install the local version of ledgered
74+
cd ledgered
75+
python -m pip install --upgrade pip
76+
python -m pip install -e .[dev]
7677
7778
- name: Gather application metadata, from inputs or 'ledger_app.toml'
7879
id: fetch_metadata
@@ -103,15 +104,6 @@ jobs:
103104
fi
104105
echo "compatible_devices=${compatible_devices}" | sed 's/+/p/' >> "$GITHUB_OUTPUT"
105106
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-
115107
# SDK language
116108
if [ "$(ledger-manifest --output-sdk "$APP_MANIFEST")" = "rust" ];
117109
then
@@ -127,4 +119,3 @@ jobs:
127119
is_rust: ${{ steps.fetch_metadata.outputs.is_rust }}
128120
compatible_devices: ${{ steps.fetch_metadata.outputs.compatible_devices }}
129121
build_directory: ${{ steps.fetch_metadata.outputs.build_directory }}
130-
pytest_directory: ${{ steps.fetch_metadata.outputs.pytest_directory }}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 there).
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 there).
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+
# To be suppressed when ledgered for manifest v2 is released
50+
- name: Clone ledgered repository
51+
uses: actions/checkout@v4
52+
with:
53+
repository: LedgerHQ/ledgered
54+
ref: y333/manage_pytest_swap_directory
55+
path: ledgered
56+
token: ${{ secrets.token && secrets.token || github.token }}
57+
58+
- name: Install dependencies
59+
run: |
60+
# pip install ledgered
61+
# Install the local version of ledgered
62+
cd ledgered
63+
python -m pip install --upgrade pip
64+
python -m pip install -e .[dev]
65+
66+
- name: Gather application metadata, from inputs or 'ledger_app.toml'
67+
id: fetch_metadata
68+
run: |
69+
if [ ! -f "$APP_MANIFEST" ];
70+
then
71+
>&2 echo "/!\ No $APP_MANIFEST manifest detected!"
72+
>&2 echo "This file is mandatory, please add it on your repository"
73+
>&2 echo "Documentation here: https://github.com/LedgerHQ/ledgered/blob/master/doc/utils/manifest.md"
74+
exit 1
75+
fi
76+
77+
# 'ledger_app.toml' exists
78+
echo "Manifest detected."
79+
# checking the manifest with the repo
80+
ledger-manifest --check . "$APP_MANIFEST"
81+
82+
set +e
83+
temp="$(ledger-manifest --output-tests-pytest-directory "$APP_MANIFEST")"
84+
status=$?
85+
set -e
86+
# catch the error if the manifest does not contain the pytest_directory
87+
if [ $status -ne 0 ]; then
88+
>&2 echo "This is a v2 manifest"
89+
pytest_directory=""
90+
temp="$(ledger-manifest --output-pytest-directories -j -- "$APP_MANIFEST")"
91+
for dir in $(echo "$temp" | jq -r '.pytest_directories[]'); do
92+
echo "Found in Manifest pytest directory: $dir"
93+
echo "Searching for '${{ inputs.pytest_directory }}'"
94+
# if the dir is the same as input.pytest_directory, we keep it
95+
if [ "$dir" = "${{ inputs.pytest_directory }}" ]; then
96+
pytest_directory="$dir"
97+
break
98+
fi
99+
done
100+
else
101+
pytest_directory="${temp}"
102+
fi
103+
echo "pytest_directory=${pytest_directory}" >> "$GITHUB_OUTPUT"
104+
105+
echo "Inferred test metadata:"
106+
cat "$GITHUB_OUTPUT"
107+
108+
outputs:
109+
pytest_directory: ${{ steps.fetch_metadata.outputs.pytest_directory }}

.github/workflows/reusable_ragger_tests.yml

Lines changed: 40 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,53 @@ 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/
179+
180+
# To be suppressed when ledgered for manifest v2 is released
181+
- name: Clone ledgered repository
182+
uses: actions/checkout@v4
183+
with:
184+
repository: LedgerHQ/ledgered
185+
ref: y333/manage_pytest_swap_directory
186+
path: ledgered
187+
fetch-tags: true
188+
fetch-depth: 0
189+
token: ${{ secrets.token && secrets.token || github.token }}
190+
191+
- name: Install local version of ledgered
192+
run: |
193+
# Install the local version of ledgered
194+
cd ledgered
195+
python -m pip install --upgrade pip
196+
pip install -e .[dev]
197+
cd ..
198+
rm -rf ledgered/tests
199+
# #######################################################
172200

173201
- name: Install tests dependencies
174202
run: |
175203
sudo apt-get update && sudo apt-get install -y qemu-user-static tesseract-ocr libtesseract-dev
176204
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
205+
pip install -r "${{ needs.call_get_test_metadata.outputs.pytest_directory }}/requirements.txt"
206+
if [ -f ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/setup_script.sh ]; then
207+
./${{ needs.call_get_test_metadata.outputs.pytest_directory }}/setup_script.sh
180208
fi
181209
182210
- name: Clear legacy snapshots
183211
if: ${{ inputs.regenerate_snapshots == true }}
184212
run: |
185-
rm -rf ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots
213+
rm -rf ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots
186214
187215
- name: Run test
188216
env:
189217
CTEST_OUTPUT_ON_FAILURE: 1
190218
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python
191219
run: |
192-
pytest ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/ \
220+
pytest ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/ \
193221
--tb=short -v \
194222
--device ${{ matrix.device }} \
195223
-k ${{ inputs.test_filter }} \
@@ -203,14 +231,14 @@ jobs:
203231
with:
204232
# Make the artifact name unique to allow running this job in parallel
205233
name: tests_snapshots${{ inputs.test_options }}-${{ matrix.device }}
206-
path: ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots-tmp
234+
path: ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots-tmp
207235

208236
- name: Upload snapshots on success if needed
209237
if: ${{ inputs.regenerate_snapshots == true }}
210238
uses: actions/upload-artifact@v4
211239
with:
212240
name: tests_snapshots${{ inputs.test_options }}-${{ matrix.device }}
213-
path: ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots-tmp
241+
path: ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots-tmp
214242

215243
- name: Set upload flag
216244
id: upload-flag
@@ -246,4 +274,4 @@ jobs:
246274
app_repository: ${{ inputs.app_repository }}
247275
app_branch_name: ${{ inputs.app_branch_name }}
248276
snapshots_artifact_name: ${{ needs.merge_artifacts_if_needed.outputs.snapshot_artifact_name }}
249-
snapshots_directory: ${{ needs.call_get_app_metadata.outputs.pytest_directory }}/snapshots
277+
snapshots_directory: ${{ needs.call_get_test_metadata.outputs.pytest_directory }}/snapshots

0 commit comments

Comments
 (0)