diff --git a/.github/workflows/on_target.yml b/.github/workflows/on_target.yml index 15683a4c..6517cc76 100644 --- a/.github/workflows/on_target.yml +++ b/.github/workflows/on_target.yml @@ -8,10 +8,6 @@ on: required: true type: boolean description: Build the firmware before running tests - runid: - required: false - type: number - description: The run ID of the build job to download artifacts from schedule: - cron: "0 0 * * *" @@ -21,7 +17,7 @@ on: jobs: build: - if: ${{ github.event.inputs.build == true }} + if: ${{ github.event.inputs.build == ''}} uses: ./.github/workflows/build.yml secrets: inherit with: @@ -46,12 +42,18 @@ jobs: path: thingy91x-oob - name: Download artifact + if: ${{ github.event.inputs.build == '' }} uses: actions/download-artifact@v4 with: name: firmware path: thingy91x-oob/tests/on_target/artifacts - run-id: ${{ github.event.workflow_run.id }} - github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Download old artifact + if: ${{ github.event.inputs.build != '' }} + run: | + echo ${{ github.event.inputs.build }} + python3 thingy91x-oob/tests/on_target/utils/download_artifacts.py \ + ${{ secrets.GITHUB_TOKEN }} - name: Set version shell: bash diff --git a/tests/on_target/tests/conftest.py b/tests/on_target/tests/conftest.py index 8c95c2c5..c2348f8c 100644 --- a/tests/on_target/tests/conftest.py +++ b/tests/on_target/tests/conftest.py @@ -69,8 +69,12 @@ def t91x_board(): @pytest.fixture(scope="module") def hex_file(request): - return request.config.getoption("--firmware-hex") - + if os.path.exists(request.config.getoption("--firmware-hex")): + return request.config.getoption("--firmware-hex") + artifacts = os.listdir("artifacts") + hex_files = [os.path.join("artifacts", file) for file in artifacts if file.endswith("-thingy91x-debug-app.hex")] + logger.warning("Not using latest firmware hex file") + return hex_files[0] # Add support for input arguments def pytest_addoption(parser): diff --git a/tests/on_target/utils/download_artifacts.py b/tests/on_target/utils/download_artifacts.py new file mode 100644 index 00000000..ede28ec8 --- /dev/null +++ b/tests/on_target/utils/download_artifacts.py @@ -0,0 +1,41 @@ +########################################################################################## +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +########################################################################################## + +import requests +import argparse +import io +import zipfile + +p = argparse.ArgumentParser() +p.add_argument("token", help="GitHub token") +p.add_argument( + "--path", + help="Folder to store artifact", + default="thingy91x-oob/tests/on_target/artifacts", +) + +args = p.parse_args() + +headers = { + "X-GitHub-Api-Version": "2022-11-28", + "Authorization": f"Bearer {args.token}", + "Accept": "application/vnd.github+json", +} + +params = {"per_page": 1, "name": "firmware"} + +url = "https://api.github.com/repos/hello-nrfcloud/firmware/actions/artifacts" + +r = requests.get(url, headers=headers, params=params) +r.raise_for_status() + +download_link = r.json()["artifacts"][0]["archive_download_url"] +print(f"Using artifact from: {download_link}") + +r = requests.get(download_link, headers=headers) +r.raise_for_status() + +with zipfile.ZipFile(io.BytesIO(r.content)) as z: + z.extractall(args.path)