2023-04-21 14:58:47 +00:00
|
|
|
#!/bin/bash
|
2023-07-13 18:36:30 +00:00
|
|
|
# This script validates if the git diff contains only docs/ui changes
|
2023-04-21 14:58:47 +00:00
|
|
|
|
|
|
|
event_type=$1 # GH event type (pull_request)
|
|
|
|
ref_name=$2 # branch reference that triggered the workflow
|
2023-05-08 19:03:23 +00:00
|
|
|
base_ref=$3 # PR branch base ref
|
2023-04-21 14:58:47 +00:00
|
|
|
|
2023-07-13 18:36:30 +00:00
|
|
|
contains() {
|
|
|
|
target=$1; shift
|
|
|
|
for i; do
|
|
|
|
if [[ "$i" == "$target" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
2023-04-21 14:58:47 +00:00
|
|
|
|
|
|
|
if [[ "$event_type" == "pull_request" ]]; then
|
|
|
|
git fetch --no-tags --prune origin $base_ref
|
2023-05-08 19:03:23 +00:00
|
|
|
head_commit="HEAD"
|
2023-04-24 17:16:01 +00:00
|
|
|
base_commit="origin/$base_ref"
|
2023-04-21 14:58:47 +00:00
|
|
|
else
|
|
|
|
git fetch --no-tags --prune origin $ref_name
|
|
|
|
head_commit=$(git log origin/$ref_name --oneline | head -1 | awk '{print $1}')
|
2023-04-24 17:16:01 +00:00
|
|
|
base_commit=$(git log origin/$ref_name --oneline | head -2 | awk 'NR==2 {print $1}')
|
2023-04-21 14:58:47 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-13 18:36:30 +00:00
|
|
|
# git diff with ... shows the differences between base_commit and head_commit starting at the last common commit
|
|
|
|
changed_dir=$(git diff $base_commit...$head_commit --name-only | awk -F"/" '{ print $1}' | uniq)
|
2023-04-24 17:16:01 +00:00
|
|
|
change_count=$(git diff $base_commit...$head_commit --name-only | awk -F"/" '{ print $1}' | uniq | wc -l)
|
2023-04-21 14:58:47 +00:00
|
|
|
|
2023-07-13 18:36:30 +00:00
|
|
|
# There are 4 main conditions to check:
|
|
|
|
#
|
|
|
|
# 1. more than two changes found, set the flags to false
|
|
|
|
# 2. doc only change
|
|
|
|
# 3. ui only change
|
|
|
|
# 4. two changes found, if either doc or ui does not exist in the changes, set both flags to false
|
2023-04-21 14:58:47 +00:00
|
|
|
|
2023-07-13 18:36:30 +00:00
|
|
|
if [[ $change_count -gt 2 ]]; then
|
|
|
|
echo "is_docs_change=false" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "is_ui_change=false" >> "$GITHUB_OUTPUT"
|
|
|
|
elif [[ $change_count -eq 1 && "$changed_dir" == "website" ]]; then
|
2023-04-21 14:58:47 +00:00
|
|
|
echo "is_docs_change=true" >> "$GITHUB_OUTPUT"
|
2023-07-13 18:36:30 +00:00
|
|
|
echo "is_ui_change=false" >> "$GITHUB_OUTPUT"
|
|
|
|
elif [[ $change_count -eq 1 && "$changed_dir" == "ui" ]]; then
|
|
|
|
echo "is_ui_change=true" >> "$GITHUB_OUTPUT"
|
2023-04-21 14:58:47 +00:00
|
|
|
echo "is_docs_change=false" >> "$GITHUB_OUTPUT"
|
2023-07-13 18:36:30 +00:00
|
|
|
else
|
|
|
|
if ! contains "website" ${changed_dir[@]} || ! contains "ui" ${changed_dir[@]}; then
|
|
|
|
echo "is_docs_change=false" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "is_ui_change=false" >> "$GITHUB_OUTPUT"
|
|
|
|
else
|
|
|
|
echo "is_docs_change=true" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "is_ui_change=true" >> "$GITHUB_OUTPUT"
|
|
|
|
fi
|
2023-04-21 14:58:47 +00:00
|
|
|
fi
|