Skip to content

Commit b37a402

Browse files
committed
external script addition to verify dependencies
Signed-off-by: ashish-jabble <[email protected]>
1 parent c540b7d commit b37a402

File tree

2 files changed

+519
-254
lines changed

2 files changed

+519
-254
lines changed

.github/workflows/verify-deps.yml

Lines changed: 17 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -55,263 +55,27 @@ jobs:
5555
echo "✅ Control file found: $CONTROL_FILE"
5656
5757
- name: Verify dependencies & generate report
58+
env:
59+
TARGET_OS: ${{ matrix.os }}
60+
TARGET_ARCH: ${{ matrix.arch }}
61+
TARGET_CODENAME: ${{ matrix.codename }}
5862
run: |
59-
set -euo pipefail
60-
61-
# Initialize report
62-
cat > "$REPORT" << EOF
63-
## 📦 Dependency Verification Report
64-
65-
**Platform:** ${{ matrix.arch }} on ${{ matrix.os }} (${{ matrix.codename }})
66-
**Generated:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')
67-
**Workflow:** ${GITHUB_WORKFLOW} - Run #${GITHUB_RUN_NUMBER}
68-
69-
EOF
70-
71-
# Enhanced dependency extraction function
72-
extract_deps() {
73-
local field="$1"
74-
awk -v field="$field" '
75-
BEGIN { found=0; deps="" }
76-
{
77-
if ($0 ~ "^" field ":") {
78-
found=1
79-
gsub("^" field ":[[:space:]]*", "")
80-
deps = $0
81-
} else if (found && $0 ~ "^[[:space:]]") {
82-
# Continuation line (starts with whitespace)
83-
gsub("^[[:space:]]*", "")
84-
if ($0 != "") {
85-
deps = deps " " $0
86-
}
87-
} else if (found && $0 !~ "^[[:space:]]" && $0 != "") {
88-
# New field found, stop processing
89-
print deps
90-
exit
91-
}
92-
}
93-
END { if (found && deps != "") print deps }
94-
' "$CONTROL_FILE" | \
95-
tr ',' '\n' | \
96-
sed -E 's/\([^)]*\)//g' | \
97-
sed -E 's/\[[^]]*\]//g' | \
98-
awk '{gsub(/^[[:space:]]+|[[:space:]]+$/, ""); if ($1 != "") print $1}' | \
99-
sort -u
100-
}
101-
102-
# Function to detect and resolve version placeholders
103-
resolve_version_placeholders() {
104-
local control_file="$1"
105-
local temp_file=""
106-
107-
echo "🔍 Checking for version placeholders in $(basename "$control_file")..." >&2
108-
109-
# Check for BOOST_VER placeholder
110-
if grep -q "{{BOOST_VER}}" "$control_file"; then
111-
echo "📦 Found {{BOOST_VER}} placeholder, resolving Boost version..." >&2
112-
113-
local boost_version=""
114-
local boost_suffix=""
115-
116-
# Method 1: Check installed libboost-dev package
117-
if [ -z "$boost_version" ]; then
118-
boost_version=$(dpkg -l 2>/dev/null | grep "libboost-dev" | awk '{print $3}' | grep -oP '^\d+\.\d+\.\d+' | head -1 || true)
119-
[ -n "$boost_version" ] && echo "✅ Found installed Boost version: $boost_version" >&2
120-
fi
121-
122-
# Method 2: Check available package version
123-
if [ -z "$boost_version" ]; then
124-
boost_version=$(apt-cache policy libboost-dev 2>/dev/null | grep "Candidate:" | awk '{print $2}' | grep -oP '^\d+\.\d+\.\d+' | head -1 || true)
125-
[ -n "$boost_version" ] && echo "✅ Found available Boost version: $boost_version" >&2
126-
fi
127-
128-
# Determine the correct Boost package suffix format
129-
echo "🔍 Determining correct Boost package naming format..." >&2
130-
131-
local boost_major_minor=$(echo "$boost_version" | cut -d'.' -f1-2)
132-
local boost_major_minor_no_dot=$(echo "$boost_major_minor" | tr -d '.')
133-
134-
# Test different naming conventions
135-
if apt-cache show "libboost-system${boost_version}" >/dev/null 2>&1; then
136-
boost_suffix="$boost_version"
137-
echo "✅ Found format: libboost-system${boost_suffix}" >&2
138-
elif apt-cache show "libboost-system${boost_major_minor}" >/dev/null 2>&1; then
139-
boost_suffix="$boost_major_minor"
140-
echo "✅ Found format: libboost-system${boost_suffix}" >&2
141-
elif apt-cache show "libboost-system${boost_major_minor_no_dot}" >/dev/null 2>&1; then
142-
boost_suffix="$boost_major_minor_no_dot"
143-
echo "✅ Found format: libboost-system${boost_suffix}" >&2
144-
else
145-
# Fallback to the most common format
146-
boost_suffix="$boost_major_minor"
147-
echo "⚠️ Could not detect format, using default: libboost-system${boost_suffix}" >&2
148-
fi
149-
150-
echo "🔢 Final Boost package suffix: $boost_suffix" >&2
151-
152-
# Create temporary file if not already created
153-
if [ -z "$temp_file" ]; then
154-
temp_file=$(mktemp)
155-
cp "$control_file" "$temp_file"
156-
fi
157-
158-
# Replace BOOST_VER placeholder
159-
sed -i "s/{{BOOST_VER}}/${boost_suffix}/g" "$temp_file"
160-
echo "✅ Resolved {{BOOST_VER}} to ${boost_suffix}" >&2
161-
162-
# Show resolved dependencies for verification
163-
echo "🔍 Resolved Boost dependencies:" >&2
164-
grep -E "libboost.*${boost_suffix}" "$temp_file" >&2 || true
165-
fi
166-
167-
# TODO: Add more placeholder handlers here in the future
168-
# Example for future use:
169-
# if grep -q "{{PYTHON_VER}}" "$control_file"; then
170-
# echo "📦 Found {{PYTHON_VER}} placeholder, resolving Python version..."
171-
# # Add Python version detection logic here
172-
# fi
173-
174-
# Return the path to the resolved file (or original if no changes)
175-
if [ -n "$temp_file" ]; then
176-
echo "📝 Using temporary control file with resolved placeholders: $temp_file" >&2
177-
echo "$temp_file"
178-
else
179-
echo "ℹ️ No version placeholders found, using original file" >&2
180-
echo "$control_file"
181-
fi
182-
}
183-
184-
# Resolve version placeholders in control file
185-
RESOLVED_CONTROL_FILE=$(resolve_version_placeholders "$CONTROL_FILE")
186-
187-
# Store the temporary file path for cleanup later
188-
if [ "$RESOLVED_CONTROL_FILE" != "$CONTROL_FILE" ]; then
189-
TEMP_CONTROL_FILE="$RESOLVED_CONTROL_FILE"
190-
echo "🔄 Using resolved control file: $TEMP_CONTROL_FILE"
191-
else
192-
echo "📄 Using original control file: $CONTROL_FILE"
193-
fi
194-
195-
# Update CONTROL_FILE to point to the resolved file
196-
CONTROL_FILE="$RESOLVED_CONTROL_FILE"
197-
198-
# Extract dependencies
199-
echo "🔍 Extracting dependencies from control file..."
200-
echo "📄 Using control file: $CONTROL_FILE"
201-
202-
BUILD_DEPS=$(extract_deps "Build-Depends")
203-
RUNTIME_DEPS=$(extract_deps "Depends")
204-
RECOMMENDS=$(extract_deps "Recommends")
205-
SUGGESTS=$(extract_deps "Suggests")
206-
207-
# Validate extraction results
208-
BUILD_COUNT=$(echo "$BUILD_DEPS" | wc -w)
209-
RUNTIME_COUNT=$(echo "$RUNTIME_DEPS" | wc -w)
210-
211-
echo "📊 Extraction results:"
212-
echo " - Build dependencies: $BUILD_COUNT packages"
213-
echo " - Runtime dependencies: $RUNTIME_COUNT packages"
214-
echo " - Recommended packages: $(echo "$RECOMMENDS" | wc -w) packages"
215-
echo " - Suggested packages: $(echo "$SUGGESTS" | wc -w) packages"
216-
217-
if [ $BUILD_COUNT -eq 0 ] && [ $RUNTIME_COUNT -eq 0 ]; then
218-
echo "❌ No dependencies extracted! This might indicate a parsing error."
219-
echo "Control file content:"
220-
head -20 "$CONTROL_FILE"
63+
# Run the dedicated dependency verification script with proper error handling
64+
set -e # Exit on any error
65+
echo "🚀 Starting dependency verification..."
66+
67+
if ! ./scripts/verify-dependencies.sh \
68+
"$CONTROL_FILE" \
69+
"$REPORT" \
70+
"$TARGET_OS" \
71+
"$TARGET_ARCH" \
72+
"$TARGET_CODENAME"; then
73+
echo "❌ Dependency verification script failed with exit code $?"
74+
echo "::error::Dependency verification failed for $TARGET_ARCH on $TARGET_OS ($TARGET_CODENAME)"
22175
exit 1
22276
fi
22377
224-
# Update package cache with retry
225-
echo "📥 Updating package cache..."
226-
for i in {1..3}; do
227-
if sudo apt-get update -qq; then
228-
break
229-
elif [ $i -eq 3 ]; then
230-
echo "❌ Failed to update package cache after 3 attempts"
231-
exit 1
232-
else
233-
echo "⚠️ Package cache update failed, retrying in 10s..."
234-
sleep 10
235-
fi
236-
done
237-
238-
# Enhanced dependency checking function
239-
check_dependencies() {
240-
local label="$1"
241-
local pkgs="$2"
242-
local is_critical="$3"
243-
local fail=0
244-
local total=0
245-
local available=0
246-
247-
echo "" >> "$REPORT"
248-
echo "## $label" >> "$REPORT"
249-
250-
if [ -z "$pkgs" ]; then
251-
echo "- ℹ️ No $label specified" >> "$REPORT"
252-
return 0
253-
fi
254-
255-
for pkg in $pkgs; do
256-
total=$((total + 1))
257-
258-
# Skip empty package names
259-
[ -z "$pkg" ] && continue
260-
261-
# Check if package is available
262-
if apt-cache show "$pkg" > /dev/null 2>&1; then
263-
# Get package version info
264-
version=$(apt-cache policy "$pkg" 2>/dev/null | grep "Candidate:" | awk '{print $2}' || echo "unknown")
265-
echo "- ✅ **$pkg** (version: $version)" >> "$REPORT"
266-
available=$((available + 1))
267-
else
268-
echo "- ❌ **$pkg** - Package not found in repositories" >> "$REPORT"
269-
270-
# Try to find similar packages
271-
similar=$(apt-cache search "^$pkg" 2>/dev/null | head -3 | cut -d' ' -f1 | tr '\n' ', ' | sed 's/,$//')
272-
if [ -n "$similar" ]; then
273-
echo " - 💡 Similar packages: $similar" >> "$REPORT"
274-
fi
275-
276-
if [ "$is_critical" = "true" ]; then
277-
fail=1
278-
fi
279-
fi
280-
done
281-
282-
# Add summary
283-
echo "" >> "$REPORT"
284-
echo "**Summary:** $available/$total packages available" >> "$REPORT"
285-
286-
if [ $fail -eq 1 ]; then
287-
echo "⚠️ **Critical dependencies missing!**" >> "$REPORT"
288-
fi
289-
290-
return $fail
291-
}
292-
293-
# Check all dependency types
294-
check_dependencies "🔨 Build Dependencies" "$BUILD_DEPS" "true" || exit 1
295-
check_dependencies "🏃 Runtime Dependencies" "$RUNTIME_DEPS" "true" || exit 1
296-
check_dependencies "💡 Recommended Packages" "$RECOMMENDS" "false" || true
297-
check_dependencies "🔧 Suggested Packages" "$SUGGESTS" "false" || true
298-
299-
# Add final summary
300-
cat >> "$REPORT" << EOF
301-
302-
---
303-
304-
## ✅ Verification Complete
305-
306-
All dependencies are accessible for ${{ matrix.arch }} on ${{ matrix.os }} (${{ matrix.codename }}).
307-
308-
EOF
309-
310-
# Cleanup temporary file if created
311-
if [ -n "${TEMP_CONTROL_FILE:-}" ] && [ -f "$TEMP_CONTROL_FILE" ]; then
312-
rm -f "$TEMP_CONTROL_FILE"
313-
echo "🧹 Cleaned up temporary control file"
314-
fi
78+
echo "✅ Dependency verification completed successfully"
31579
31680
- name: Validate report was generated
31781
run: |
@@ -339,4 +103,3 @@ jobs:
339103
echo "This indicates build or runtime dependencies are missing."
340104
echo "Please review the generated report and update the control file or repository configuration."
341105
exit 1
342-

0 commit comments

Comments
 (0)