Skip to content

Commit

Permalink
Exclude SHAs changes from validate
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi committed Sep 30, 2024
1 parent eb15fc2 commit db10a4b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,7 @@ jobs:
- name: Check if everything is consistent
working-directory: ./src/github.com/${{ github.repository }}
run: |
if [ -n "$(git status --porcelain)" ]; then
echo '::debug::Running `git status`'
git -c color.status=always status
echo '::debug::Running `git diff`'
git -c color.ui=always diff
echo '::error::Not all generated files are commited. Run `make generated-files` and commit files.'
echo '::warning::`make generated-files` needs to be run on GOPATH due to https://github.com/knative/pkg/issues/1287'
exit 33
fi
run: ./hack/verify-diff.sh

- name: Check existence of skipRange and replaces in ClusterServiceVersion
working-directory: ./src/github.com/${{ github.repository }}
Expand Down
59 changes: 59 additions & 0 deletions hack/verify-diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

# Define the files to exclude
readonly EXCLUDE_FILES=(
'olm-catalog/serverless-operator/manifests/serverless-operator.clusterserviceversion.yaml'
'olm-catalog/serverless-operator/index/Dockerfile'
)
# Define the patterns to exclude
readonly EXCLUDE_PATTERNS=(
'*sha256:*'
)

# Function to check if a file should be excluded
function should_exclude() {
local file="$1"
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
diff="$(git --no-pager -c color.ui=never diff --unified=0 "$file" | grep '^[+-] ')"
while IFS= read -r line; do
# shellcheck disable=SC2053
if [[ $line == $pattern || $line =~ $pattern ]]; then
echo "Excluding line $line since matches pattern $pattern"
else
echo "line '$line' doesn't match pattern '$pattern', failing the exclude check"
return 1
fi
done <<< "$diff"
done

return 0
}

# shellcheck disable=SC2016
function debug_log_fail() {
echo '::debug::Running `git status`'
git -c color.status=always status
echo '::debug::Running `git diff`'
git --no-pager -c color.ui=always diff
echo '::error::Not all generated files are committed. Run `make generated-files` and commit files.'
echo '::warning::`make generated-files` needs to be run on GOPATH due to https://github.com/knative/pkg/issues/1287'
}

# shellcheck disable=SC2143
if [ -n "$(git status --porcelain | grep -v -E "$(IFS=\|; echo "${EXCLUDE_FILES[*]}")")" ]; then
debug_log_fail
exit 33
fi

# shellcheck disable=SC2143
if [ -n "$(git status --porcelain | grep -E "$(IFS=\|; echo "${EXCLUDE_FILES[*]}")")" ]; then
echo 'Excluded files are different'

git diff --name-only | while read -r file; do
if ! should_exclude "$file"; then
git --no-pager -c color.ui=always diff "$file"
debug_log_fail
exit 33
fi
done
fi

0 comments on commit db10a4b

Please sign in to comment.