mnemo_cards/tools/deploy/setup-forgejo-actions.sh

152 lines
4.5 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
# Script to setup and diagnose Forgejo Actions
# Fixes common issues with actions not running
set -e
SERVER_IP="147.45.152.129"
SERVER_USER="root"
FORGEJO_DOMAIN="code.mnemo-cards.online"
echo "🔧 Setting up Forgejo Actions..."
ssh "$SERVER_USER@$SERVER_IP" << 'EOF'
set -e
echo "📝 Checking Forgejo installation..."
# Check if Forgejo is running
if systemctl is-active --quiet forgejo; then
echo "✅ Forgejo service is running"
else
echo "❌ Forgejo service is not running"
echo "Starting Forgejo..."
systemctl start forgejo
sleep 3
fi
# Check Forgejo configuration
FORGEJO_CONFIG="/etc/forgejo/app.ini"
if [ ! -f "$FORGEJO_CONFIG" ]; then
FORGEJO_CONFIG="/var/lib/forgejo/custom/conf/app.ini"
fi
if [ ! -f "$FORGEJO_CONFIG" ]; then
echo "❌ Forgejo config not found. Checking possible locations..."
find / -name "app.ini" 2>/dev/null | grep -i forgejo || echo "Config not found"
exit 1
fi
echo "✅ Found Forgejo config: $FORGEJO_CONFIG"
echo ""
echo "📊 Checking Actions configuration..."
# Check if Actions are enabled
if grep -q "^\[actions\]" "$FORGEJO_CONFIG"; then
echo "✅ Actions section found in config"
grep -A 5 "^\[actions\]" "$FORGEJO_CONFIG" || true
else
echo "⚠️ Actions section not found in config"
echo "Adding Actions configuration..."
cat >> "$FORGEJO_CONFIG" << 'CONFIG'
[actions]
ENABLED = true
DEFAULT_ACTIONS_URL = https://code.forgejo.org
CONFIG
echo "✅ Actions configuration added"
systemctl restart forgejo
sleep 5
fi
echo ""
echo "🏃 Checking for Forgejo Runner..."
# Check if act runner is installed
if command -v act_runner &> /dev/null; then
echo "✅ act_runner is installed"
act_runner --version || true
else
echo "❌ act_runner is not installed"
echo "Installing act_runner..."
# Download and install act_runner
cd /tmp
wget -q https://dl.gitea.com/act_runner/latest/act_runner-linux-amd64 -O act_runner
chmod +x act_runner
mv act_runner /usr/local/bin/
echo "✅ act_runner installed"
fi
# Check if runner is registered
if systemctl is-active --quiet act_runner 2>/dev/null; then
echo "✅ Runner service is running"
else
echo "⚠️ Runner service is not running or not configured"
echo ""
echo "To register the runner:"
echo "1. Get registration token from Forgejo:"
echo " Site Admin → Actions → Runners → Create runner"
echo ""
echo "2. Register the runner:"
echo " act_runner register --no-interactive \\"
echo " --instance https://code.mnemo-cards.online \\"
echo " --token YOUR_TOKEN_HERE \\"
echo " --name default-runner"
echo ""
echo "3. Create systemd service:"
cat > /tmp/act_runner_service.txt << 'SERVICE'
[Unit]
Description=Forgejo Actions Runner
After=network.target
[Service]
Type=simple
User=forgejo
WorkingDirectory=/var/lib/forgejo
ExecStart=/usr/local/bin/act_runner daemon
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
SERVICE
echo "Save this to /etc/systemd/system/act_runner.service"
cat /tmp/act_runner_service.txt
fi
echo ""
echo "📊 Summary:"
echo " - Forgejo: $(systemctl is-active forgejo || echo 'not running')"
echo " - act_runner installed: $(command -v act_runner &> /dev/null && echo 'yes' || echo 'no')"
echo " - Runner service: $(systemctl is-active act_runner 2>/dev/null || echo 'not configured')"
echo ""
echo "📝 Next steps:"
echo "1. Go to https://code.mnemo-cards.online/admin/actions/runners"
echo "2. Click 'Create new Runner'"
echo "3. Copy the registration token"
echo "4. Run this on the server:"
echo " act_runner register --no-interactive \\"
echo " --instance https://code.mnemo-cards.online \\"
echo " --token YOUR_TOKEN \\"
echo " --name default-runner"
echo "5. Enable and start the service:"
echo " systemctl enable act_runner"
echo " systemctl start act_runner"
EOF
echo ""
echo "✅ Forgejo Actions setup check completed!"
echo ""
echo "🌐 Open Forgejo: https://code.mnemo-cards.online"
echo "🔑 Login as: cinnabarflower"
echo "⚙️ Admin panel: https://code.mnemo-cards.online/admin/actions/runners"