Skip to content

Commit 9000563

Browse files
committed
feat: Add local GitHub Actions testing setup - Add interactive test script (scripts/test-workflows.sh) with menu-driven workflow testing - Add .actrc configuration optimized for Apple M-series Macs - Enable local testing of CI, security, docs, and release workflows - Include Docker status checks and colored output for better UX
1 parent d6125d6 commit 9000563

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed

.actrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Act configuration file for MCP Rust Examples project
2+
# This file configures act for optimal performance on Apple M-series Macs
3+
4+
# Use linux/amd64 architecture for compatibility
5+
--container-architecture linux/amd64
6+
7+
# Use medium size runner image (good balance of features vs size)
8+
-P ubuntu-latest=catthehacker/ubuntu:act-latest
9+
10+
# Bind working directory instead of copying (faster for development)
11+
--bind
12+
13+
# Cache action downloads for faster subsequent runs
14+
--action-cache-path ~/.cache/act
15+
16+
# Set default actor name
17+
--actor nektos/act
18+
19+
# Environment variables for testing
20+
--env CARGO_TERM_COLOR=always
21+
--env RUST_BACKTRACE=1
22+
--env CI=true

scripts/test-workflows.sh

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#!/bin/bash
2+
# GitHub Actions Local Testing Script
3+
# This script helps you test your GitHub Actions workflows locally using act
4+
5+
set -e
6+
7+
# Colors for output
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
BLUE='\033[0;34m'
12+
NC='\033[0m' # No Color
13+
14+
# Function to print colored output
15+
print_status() {
16+
echo -e "${BLUE}[INFO]${NC} $1"
17+
}
18+
19+
print_success() {
20+
echo -e "${GREEN}[SUCCESS]${NC} $1"
21+
}
22+
23+
print_warning() {
24+
echo -e "${YELLOW}[WARNING]${NC} $1"
25+
}
26+
27+
print_error() {
28+
echo -e "${RED}[ERROR]${NC} $1"
29+
}
30+
31+
# Check if act is installed
32+
if ! command -v act &> /dev/null; then
33+
print_error "act is not installed. Please install it first:"
34+
echo " brew install act"
35+
exit 1
36+
fi
37+
38+
# Check if Docker is running
39+
if ! docker info &> /dev/null; then
40+
print_error "Docker is not running. Please start Docker first."
41+
exit 1
42+
fi
43+
44+
print_status "🎭 GitHub Actions Local Testing Script"
45+
echo ""
46+
47+
# Function to run a workflow job
48+
run_job() {
49+
local job_name="$1"
50+
local description="$2"
51+
52+
print_status "Testing: $description"
53+
echo "Command: act push --job $job_name --container-architecture linux/amd64"
54+
echo ""
55+
56+
if act push --job "$job_name" --container-architecture linux/amd64; then
57+
print_success "$description completed successfully!"
58+
else
59+
print_error "$description failed!"
60+
return 1
61+
fi
62+
echo ""
63+
}
64+
65+
# Main menu
66+
show_menu() {
67+
echo "🚀 Choose what to test:"
68+
echo ""
69+
echo "1) Quick Test (quality checks only)"
70+
echo "2) Build Test (compile all examples)"
71+
echo "3) Security Audit"
72+
echo "4) Documentation Build"
73+
echo "5) Full CI Pipeline (all jobs)"
74+
echo "6) List Available Jobs"
75+
echo "7) Custom Job"
76+
echo "q) Quit"
77+
echo ""
78+
}
79+
80+
# Quick test function
81+
quick_test() {
82+
print_status "🔍 Running quick quality checks..."
83+
run_job "quality" "Code Quality (clippy, formatting)"
84+
}
85+
86+
# Build test function
87+
build_test() {
88+
print_status "🔨 Running build tests..."
89+
run_job "test" "Build and Test Suite"
90+
}
91+
92+
# Security test function
93+
security_test() {
94+
print_status "🛡️ Running security audit..."
95+
run_job "security-audit" "Security Audit"
96+
}
97+
98+
# Documentation test function
99+
docs_test() {
100+
print_status "📚 Running documentation build..."
101+
run_job "build-docs" "Documentation Build"
102+
}
103+
104+
# Full CI test function
105+
full_ci_test() {
106+
print_status "🚀 Running full CI pipeline..."
107+
print_warning "This will take several minutes and requires significant resources."
108+
read -p "Continue? (y/N): " -n 1 -r
109+
echo ""
110+
111+
if [[ $REPLY =~ ^[Yy]$ ]]; then
112+
run_job "test" "Build and Test Suite" && \
113+
run_job "quality" "Code Quality" && \
114+
run_job "security-audit" "Security Audit" && \
115+
run_job "build-docs" "Documentation Build"
116+
117+
if [ $? -eq 0 ]; then
118+
print_success "🎉 Full CI pipeline completed successfully!"
119+
else
120+
print_error "❌ CI pipeline failed!"
121+
fi
122+
else
123+
print_status "Cancelled."
124+
fi
125+
}
126+
127+
# List jobs function
128+
list_jobs() {
129+
print_status "📋 Available workflow jobs:"
130+
act --list
131+
}
132+
133+
# Custom job function
134+
custom_job() {
135+
echo ""
136+
echo "Available jobs:"
137+
act --list | grep -E "^\d+" | awk '{print " - " $2}'
138+
echo ""
139+
read -p "Enter job name: " job_name
140+
141+
if [ -n "$job_name" ]; then
142+
run_job "$job_name" "Custom Job: $job_name"
143+
else
144+
print_warning "No job name provided."
145+
fi
146+
}
147+
148+
# Main loop
149+
main() {
150+
print_status "Docker status: $(docker info >/dev/null 2>&1 && echo '✅ Running' || echo '❌ Not running')"
151+
print_status "Act version: $(act --version 2>/dev/null || echo 'Unknown')"
152+
echo ""
153+
154+
while true; do
155+
show_menu
156+
read -p "Choose an option (1-7, q): " choice
157+
echo ""
158+
159+
case $choice in
160+
1)
161+
quick_test
162+
;;
163+
2)
164+
build_test
165+
;;
166+
3)
167+
security_test
168+
;;
169+
4)
170+
docs_test
171+
;;
172+
5)
173+
full_ci_test
174+
;;
175+
6)
176+
list_jobs
177+
;;
178+
7)
179+
custom_job
180+
;;
181+
q|Q)
182+
print_status "👋 Goodbye!"
183+
exit 0
184+
;;
185+
*)
186+
print_warning "Invalid option. Please choose 1-7 or q."
187+
;;
188+
esac
189+
190+
echo ""
191+
read -p "Press Enter to continue..."
192+
echo ""
193+
done
194+
}
195+
196+
# Run main function
197+
main "$@"

0 commit comments

Comments
 (0)