@@ -49,117 +49,3 @@ jobs:
4949
5050 - name : Test database connection
5151 run : php -r "require 'vendor/autoload.php'; require 'config/db.php'; if (isset(\$conn) && \$conn instanceof mysqli) { echo 'Database connected successfully'; } else { echo 'Database connection failed'; exit(1); }"
52-
53- deploy :
54- name : Deploy to Server
55- runs-on : ubuntu-latest
56- needs : test
57- if : github.ref == 'refs/heads/main'
58-
59- steps :
60- - name : Checkout code
61- uses : actions/checkout@v3
62-
63- - name : Setup PHP
64- uses : shivammathur/setup-php@v2
65- with :
66- php-version : ' 8.2'
67-
68- - name : Install dependencies
69- run : composer install --no-dev --optimize-autoloader
70-
71- - name : Create deployment package
72- run : |
73- mkdir -p deploy
74- rsync -av --exclude='.git' \
75- --exclude='.github' \
76- --exclude='deploy' \
77- --exclude='.env' \
78- --exclude='*.md' \
79- --exclude='composer.lock' \
80- --exclude='node_modules' \
81- . deploy/
82-
83- - name : Deploy via SSH
84- uses : appleboy/ssh-action@master
85- with :
86- host : ${{ secrets.SSH_HOST }}
87- username : ${{ secrets.SSH_USER }}
88- key : ${{ secrets.SSH_PRIVATE_KEY }}
89- port : ${{ secrets.SSH_PORT }}
90- script : |
91- # Create backup
92- cd ${{ secrets.DEPLOY_PATH }}
93- if [ -d "smart-tailoring" ]; then
94- cp -r smart-tailoring smart-tailoring-backup-$(date +%Y%m%d-%H%M%S)
95- fi
96-
97- # Remove old deployment directory
98- rm -rf smart-tailoring-temp
99-
100- # Create fresh deployment directory
101- mkdir -p smart-tailoring-temp
102-
103- - name : Copy files to server
104- uses : appleboy/scp-action@master
105- with :
106- host : ${{ secrets.SSH_HOST }}
107- username : ${{ secrets.SSH_USER }}
108- key : ${{ secrets.SSH_PRIVATE_KEY }}
109- port : ${{ secrets.SSH_PORT }}
110- source : " deploy/*"
111- target : " ${{ secrets.DEPLOY_PATH }}/smart-tailoring-temp"
112- strip_components : 1
113-
114- - name : Finalize deployment
115- uses : appleboy/ssh-action@master
116- with :
117- host : ${{ secrets.SSH_HOST }}
118- username : ${{ secrets.SSH_USER }}
119- key : ${{ secrets.SSH_PRIVATE_KEY }}
120- port : ${{ secrets.SSH_PORT }}
121- script : |
122- cd ${{ secrets.DEPLOY_PATH }}
123-
124- # Copy .env from old deployment if exists
125- if [ -f "smart-tailoring/.env" ]; then
126- cp smart-tailoring/.env smart-tailoring-temp/.env
127- fi
128-
129- # Set proper permissions
130- find smart-tailoring-temp -type d -exec chmod 755 {} \;
131- find smart-tailoring-temp -type f -exec chmod 644 {} \;
132- chmod 755 smart-tailoring-temp/uploads/profiles
133- chmod 755 smart-tailoring-temp/uploads/shops
134-
135- # Run migrations
136- cd smart-tailoring-temp
137- php database/migrate.php run
138-
139- # Swap directories (atomic deployment)
140- cd ${{ secrets.DEPLOY_PATH }}
141- if [ -d "smart-tailoring" ]; then
142- mv smart-tailoring smart-tailoring-old
143- fi
144- mv smart-tailoring-temp smart-tailoring
145- rm -rf smart-tailoring-old
146-
147- # Clear PHP opcache if available
148- if command -v php &> /dev/null; then
149- php -r "if (function_exists('opcache_reset')) { opcache_reset(); }"
150- fi
151-
152- - name : Health check
153- run : |
154- sleep 5
155- curl -f ${{ secrets.APP_URL }}/api/health.php || exit 1
156-
157- - name : Notify deployment status
158- if : always()
159- run : |
160- if [ "${{ job.status }}" == "success" ]; then
161- echo "✅ Deployment successful!"
162- else
163- echo "❌ Deployment failed!"
164- exit 1
165- fi
0 commit comments