Skip to content

Commit

Permalink
detect-changed-components: detect changes when resources are a direct…
Browse files Browse the repository at this point in the history
…ory. (#28)
  • Loading branch information
DriesSchaumont authored Mar 6, 2024
1 parent 02e2ae5 commit a99a25f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# viash-actions v5.3.0

## New functionality

* `project/detect-changed-components`: Detect changed components when a resource is a directory (PR #28).

# viash-actions v5.2.1

## Bug Fixes
Expand Down Expand Up @@ -145,4 +151,4 @@
Initial release. Contains the following actions:

* `setup`: Install Viash
* `ns-list`: List components in repo
* `ns-list`: List components in repo
41 changes: 33 additions & 8 deletions project/detect-changed-components/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
steps:
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected].2
uses: tj-actions/[email protected].5
with:
separator: ";"
diff_relative: true
Expand Down Expand Up @@ -76,6 +76,7 @@ runs:
declare -a changed_files=()
trim_slash() {
line=$2
echo "Found changed file: $line"
changed_files[$1]="${line/%\\/}"
}
# read changed files as array
Expand All @@ -102,15 +103,39 @@ runs:
)[]
' <<< "$component"
)
# check if resource is in the list of changed resources
for resource_rel_path in "${resources[@]}"; do
resource_project_path=$(realpath --relative-to="$GITHUB_WORKSPACE" "$resource_rel_path")
if [[ " ${changed_files[*]} " =~ " ${resource_project_path} " ]]; then
echo " Detected changed resources!"
output_array+="$component"
break
for resource in "${resources[@]}"; do
echo "Checking resource: $resource"
if [ ! -e "$resource" ]; then
echo "Resource $resource does not exist."
exit 1
fi
resource_real_path=$(realpath "$resource")
resource_arr=("$resource_real_path")
# Resolve resources that are a directory into files
if [ -d "$resource_real_path" ]; then
echo "Resource is a directory"
files_from_directories=()
readarray -d '' files_from_directories < <(find $resource_real_path -type f -print0)
resource_arr+=(${files_from_directories[@]})
fi
echo "All resources including files from directories: ${resource_arr[@]}"
for changed_file in ${changed_files[@]}; do
should_add_component=0
changed_file_real_path=$(realpath "$changed_file")
echo "Using changed file: $changed_file_real_path"
for resource_to_check in ${resource_arr[@]}; do
if [ "$changed_file_real_path" = "$resource_to_check" ]; then
echo "Detected changed component!"
should_add_component=1
break
fi
done
if [[ "$should_add_component" -eq 1 ]]; then
output_array+="$component"
break
fi
done
done
done
Expand Down

0 comments on commit a99a25f

Please sign in to comment.