From 296639bddc4585c59d7a77f94f4689da59f16f23 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Fri, 21 Apr 2023 10:27:10 +0200 Subject: [PATCH] Use `path` and `parent` to detect a component's resources. (#12) * Use `path` and `parent` to detect a component's resources. * rephrase changelog --- CHANGELOG.md | 4 ++ project/detect-changed-components/action.yml | 49 +++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24f5649..3227bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ * `pro/generate-documentation-qmd`: Added `working_directory` option. +## Bug fixes + +* `project/detect-changed-components`: Refactor component resource detection. + # viash-actions v3.0.0 ## New features diff --git a/project/detect-changed-components/action.yml b/project/detect-changed-components/action.yml index 0f48507..1d2f3b5 100644 --- a/project/detect-changed-components/action.yml +++ b/project/detect-changed-components/action.yml @@ -24,6 +24,37 @@ runs: separator: ";" diff_relative: true + # Note: a component's resources is detected using a jq statement. + # Example usage of the jq statement: + # + # Input: + # functionality: + # resources: + # - type: python_script + # path: script.py + # parent: file:/home/rcannood/workspace/openproblems/openproblems-v2/src/label_projection/methods/knn/config.vsh.yaml + # - type: file + # path: file.txt + # parent: file:///home/rcannood/workspace/openproblems/openproblems-v2/ + # - type: "file" + # path: "resources_test/label_projection/pancreas" + # parent: "file:///home/rcannood/workspace/openproblems/openproblems-v2/" + # test_resources: + # - type: "file" + # path: "LICENSE" + # parent: "file:///home/rcannood/workspace/openproblems/openproblems-v2/" + # - type: "file" + # text: "content" + # dest: "foo.txt" + # info: + # config: /home/rcannood/workspace/openproblems/openproblems-v2/src/label_projection/methods/knn/config.vsh.yaml + # + # Output: + # /home/rcannood/workspace/openproblems/openproblems-v2/src/label_projection/methods/knn/config.vsh.yaml + # /home/rcannood/workspace/openproblems/openproblems-v2/src/label_projection/methods/knn/script.py + # /home/rcannood/workspace/openproblems/openproblems-v2/file.txt + # /home/rcannood/workspace/openproblems/openproblems-v2/resources_test/label_projection/pancreas + # /home/rcannood/workspace/openproblems/openproblems-v2/LICENSE - name: Set matrix to only run tests for components that had their config or resources changed. id: filter shell: bash @@ -52,12 +83,18 @@ runs: echo "Checking '$config_path'" # get the components resources - readarray -t resources < <(jq -cr ' - (.info.config | capture("^(?.*\/)").dir) as $dir | - ([.info.config] + - ([.functionality.resources[].path?] | map($dir + .)) + - ([.functionality.test_resources[].path?] | map($dir + .)))[] - ' <<< "$component") + readarray -t resources < <( + jq -cr ' + ( + [.info.config] + + [ + .functionality.resources[], .functionality.test_resources[] + | select(.path and .parent) + | (.parent | sub("^file:(//)?"; "") | sub("/[^/]*$"; "")) + "/" + .path + ] + )[] + ' <<< "$component" + ) # check if resource is in the list of changed resources for resource_rel_path in "${resources[@]}"; do