forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_before_tag.sh
More file actions
executable file
·103 lines (92 loc) · 3.3 KB
/
check_before_tag.sh
File metadata and controls
executable file
·103 lines (92 loc) · 3.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
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Script to check code formatting and other requirements before creating a tag
# Usage: ./check_before_tag.sh
echo "🔍 Pre-tag checks starting..."
echo ""
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Track if all checks pass
ALL_CHECKS_PASS=true
# 1. Check for uncommitted changes
echo "1. Checking for uncommitted changes..."
if ! git diff --quiet || ! git diff --cached --quiet; then
echo -e "${RED}❌ Uncommitted changes detected. Please commit or stash them first.${NC}"
ALL_CHECKS_PASS=false
else
echo -e "${GREEN}✅ Working directory clean${NC}"
fi
echo ""
# 2. Check code formatting
echo "2. Checking code formatting..."
if dotnet format --verify-no-changes > /dev/null 2>&1; then
echo -e "${GREEN}✅ Code formatting is correct${NC}"
else
echo -e "${YELLOW}⚠️ Code formatting issues detected${NC}"
echo " Run 'dotnet format' to fix formatting issues"
ALL_CHECKS_PASS=false
fi
echo ""
# 3. Build the project
echo "3. Building the project..."
if dotnet build -c Release --nologo --verbosity quiet > /dev/null 2>&1; then
echo -e "${GREEN}✅ Build successful${NC}"
else
echo -e "${RED}❌ Build failed${NC}"
echo " Run 'dotnet build -c Release' to see errors"
ALL_CHECKS_PASS=false
fi
echo ""
# 4. Run tests (if they exist)
echo "4. Checking for tests..."
if [ -d "tests" ] || find . -name "*.Tests.csproj" -o -name "*.Test.csproj" 2>/dev/null | grep -q .; then
echo " Running tests..."
if dotnet test --nologo --verbosity quiet > /dev/null 2>&1; then
echo -e "${GREEN}✅ Tests passed${NC}"
else
echo -e "${RED}❌ Tests failed${NC}"
echo " Run 'dotnet test' to see failures"
ALL_CHECKS_PASS=false
fi
else
echo -e "${YELLOW}ℹ️ No test projects found${NC}"
fi
echo ""
# 5. Check current branch
echo "5. Checking current branch..."
CURRENT_BRANCH=$(git branch --show-current)
if [[ "$CURRENT_BRANCH" == "develop" ]] || [[ "$CURRENT_BRANCH" == "master" ]] || [[ "$CURRENT_BRANCH" == "main" ]]; then
echo -e "${GREEN}✅ On branch: $CURRENT_BRANCH${NC}"
else
echo -e "${YELLOW}⚠️ On feature branch: $CURRENT_BRANCH${NC}"
echo " Consider switching to develop or master branch"
fi
echo ""
# 6. Check if up to date with remote
echo "6. Checking if up to date with remote..."
git fetch origin --quiet
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/$CURRENT_BRANCH 2>/dev/null)
if [ "$LOCAL" = "$REMOTE" ]; then
echo -e "${GREEN}✅ Branch is up to date with origin${NC}"
elif [ -z "$REMOTE" ]; then
echo -e "${YELLOW}⚠️ No remote tracking branch${NC}"
else
echo -e "${YELLOW}⚠️ Branch differs from origin${NC}"
echo " Consider pulling latest changes or pushing local commits"
fi
echo ""
# Final summary
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [ "$ALL_CHECKS_PASS" = true ]; then
echo -e "${GREEN}✅ All checks passed! Ready to create tag.${NC}"
echo ""
echo "To create a new tag, run:"
echo " git tag -a v2025.34-IW.X -m \"Release description\""
echo " git push origin v2025.34-IW.X"
else
echo -e "${RED}❌ Some checks failed. Please fix issues before creating tag.${NC}"
exit 1
fi