Skip to content

Commit

Permalink
Preparing to ship v1 version (antmicro#49)
Browse files Browse the repository at this point in the history
Replaces `required_by` with `before` for grater clarity.
The before dependency is no longer strict. Tasks that need to be
started after the specific task do not need to exist.

Fixes `error` function override by local variable in get_file function.

Adds test that checks correctness of custom tasks

Action now catches the pexepect.EOF exception

Deletes depreacted `shared-dir` parameter (`shared-dirs` stays)
  • Loading branch information
WiktorOgrodnik authored Jun 19, 2023
1 parent 94b1ec8 commit 3ca9311
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 27 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,18 @@ jobs:
should-fail: true
commands:
- "wget example.org"
custom-task-test:
runs-on: ubuntu-latest
needs: send-to-releases
if: ${{ !failure() && !github.event.act }}
steps:
- uses: actions/checkout@v3

- name: test
uses: ./
with:
shared-dirs: tests
tasks: |
tests/python_exists_image.yml
tests/python_exists_initramfs.yml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ A task file is a YAML file with the following fields:
- `name`: the only mandatory field; it is used to resolve dependencies between tasks.
- `shell`: the name of the shell on which the commands will be executed. The action has three available shells (`host`, `target`, `renode`).
- `requires`: the array of tasks that must be executed before this task. This list is empty by default.
- `required-by`: the array of tasks that must be executed after this task. This list is empty by default.
- `before`: the array of tasks that must be executed after this task, but these tasks do not have to exist. This list is empty by default.
- `echo`: Boolean parameter. If true, the output from the shell will be printed. Default: false
- `timeout`: Default timeout for each command. Commands can override this setting. Default: null, meaning no timeout for your commands.
- `fail-fast`: Boolean parameter. If true, the action will return the error from the first failed command and stop. Otherwise, the action will fail at the end of the task. Default: true
Expand Down
4 changes: 0 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ inputs:
description: Paths to shared directories
required: false
default:
shared-dir:
description: Path to shared directory (deprecated)
required: false
default: ""
devices:
description: Devices to set up
required: false
Expand Down
3 changes: 1 addition & 2 deletions action/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Task:
name: str
shell: str
requires: list[str] = field(default_factory=list)
required_by: list[str] = field(default_factory=list)
before: list[str] = field(default_factory=list)
echo: bool = False
timeout: int | NoneType = None
fail_fast: bool = True
Expand All @@ -126,7 +126,6 @@ def apply_vars(self, default_vars: Dict[str, str], override_variables: Dict[str,
def load_from_dict(dict: Dict[str, Any]) -> 'Task':

name_map = {name: name for name in dict.keys()} | {
"required-by": "required_by",
"fail-fast": "fail_fast",
"check-exit-code": "check_exit_code",
"should-fail": "should_fail",
Expand Down
4 changes: 2 additions & 2 deletions action/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def get_file(path_or_url: str, target_path: str):
try:
r = requests.get(path_or_url)
r.raise_for_status()
except (requests.exceptions.MissingSchema, requests.RequestException) as error:
error(f"Error while downloading {path_or_url} {error.response}")
except (requests.exceptions.MissingSchema, requests.RequestException, requests.HTTPError) as err:
error(f"Error while downloading {path_or_url} {err.response}")
finally:
with open(target_path, "wb") as fd:
fd.write(r.content)
Expand Down
12 changes: 6 additions & 6 deletions action/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def __init__(self, board: str, global_vars: Dict[str, str], override_vars: Dict[
"host": ["sh", self.default_stdout, [
Command(command=[], expect=["#"], timeout=5),
Command(command=["screen -d -m renode --disable-xwt"], expect=["#"], timeout=5),
], 7, "#"],
], 5, "#"],
"renode": ["telnet 127.0.0.1 1234", self.default_stdout, [
Command(command=[], expect=["(monitor)"], timeout=5),
Command(command=["emulation CreateServerSocketTerminal 3456 \"term\""], expect=["(monitor)"], timeout=5),
], 5, r"\([\-a-zA-Z\d\s]+\)"],
], 3, r"\([\-a-zA-Z\d\s]+\)"],
"target": ["telnet 127.0.0.1 3456", self.default_stdout, [], 0, "#"],
}

Expand Down Expand Up @@ -103,10 +103,10 @@ def _sort_tasks(self) -> None:
if dependency not in self.tasks.keys():
error(f"Dependency {dependency} for {name} not satisfied. No such task.")
task_graph.add_edge(dependency, name)
for dependency in task.required_by:
if dependency not in self.tasks.keys():
error(f"Dependency {name} for {dependency} not satisfied. No such task.")
task_graph.add_edge(name, dependency)

for dependency in task.before:
if dependency in self.tasks.keys():
task_graph.add_edge(name, dependency)

try:
results = task_graph.topological_sorting(mode='out')
Expand Down
2 changes: 1 addition & 1 deletion action/run-in-renode.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_task(test_task_str: str):

prepare_kernel_and_initramfs(kernel)

prepare_shared_directories(args.get("shared-dir", "") + '\n' + args.get("shared-dirs", ""))
prepare_shared_directories(args.get("shared-dirs", ""))

devices = add_devices(args.get("devices", ""))
python_packages = add_packages(arch, args.get("python-packages", ""))
Expand Down
29 changes: 21 additions & 8 deletions action/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from command import Command, Task

from typing import Iterator, TextIO
from time import sleep

import queue
import pexpect as px
Expand Down Expand Up @@ -52,16 +53,26 @@ def _spawn(self) -> None:
"""
Start shell
"""
retries = 7

try:
self.child = px.spawn(
self.spawn_cmd,
encoding="utf-8",
timeout=None
)
while retries > 0:
try:
self.child = px.spawn(
self.spawn_cmd,
encoding="utf-8",
timeout=None
)

except px.EOF:
retries -= 1
sleep(1)
continue
except px.TIMEOUT:
error("Timeout!")
else:
return

except px.TIMEOUT:
error("Timeout!")
error(f"Shell {self.name} is not responding")

def _expect(self, command: Command) -> None:
self.last_option = self.child.expect(command.expect, timeout=command.timeout)
Expand Down Expand Up @@ -133,5 +144,7 @@ def return_code(command: Command):

except IndexError:
error("Not enough options for last expect!")
except px.EOF:
error(f"Shell {self.name} is not responding")
except px.TIMEOUT:
error("Timeout!")
2 changes: 1 addition & 1 deletion action/tasks/devices/gpio.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: device-gpio
shell: target
required-by: [chroot]
before: [chroot]
echo: true
timeout: 10
fail-fast: true
Expand Down
2 changes: 1 addition & 1 deletion action/tasks/devices/i2c.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: device-i2c
shell: target
required-by: [chroot]
before: [chroot]
echo: true
timeout: 10
fail-fast: true
Expand Down
2 changes: 1 addition & 1 deletion action/tasks/devices/vivid.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: device-vivid
shell: target
required-by: [chroot]
before: [chroot]
echo: true
timeout: 10
fail-fast: true
Expand Down
9 changes: 9 additions & 0 deletions tests/python_exists_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: python-exists-image
shell: target
requires: [chroot]
echo: true
timeout: 5
should-fail: false
commands:
- command:
- "sh -c \"if command -v python &> /dev/null; then echo Python available; exit 0; else echo Python not available; exit 1; fi;\""
9 changes: 9 additions & 0 deletions tests/python_exists_initramfs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: python-exists-initramfs
shell: target
before: [chroot]
echo: true
timeout: 5
should-fail: true
commands:
- command:
- "sh -c \"if command -v python &> /dev/null; then echo Python available; exit 0; else echo Python not available; exit 1; fi;\""

0 comments on commit 3ca9311

Please sign in to comment.