Skip to content

Commit

Permalink
Merge branch 'release-candidate' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
hedger committed Jun 27, 2023
2 parents b3ec82a + 9c21aff commit b3a1f93
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 18 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run tests

on:
pull_request:

jobs:
run-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.11]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip .
- name: Run tests
run: |
python -m unittest
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.4.2
0.2.4.3
86 changes: 86 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import json
import subprocess
import unittest


# ufbt invokation & json status output
def ufbt_status() -> dict:
# Call "ufbt status --json" and return the parsed json
try:
status = subprocess.check_output(["ufbt", "status", "--json"])
except subprocess.CalledProcessError as e:
status = e.output
return json.loads(status)


def ufbt_exec(args):
# Call "ufbt" with the given args and return the parsed json
return subprocess.check_output(["ufbt"] + args)


# Test initial deployment
class TestInitialDeployment(unittest.TestCase):
def test_default_deployment(self):
ufbt_exec(["clean"])
status = ufbt_status()
self.assertEqual(status.get("error"), "SDK is not deployed")

ufbt_exec(["update"])
status = ufbt_status()
self.assertIsNone(status.get("error"))
self.assertEqual(status.get("target"), "f7")
self.assertEqual(status.get("mode"), "channel")
self.assertEqual(status.get("details", {}).get("channel"), "release")

def test_customized_deployment(self):
ufbt_exec(["clean"])
status = ufbt_status()
self.assertEqual(status.get("error"), "SDK is not deployed")

ufbt_exec(["update", "-t", "f18", "-c", "rc"])
status = ufbt_status()
self.assertIsNone(status.get("error"))
self.assertEqual(status.get("target"), "f18")
self.assertEqual(status.get("mode"), "channel")
self.assertEqual(status.get("details", {}).get("channel"), "rc")
self.assertIn("rc", status.get("version", ""))

def test_target_switch(self):
ufbt_exec(["clean"])
status = ufbt_status()
self.assertEqual(status.get("error"), "SDK is not deployed")

ufbt_exec(["update"])
status = ufbt_status()
self.assertEqual(status.get("target"), "f7")

ufbt_exec(["update", "-t", "f18"])
status = ufbt_status()
self.assertEqual(status.get("target"), "f18")
self.assertEqual(status.get("mode"), "channel")
self.assertEqual(status.get("details", {}).get("channel"), "release")

def test_target_mode_switches(self):
ufbt_exec(["clean"])
status = ufbt_status()
self.assertEqual(status.get("error"), "SDK is not deployed")

ufbt_exec(["update"])
status = ufbt_status()
self.assertEqual(status.get("target"), "f7")

ufbt_exec(["update", "-t", "f18"])
status = ufbt_status()
self.assertEqual(status.get("target"), "f18")
self.assertEqual(status.get("mode"), "channel")

ufbt_exec(["update", "-b", "dev"])
status = ufbt_status()
self.assertEqual(status.get("target"), "f18")
self.assertEqual(status.get("mode"), "branch")
self.assertEqual(status.get("details", {}).get("branch"), "dev")

previous_status = status
ufbt_exec(["update"])
status = ufbt_status()
self.assertEqual(previous_status, status)
20 changes: 3 additions & 17 deletions ufbt/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,25 +597,11 @@ def _add_arguments(self, parser: argparse.ArgumentParser) -> None:

def _func(self, args) -> int:
sdk_deployer = UfbtSdkDeployer(args.ufbt_home)
current_task = SdkDeployTask.from_args(args)
task_to_deploy = None

if previous_task := sdk_deployer.get_previous_task():
previous_task.update_from(current_task)
task_to_deploy = previous_task
else:
if current_task.mode:
task_to_deploy = current_task
# No previous state, use default hw target
if task_to_deploy and not task_to_deploy.hw_target:
task_to_deploy.hw_target = SdkDeployTask.DEFAULT_HW_TARGET
else:
log.warn("No previous SDK state was found, fetching latest release")
task_to_deploy = SdkDeployTask.default()
task_to_deploy = sdk_deployer.get_previous_task() or SdkDeployTask.default()
task_to_deploy.update_from(SdkDeployTask.from_args(args))

if not sdk_deployer.deploy(task_to_deploy):
return 1
return 0
return 0 if sdk_deployer.deploy(task_to_deploy) else 1


class CleanSubcommand(CliSubcommand):
Expand Down

0 comments on commit b3a1f93

Please sign in to comment.