refactor: Simplify CI testing to use docker-compose directly
Instead of trying to use workflow runner tools (act/act_runner), the script now directly runs the docker-compose command that CI uses. This is: - More accurate (exact same command as CI) - Simpler (no additional tools needed) - Faster (no workflow interpretation overhead) - Easier to debug (direct access to service logs) The CI workflow literally runs `docker compose -f docker-compose.ci.yml`, so running that locally is the most accurate way to test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
# Script to test Gitea Actions workflow locally using act (nektos/act)
|
||||
# This runs the actual .gitea/workflows/magnitude.yml file in a containerized environment
|
||||
# Script to test CI workflow locally by running the exact same docker-compose command as CI
|
||||
# This runs docker-compose.ci.yml which is what the Gitea Actions workflow uses
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "========================================="
|
||||
echo "Testing Gitea Actions Workflow Locally"
|
||||
echo "Testing CI Workflow Locally"
|
||||
echo "========================================="
|
||||
|
||||
# Colors for output
|
||||
@@ -21,42 +21,42 @@ if [ ! -f .env ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load environment variables from .env for passing as secrets
|
||||
echo -e "${YELLOW}Loading environment variables from .env${NC}"
|
||||
export $(cat .env | grep -v '^#' | xargs)
|
||||
echo -e "${YELLOW}Running the exact same docker-compose command as CI${NC}"
|
||||
echo -e "${YELLOW}This executes: docker compose -f docker-compose.ci.yml --profile test up${NC}"
|
||||
echo ""
|
||||
|
||||
# Build secret flags for act
|
||||
# These will be available in the workflow as secrets.*
|
||||
SECRET_FLAGS=""
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s ATPROTO_CLIENT_ID=$ATPROTO_CLIENT_ID"
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s ATPROTO_REDIRECT_URI=$ATPROTO_REDIRECT_URI"
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s GOOGLE_API_KEY=$GOOGLE_API_KEY"
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s DEEPGRAM_API_KEY=$DEEPGRAM_API_KEY"
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s SURREAL_JWT_SECRET=$SURREAL_JWT_SECRET"
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s TEST_BLUESKY_HANDLE=$TEST_BLUESKY_HANDLE"
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s TEST_BLUESKY_PASSWORD=$TEST_BLUESKY_PASSWORD"
|
||||
SECRET_FLAGS="$SECRET_FLAGS -s ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY"
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
echo -e "${YELLOW}Cleaning up containers and volumes...${NC}"
|
||||
docker compose -f docker-compose.ci.yml down -v
|
||||
}
|
||||
|
||||
echo -e "${YELLOW}Running Gitea Actions workflow with act (nektos/act)${NC}"
|
||||
echo -e "${YELLOW}This will execute .gitea/workflows/magnitude.yml${NC}"
|
||||
# Trap cleanup on exit
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run act in Docker to execute the workflow
|
||||
# - Mount Docker socket so act can create containers
|
||||
# - Mount current directory as workspace
|
||||
# - Pass secrets as flags
|
||||
# - Use -W flag to specify workflow file
|
||||
# - Use --rm to clean up container after run
|
||||
docker run --rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v "$(pwd):/workspace" \
|
||||
-w /workspace \
|
||||
nektos/act:latest \
|
||||
-W .gitea/workflows/magnitude.yml \
|
||||
$SECRET_FLAGS || {
|
||||
echo -e "${RED}Workflow execution failed!${NC}"
|
||||
# Run the exact same command that CI runs
|
||||
docker compose -f docker-compose.ci.yml --profile test up \
|
||||
--abort-on-container-exit \
|
||||
--exit-code-from magnitude || {
|
||||
echo ""
|
||||
echo -e "${RED}=========================================${NC}"
|
||||
echo -e "${RED}Tests failed!${NC}"
|
||||
echo -e "${RED}=========================================${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Showing service logs:${NC}"
|
||||
echo ""
|
||||
echo "=== SurrealDB Logs ==="
|
||||
docker compose -f docker-compose.ci.yml logs --tail=50 surrealdb
|
||||
echo ""
|
||||
echo "=== Next.js Logs ==="
|
||||
docker compose -f docker-compose.ci.yml logs --tail=50 nextjs
|
||||
echo ""
|
||||
echo "=== Magnitude Logs ==="
|
||||
docker compose -f docker-compose.ci.yml logs --tail=50 magnitude
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}=========================================${NC}"
|
||||
echo -e "${GREEN}Workflow executed successfully!${NC}"
|
||||
echo -e "${GREEN}All tests passed!${NC}"
|
||||
echo -e "${GREEN}=========================================${NC}"
|
||||
|
||||
Reference in New Issue
Block a user