Skip to content

Force add test_connection_status.php for debugging #12

Force add test_connection_status.php for debugging

Force add test_connection_status.php for debugging #12

Workflow file for this run

name: Deploy to Production
on:
push:
branches:
- main
workflow_dispatch:
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: pdo, pdo_mysql, mysqli, mbstring, openssl
coverage: none
- name: Validate composer.json
run: composer validate --strict
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Check PHP syntax
run: find . -name "*.php" ! -path "./vendor/*" -exec php -l {} \;
- name: Create test .env file
run: |
cp .env.example .env
echo "DB_HOST=localhost" >> .env
echo "DB_NAME=smart_tailoring_test" >> .env
echo "DB_USER=root" >> .env
echo "DB_PASS=" >> .env
- name: Setup MySQL
run: |
sudo systemctl start mysql
mysql -uroot -proot -e "CREATE DATABASE smart_tailoring_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
- name: Run database migrations
run: php database/migrate.php run
- name: Test database connection
run: php -r "require 'vendor/autoload.php'; require 'config/db.php'; \$pdo = getDatabaseConnection(); echo 'Database connected successfully';"
deploy:
name: Deploy to Server
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install --no-dev --optimize-autoloader
- name: Create deployment package
run: |
mkdir -p deploy
rsync -av --exclude='.git' \
--exclude='.github' \
--exclude='deploy' \
--exclude='.env' \
--exclude='*.md' \
--exclude='composer.lock' \
--exclude='node_modules' \
. deploy/
- name: Deploy via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
# Create backup
cd ${{ secrets.DEPLOY_PATH }}
if [ -d "smart-tailoring" ]; then
cp -r smart-tailoring smart-tailoring-backup-$(date +%Y%m%d-%H%M%S)
fi
# Remove old deployment directory
rm -rf smart-tailoring-temp
# Create fresh deployment directory
mkdir -p smart-tailoring-temp
- name: Copy files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
source: "deploy/*"
target: "${{ secrets.DEPLOY_PATH }}/smart-tailoring-temp"
strip_components: 1
- name: Finalize deployment
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ${{ secrets.DEPLOY_PATH }}
# Copy .env from old deployment if exists
if [ -f "smart-tailoring/.env" ]; then
cp smart-tailoring/.env smart-tailoring-temp/.env
fi
# Set proper permissions
find smart-tailoring-temp -type d -exec chmod 755 {} \;
find smart-tailoring-temp -type f -exec chmod 644 {} \;
chmod 755 smart-tailoring-temp/uploads/profiles
chmod 755 smart-tailoring-temp/uploads/shops
# Run migrations
cd smart-tailoring-temp
php database/migrate.php run
# Swap directories (atomic deployment)
cd ${{ secrets.DEPLOY_PATH }}
if [ -d "smart-tailoring" ]; then
mv smart-tailoring smart-tailoring-old
fi
mv smart-tailoring-temp smart-tailoring
rm -rf smart-tailoring-old
# Clear PHP opcache if available
if command -v php &> /dev/null; then
php -r "if (function_exists('opcache_reset')) { opcache_reset(); }"
fi
- name: Health check
run: |
sleep 5
curl -f ${{ secrets.APP_URL }}/api/health.php || exit 1
- name: Notify deployment status
if: always()
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "✅ Deployment successful!"
else
echo "❌ Deployment failed!"
exit 1
fi