Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect-changed-components: detect changes when resources are a directory. #28

Merged
merged 17 commits into from
Mar 6, 2024
Merged
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