mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 19:47:54 +00:00
use verify changes for docs to skip tests (#21620)
* use verify changes for docs to skip tests * add verify-changes to the needed jobs * skip go tests for doc/ui only changes * fix a job ref * change names, remove script * remove ui conditions * separate flags * feedback
This commit is contained in:
43
.github/scripts/verify_changes.sh
vendored
43
.github/scripts/verify_changes.sh
vendored
@@ -1,11 +1,19 @@
|
||||
#!/bin/bash
|
||||
# This script validates if the git diff contains on docs changes
|
||||
# This script validates if the git diff contains only docs/ui changes
|
||||
|
||||
event_type=$1 # GH event type (pull_request)
|
||||
ref_name=$2 # branch reference that triggered the workflow
|
||||
base_ref=$3 # PR branch base ref
|
||||
|
||||
changed_dir=""
|
||||
contains() {
|
||||
target=$1; shift
|
||||
for i; do
|
||||
if [[ "$i" == "$target" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
if [[ "$event_type" == "pull_request" ]]; then
|
||||
git fetch --no-tags --prune origin $base_ref
|
||||
@@ -17,15 +25,32 @@ else
|
||||
base_commit=$(git log origin/$ref_name --oneline | head -2 | awk 'NR==2 {print $1}')
|
||||
fi
|
||||
|
||||
# git diff with ... shows the differences count between base_commit and head_commit starting at the last common commit
|
||||
# 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)
|
||||
change_count=$(git diff $base_commit...$head_commit --name-only | awk -F"/" '{ print $1}' | uniq | wc -l)
|
||||
|
||||
if [[ $change_count -eq 1 ]]; then
|
||||
changed_dir=$(git diff $base_commit...$head_commit --name-only | awk -F"/" '{ print $1}' | uniq)
|
||||
fi
|
||||
# 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
|
||||
|
||||
if [[ "$changed_dir" == "website" ]]; then
|
||||
echo "is_docs_change=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
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
|
||||
echo "is_docs_change=true" >> "$GITHUB_OUTPUT"
|
||||
echo "is_ui_change=false" >> "$GITHUB_OUTPUT"
|
||||
elif [[ $change_count -eq 1 && "$changed_dir" == "ui" ]]; then
|
||||
echo "is_ui_change=true" >> "$GITHUB_OUTPUT"
|
||||
echo "is_docs_change=false" >> "$GITHUB_OUTPUT"
|
||||
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
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user