Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenmk committed Aug 26, 2024
1 parent e0ca9c7 commit 44a2efd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/on_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * *"
Expand All @@ -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:
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/on_target/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
41 changes: 41 additions & 0 deletions tests/on_target/utils/download_artifacts.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 44a2efd

Please sign in to comment.