1+ #! /bin/bash
2+
3+ echo " ======================================"
4+ echo " Local Build Check (GitHub Actions Simulation)"
5+ echo " ======================================"
6+ echo " "
7+
8+ # Colors for output
9+ RED=' \033[0;31m'
10+ GREEN=' \033[0;32m'
11+ YELLOW=' \033[1;33m'
12+ NC=' \033[0m' # No Color
13+
14+ # Track overall status
15+ BUILD_SUCCESS=true
16+
17+ echo " 1. Checking for unnecessary using directives (IDE0005)..."
18+ echo " ---------------------------------------------------"
19+ if dotnet build -c Release src/SourceGit.csproj -warnaserror:IDE0005 > /tmp/build_ide0005.log 2>&1 ; then
20+ echo -e " ${GREEN} ✅ No IDE0005 errors found${NC} "
21+ else
22+ echo -e " ${RED} ❌ IDE0005 errors detected:${NC} "
23+ grep " error IDE0005" /tmp/build_ide0005.log
24+ BUILD_SUCCESS=false
25+ fi
26+ echo " "
27+
28+ echo " 2. Running full Release build..."
29+ echo " --------------------------------"
30+ if dotnet build -c Release src/SourceGit.csproj > /tmp/build_release.log 2>&1 ; then
31+ echo -e " ${GREEN} ✅ Release build successful${NC} "
32+ WARNINGS=$( grep -c " warning" /tmp/build_release.log 2> /dev/null || echo " 0" )
33+ if [ " $WARNINGS " -gt " 0" ]; then
34+ echo -e " ${YELLOW} ⚠️ Build has $WARNINGS warnings${NC} "
35+ fi
36+ else
37+ echo -e " ${RED} ❌ Release build failed${NC} "
38+ grep -E " error" /tmp/build_release.log | head -10
39+ BUILD_SUCCESS=false
40+ fi
41+ echo " "
42+
43+ echo " 3. Checking code analysis rules..."
44+ echo " -----------------------------------"
45+ # Check with all code analysis rules that GitHub Actions uses
46+ if dotnet build -c Release src/SourceGit.csproj \
47+ -warnaserror:IDE0005 \
48+ -warnaserror:CS8600 \
49+ -warnaserror:CS8602 \
50+ -warnaserror:CS8604 \
51+ -warnaserror:CS8618 \
52+ -warnaserror:CS8625 \
53+ -p:TreatWarningsAsErrors=false \
54+ > /tmp/build_analysis.log 2>&1 ; then
55+ echo -e " ${GREEN} ✅ Code analysis passed${NC} "
56+ else
57+ echo -e " ${RED} ❌ Code analysis failed:${NC} "
58+ grep -E " error" /tmp/build_analysis.log | head -10
59+ BUILD_SUCCESS=false
60+ fi
61+ echo " "
62+
63+ echo " 4. Checking for common issues..."
64+ echo " ---------------------------------"
65+
66+ # Check for tabs vs spaces issues
67+ TAB_FILES=$( find src -name " *.cs" -exec grep -l $' \t ' {} \; 2> /dev/null | wc -l)
68+ if [ " $TAB_FILES " -eq 0 ]; then
69+ echo -e " ${GREEN} ✅ No tab/space issues${NC} "
70+ else
71+ echo -e " ${YELLOW} ⚠️ $TAB_FILES files contain tabs${NC} "
72+ fi
73+
74+ # Check for BOM issues
75+ BOM_FILES=$( find src -name " *.cs" -exec file {} \; | grep -c " with BOM" || echo " 0" )
76+ if [ " $BOM_FILES " -eq 0 ]; then
77+ echo -e " ${GREEN} ✅ No BOM issues${NC} "
78+ else
79+ echo -e " ${YELLOW} ⚠️ $BOM_FILES files have BOM${NC} "
80+ fi
81+
82+ # Check for line ending issues (CRLF vs LF)
83+ CRLF_FILES=$( find src -name " *.cs" -exec file {} \; | grep -c " CRLF" || echo " 0" )
84+ echo -e " ${YELLOW} ℹ️ $CRLF_FILES files use CRLF line endings${NC} "
85+
86+ echo " "
87+ echo " 5. Test compilation for all platforms..."
88+ echo " -----------------------------------------"
89+
90+ # Test Windows build
91+ echo -n " Windows (win-x64): "
92+ if dotnet publish src/SourceGit.csproj -c Release -r win-x64 --self-contained -o /tmp/test-win > /dev/null 2>&1 ; then
93+ echo -e " ${GREEN} ✅${NC} "
94+ else
95+ echo -e " ${RED} ❌${NC} "
96+ BUILD_SUCCESS=false
97+ fi
98+
99+ # Test macOS build
100+ echo -n " macOS (osx-arm64): "
101+ if dotnet publish src/SourceGit.csproj -c Release -r osx-arm64 --self-contained -o /tmp/test-osx > /dev/null 2>&1 ; then
102+ echo -e " ${GREEN} ✅${NC} "
103+ else
104+ echo -e " ${RED} ❌${NC} "
105+ BUILD_SUCCESS=false
106+ fi
107+
108+ # Test Linux build
109+ echo -n " Linux (linux-x64): "
110+ if dotnet publish src/SourceGit.csproj -c Release -r linux-x64 --self-contained -o /tmp/test-linux > /dev/null 2>&1 ; then
111+ echo -e " ${GREEN} ✅${NC} "
112+ else
113+ echo -e " ${RED} ❌${NC} "
114+ BUILD_SUCCESS=false
115+ fi
116+
117+ # Cleanup temp directories
118+ rm -rf /tmp/test-win /tmp/test-osx /tmp/test-linux 2> /dev/null
119+
120+ echo " "
121+ echo " ======================================"
122+ if [ " $BUILD_SUCCESS " = true ]; then
123+ echo -e " ${GREEN} ✅ ALL CHECKS PASSED!${NC} "
124+ echo " Ready to commit and push to GitHub."
125+ else
126+ echo -e " ${RED} ❌ SOME CHECKS FAILED!${NC} "
127+ echo " Please fix the issues before pushing to GitHub."
128+ echo " "
129+ echo " To see detailed errors, check:"
130+ echo " /tmp/build_ide0005.log"
131+ echo " /tmp/build_release.log"
132+ echo " /tmp/build_analysis.log"
133+ fi
134+ echo " ======================================"
135+
136+ # Exit with error if build failed
137+ if [ " $BUILD_SUCCESS " = false ]; then
138+ exit 1
139+ fi
0 commit comments