forked from akshaylg0314/cicd_pullpiri
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmt_check.sh
More file actions
executable file
·94 lines (77 loc) · 3 KB
/
fmt_check.sh
File metadata and controls
executable file
·94 lines (77 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -euo pipefail # Exit immediately on error, unset variable, or pipe failure
LOG_FILE="fmt_results.log"
TMP_FILE="fmt_output.txt"
# Create directory to store formatting reports
mkdir -p dist/reports/fmt
REPORT_FILE="dist/reports/fmt/fmt_summary.md"
# Clean up old logs and reports before starting
rm -f "$LOG_FILE" "$TMP_FILE" "$REPORT_FILE"
echo "Running Cargo fmt..." | tee -a "$LOG_FILE"
# Determine project root: use GitHub workspace if set, else current dir
PROJECT_ROOT=${GITHUB_WORKSPACE:-$(pwd)}
cd "$PROJECT_ROOT"
FAILED_TOTAL=0 # Counter for failed formatting checks
PASSED_TOTAL=0 # Counter for passed formatting checks
PIDS=() # (Unused here but declared in case of future parallel runs)
# Declare paths to Cargo.toml manifests for different crates/components
COMMON_MANIFEST="src/common/Cargo.toml"
AGENT_MANIFEST="src/agent/Cargo.toml"
TOOLS_MANIFEST="src/tools/Cargo.toml"
APISERVER_MANIFEST="src/server/apiserver/Cargo.toml"
FILTERGATEWAY_MANIFEST="src/player/filtergateway/Cargo.toml"
ACTIONCONTROLLER_MANIFEST="src/player/actioncontroller/Cargo.toml"
# Function to run 'cargo fmt --check' on a given manifest and record results
run_fmt() {
local manifest="$1"
local label="$2"
local fmt_passed=false
echo "Running fmt for $label ($manifest)" | tee -a "$LOG_FILE"
# Run cargo fmt in check mode; output to TMP_FILE
if cargo fmt --manifest-path="$manifest" --all --check | tee "$TMP_FILE"; then
echo "fmt for $label passed clean." | tee -a "$LOG_FILE"
fmt_passed=true
else
echo "::error ::fmt for $label failed! Found formatting issues. Check logs." | tee -a "$LOG_FILE"
# Optionally, you could extract and log only relevant warnings/errors from TMP_FILE
# e.g., grep -E "warning:|error:" "$TMP_FILE" | tee -a "$LOG_FILE"
fi
# Append pass/fail status to markdown summary report
if $fmt_passed; then
echo "✅ fmt for $label: PASSED" >> "$REPORT_FILE"
else
echo "❌ fmt for $label: FAILED" >> "$REPORT_FILE"
(( FAILED_TOTAL++ )) # Increment failure count
fi
}
# Run formatting checks for each crate manifest if the file exists
if [[ -f "$COMMON_MANIFEST" ]]; then
run_fmt "$COMMON_MANIFEST" "common"
else
echo "::warning ::$COMMON_MANIFEST not found, skipping..."
fi
if [[ -f "$APISERVER_MANIFEST" ]]; then
run_fmt "$APISERVER_MANIFEST" "apiserver"
else
echo "::warning ::$APISERVER_MANIFEST not found, skipping..."
fi
if [[ -f "$TOOLS_MANIFEST" ]]; then
run_fmt "$TOOLS_MANIFEST" "tools"
else
echo "::warning ::$TOOLS_MANIFEST not found, skipping..."
fi
if [[ -f "$AGENT_MANIFEST" ]]; then
run_fmt "$AGENT_MANIFEST" "agent"
else
echo "::warning ::$AGENT_MANIFEST not found, skipping..."
fi
if [[ -f "$FILTERGATEWAY_MANIFEST" ]]; then
run_fmt "$FILTERGATEWAY_MANIFEST" "filtergateway"
else
echo "::warning ::$FILTERGATEWAY_MANIFEST not found, skipping..."
fi
if [[ -f "$ACTIONCONTROLLER_MANIFEST" ]]; then
run_fmt "$ACTIONCONTROLLER_MANIFEST" "actioncontroller"
else
echo "::warning ::$ACTIONCONTROLLER_MANIFEST not found, skipping..."
fi