From dbd3e50c6703e2c1b5aea9a5b3a9557e01906310 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Tue, 23 Aug 2022 12:26:46 +0200 Subject: [PATCH] Enhancements to actions documentation/testing (#1128) * New test for 'directory' property of actions * Improvements to actions docs in catalog spec * Code review fix * Bump submodule Co-authored-by: GHA --- doc/catalog-format-spec.md | 27 +++++++++++++++++++--- testsuite/drivers/alr.py | 4 +++- testsuite/tests/action/directory/test.py | 24 +++++++++++++++++++ testsuite/tests/action/directory/test.yaml | 1 + 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 testsuite/tests/action/directory/test.py create mode 100644 testsuite/tests/action/directory/test.yaml diff --git a/doc/catalog-format-spec.md b/doc/catalog-format-spec.md index 2901242f..ffe79d60 100644 --- a/doc/catalog-format-spec.md +++ b/doc/catalog-format-spec.md @@ -342,12 +342,14 @@ static, i.e. they cannot depend on the context. ``` - `actions`: optional dynamic list of actions to perform when certain events - take place in a workspace. The general action syntax is: + take place in a workspace. Actions are executed in the order they are + defined in the manifest. The general action syntax is: ```toml [[actions]] type = command = + directory = # Optional ``` `` is an array of strings for a shell command to run in the @@ -361,6 +363,10 @@ static, i.e. they cannot depend on the context. root release is considered part of the dependency solution, and so its actions are executed too, always in the last place. + `directory` is an optional portable relative path (forward-slashed) from the + crate root, in which the action will be executed. This directory must exist + or the action will error. Actions are executed by default in the crate root. + `` can be either: - `post-fetch`: the command is to be run whenever there are new sources @@ -381,8 +387,9 @@ static, i.e. they cannot depend on the context. - `test`: the command is run on demand for crate testing within the Alire ecosystem (using `alr test`). This kind of action is run only for the - root crate being tested, after its build succeeds, and after any - `post-build` actions. + root crate being tested. The crate is not built beforehand when a test + action is defined so, if a build is necessary, it should be explicitly + given as part of the action sequence. Since actions may end being run more than once they should take this into account and allow multiple runs with the expected results intended by the @@ -403,6 +410,20 @@ static, i.e. they cannot depend on the context. # An explicit empty case alternative, which is not mandatory ``` + The aforementioned TOML syntax is valid when there is only one conditional + action. For multiple conditional actions, one can write: + + ```toml + [[actions]] + [actions.'case(os)'.linux] + # Regular contents of an action, applying to the Linux case + [actions.'case(os)'.macos] + # macOS case + + [[actions]] + # Another action, that needs not be also conditional (but could be). + ``` + - `auto-gpr-with`: optional Boolean value that specifies if the project (gpr) files of a crate can be automatically depended upon ('withed') directly by the root project file. (The default is true.) This feature is meant to simplify the process diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 618c6d49..f96dde74 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -429,7 +429,7 @@ def alr_with(dep="", path="", url="", commit="", branch="", return run_alr(*args, force=force) -def add_action(type, command, name=""): +def add_action(type, command, name="", directory=""): """ Add an action to the manifest in the current directory. :param str type: "pre-build", etc @@ -444,6 +444,8 @@ def add_action(type, command, name=""): manifest.write(f"command = {command}\n") if name != "": manifest.write(f"name = '{name}'\n") + if directory != "": + manifest.write(f"directory = '{directory}'\n") def alr_submit(manifest, index_path): diff --git a/testsuite/tests/action/directory/test.py b/testsuite/tests/action/directory/test.py new file mode 100644 index 00000000..f899d8a5 --- /dev/null +++ b/testsuite/tests/action/directory/test.py @@ -0,0 +1,24 @@ +""" +Test the 'directory' property of actions +""" + +import os + +from drivers.alr import run_alr, init_local_crate, add_action + +init_local_crate() + +# Add an action that touchs file in subdir +add_action("post-fetch", ["touch", "touched"], directory="sub") + +# It must initially fail as the subdir doesn't exit +p = run_alr("action", "post-fetch", complain_on_error=False) +assert p.status != 0, "Expected command to fail but didn't" + +os.mkdir("sub") + +# It must not fail now, and the touched file must exist +run_alr("action", "post-fetch") +assert os.path.isfile(os.path.join("sub", "touched")), "Expected file missing" + +print('SUCCESS') diff --git a/testsuite/tests/action/directory/test.yaml b/testsuite/tests/action/directory/test.yaml new file mode 100644 index 00000000..32c747b3 --- /dev/null +++ b/testsuite/tests/action/directory/test.yaml @@ -0,0 +1 @@ +driver: python-script -- 2.39.5