Skip to content

Commit e4babbe

Browse files
committed
try to fix prow
Signed-off-by: Daniel Grimm <[email protected]> Signed-off-by: Daniel Grimm <[email protected]>
1 parent 6327a74 commit e4babbe

File tree

1 file changed

+69
-40
lines changed

1 file changed

+69
-40
lines changed

tools/crd-schema-checker.sh

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,59 @@ fi
5050

5151
current_branch=$(git rev-parse --abbrev-ref HEAD)
5252

53-
# prow uses shallow-clones
54-
prow=false
53+
# Store original working directory
54+
original_dir="$(pwd)"
55+
cleanup_clone=false
56+
57+
# Enhanced prow shallow clone handling - use temporary full clone
5558
if git rev-parse --is-shallow-repository | grep -q true; then
56-
git fetch --unshallow origin || git fetch origin '+refs/heads/*:refs/remotes/origin/*'
57-
git fetch origin '+refs/heads/release-*:refs/remotes/origin/release-*' || true
58-
prow=true
59+
echo "Detected shallow clone (prow environment). Creating temporary full clone..."
60+
61+
# Get the clone URL
62+
clone_url=$(git remote get-url origin)
63+
if [[ -z "$clone_url" ]]; then
64+
echo "ERROR: Could not determine remote URL"
65+
exit 1
66+
fi
67+
68+
# Create temporary directory for full clone
69+
temp_clone_dir=$(mktemp -d)
70+
cleanup_clone=true
71+
72+
echo "Cloning full repository to $temp_clone_dir..."
73+
if ! git clone "$clone_url" "$temp_clone_dir" --quiet; then
74+
echo "ERROR: Failed to clone repository"
75+
rm -rf "$temp_clone_dir"
76+
exit 1
77+
fi
78+
79+
# Get current branch name to checkout the same branch in the clone
80+
current_branch_local=$(git rev-parse --abbrev-ref HEAD)
81+
82+
# Change to the cloned directory
83+
cd "$temp_clone_dir"
84+
85+
# Checkout the same branch if it exists
86+
if git show-ref --verify --quiet "refs/remotes/origin/$current_branch_local"; then
87+
git checkout "$current_branch_local" --quiet
88+
else
89+
echo "WARNING: Current branch '$current_branch_local' not found in full clone. Using default branch."
90+
fi
91+
92+
# Update current_branch in case we switched
93+
current_branch=$(git rev-parse --abbrev-ref HEAD)
5994
fi
6095

96+
# Setup cleanup trap
97+
cleanup() {
98+
cd "$original_dir"
99+
if [[ "$cleanup_clone" == "true" && -n "${temp_clone_dir:-}" ]]; then
100+
echo "Cleaning up temporary clone..."
101+
rm -rf "$temp_clone_dir"
102+
fi
103+
}
104+
trap cleanup EXIT
105+
61106
# Determine what to compare
62107
if [[ "$current_branch" =~ ^release-[0-9]+\.[0-9]+$ ]]; then
63108
# On release branch: compare against previous release
@@ -78,43 +123,21 @@ fi
78123

79124
# Find previous release branch (only if we're on a release branch)
80125
if [[ "$current_branch" =~ ^release-[0-9]+\.[0-9]+$ ]]; then
81-
echo "Looking for previous release branch before $target_branch..."
82-
83-
# Debug: show available branches
84-
echo "Available local branches:"
85-
git branch -a | grep -E 'release-[0-9]+\.[0-9]+$' | head -5
86-
87126
previous_branch=$(git branch -a | grep -E 'release-[0-9]+\.[0-9]+$' | \
88127
sed 's/.*release-/release-/' | sort -V | uniq | \
89128
awk -v target="$target_branch" '
90129
$0 == target { print prev; exit }
91130
{ prev = $0 }
92131
')
93-
94-
# Fallback: try to find in remote branches if not found locally (prow fix)
95-
if [[ -z "$previous_branch" && "$prow" == "true" ]]; then
96-
echo "Fallback: checking remote branches..."
97-
echo "Available remote branches:"
98-
git branch -r | grep -E 'origin/release-[0-9]+\.[0-9]+$' | head -5
99-
100-
previous_branch=$(git branch -r | grep -E 'origin/release-[0-9]+\.[0-9]+$' | \
101-
sed 's|.*origin/||' | sort -V | uniq | \
102-
awk -v target="$target_branch" '
103-
$0 == target { print prev; exit }
104-
{ prev = $0 }
105-
')
106-
fi
107-
108-
echo "Found previous branch: '$previous_branch'"
109132
fi
110133

111-
[[ -n "$previous_branch" ]] || {
112-
echo "ERROR: No previous release branch found for target: $target_branch"
134+
# Handle case where no previous release branch exists
135+
if [[ -z "$previous_branch" ]]; then
136+
echo "WARNING: No previous release branch found for target: $target_branch"
113137
echo "This might be expected for the first release in a series."
114-
echo "Available branches:"
115-
git branch -a | grep -E 'release-[0-9]+\.[0-9]+' | head -10
116-
exit 1
117-
}
138+
echo "Skipping CRD compatibility check."
139+
exit 0
140+
fi
118141

119142
echo "Checking CRD compatibility: $previous_branch -> $current_branch"
120143

@@ -127,9 +150,7 @@ mkdir -p "$previous_dir" "$current_dir"
127150

128151
extract_crds() {
129152
local branch="$1" output_dir="$2"
130-
if [[ "${prow}" == "true" ]]; then
131-
git fetch origin "${branch}" || true
132-
fi
153+
# No need to fetch branches in full clone
133154
while IFS= read -r file; do
134155
[[ -z "$file" ]] && continue
135156
content=$(git show "$branch:bundle/manifests/$file" 2>/dev/null)
@@ -167,10 +188,18 @@ for previous_crd in "${previous_crds[@]}"; do
167188

168189
if [[ -n "${current_crd_map[$crd_name]:-}" ]]; then
169190
set +e
170-
output=$($CRD_SCHEMA_CHECKER check-manifests \
171-
--disabled-validators=NoBools,NoMaps \
172-
--existing-crd-filename="$previous_crd" \
173-
--new-crd-filename="${current_crd_map[$crd_name]}" 2>&1)
191+
# Use the original directory's crd-schema-checker if we're in a temp clone
192+
if [[ "$cleanup_clone" == "true" ]]; then
193+
output=$("$original_dir/$CRD_SCHEMA_CHECKER" check-manifests \
194+
--disabled-validators=NoBools,NoMaps \
195+
--existing-crd-filename="$previous_crd" \
196+
--new-crd-filename="${current_crd_map[$crd_name]}" 2>&1)
197+
else
198+
output=$($CRD_SCHEMA_CHECKER check-manifests \
199+
--disabled-validators=NoBools,NoMaps \
200+
--existing-crd-filename="$previous_crd" \
201+
--new-crd-filename="${current_crd_map[$crd_name]}" 2>&1)
202+
fi
174203
exit_code=$?
175204
set -e
176205

0 commit comments

Comments
 (0)