Repository navigation
Update server #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy | |
| on: | |
| push: | |
| branches: | |
| - build | |
| jobs: | |
| web-deploy: | |
| name: π Deploy | |
| runs-on: ubuntu-latest | |
| environment: deploy | |
| steps: | |
| - name: π Get latest code | |
| uses: actions/checkout@v4 | |
| # Step 1: Prepare .env for migrations (dev/staging) | |
| - name: π§© Prepare .env for migrations | |
| run: | | |
| if [ ! -f .env ]; then | |
| cp .env.example .env | |
| fi | |
| # Dev environment for migrations | |
| sed -i 's/^APP_ENV=.*/APP_ENV=development/' .env | |
| sed -i 's/^APP_DEBUG=.*/APP_DEBUG=true/' .env | |
| sed -i 's|^APP_URL=.*|APP_URL="http://staging.patronmonitoring.cz/"|' .env | |
| # DB settings | |
| sed -i "s/^#\? *DB_CONNECTION=.*/DB_CONNECTION=${{ vars.DB_CONNECTION }}/" .env | |
| sed -i "s/^#\? *DB_HOST=.*/DB_HOST=${{ secrets.DB_HOST }}/" .env | |
| sed -i "s/^#\? *DB_PORT=.*/DB_PORT=${{ secrets.DB_PORT }}/" .env | |
| sed -i "s/^#\? *DB_DATABASE=.*/DB_DATABASE=${{ secrets.DB_DATABASE }}/" .env | |
| sed -i "s/^#\? *DB_USERNAME=.*/DB_USERNAME=${{ secrets.DB_USERNAME }}/" .env | |
| sed -i "s/^#\? *DB_PASSWORD=.*/DB_PASSWORD=${{ secrets.DB_PASSWORD }}/" .env | |
| - name: π§° Set up PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.2' | |
| extensions: mbstring, bcmath, intl | |
| tools: composer | |
| - name: π¦ Install Composer dependencies | |
| run: composer install --no-dev --optimize-autoloader | |
| - name: π§° Use Node.js 20 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: π¨ Build Project | |
| run: | | |
| npm ci | |
| npm run build | |
| # Step 2: Run migrations in dev/staging | |
| - name: β‘ Run migrations (staging/dev) | |
| uses: appleboy/ssh-action@v1.1.0 | |
| with: | |
| host: ${{ secrets.SSH_SERVER }} | |
| username: ${{ secrets.SSH_USER }} | |
| password: ${{ secrets.SSH_PASSWORD }} | |
| port: 22 | |
| script: | | |
| cd storage/d943a45e/7a1f73c9-0571-4b5b-afbf-80d3effbc62f/nyoncode.cz/www | |
| php8.2 artisan migrate --force | |
| # Step 3: Switch .env to production | |
| - name: π§© Switch .env to production | |
| run: | | |
| sed -i 's/^APP_ENV=.*/APP_ENV=production/' .env | |
| sed -i 's/^APP_DEBUG=.*/APP_DEBUG=false/' .env | |
| sed -i 's|^APP_URL=.*|APP_URL="http://patronmonitoring.cz/"|' .env | |
| - name: π Deploy via FTP | |
| uses: SamKirkland/FTP-Deploy-Action@v4.3.5 | |
| with: | |
| server: ${{ secrets.FTP_SERVER }} | |
| username: ${{ secrets.FTP_USER }} | |
| password: ${{ secrets.FTP_PASSWORD }} | |
| server-dir: ${{ vars.FTP_SERVER_DIR }} | |
| exclude: | | |
| **/.git* | |
| **/node_modules/** | |
| **/vendor/** | |
| # Step 4: Run production commands (without migrations) | |
| - name: βοΈ Run Composer & Artisan Commands (production) | |
| uses: appleboy/ssh-action@v1.1.0 | |
| with: | |
| host: ${{ secrets.SSH_SERVER }} | |
| username: ${{ secrets.SSH_USER }} | |
| password: ${{ secrets.SSH_PASSWORD }} | |
| port: 22 | |
| script: | | |
| cd storage/d943a45e/7a1f73c9-0571-4b5b-afbf-80d3effbc62f/nyoncode.cz/www | |
| composer install --no-dev --optimize-autoloader | |
| php8.2 artisan optimize:clear | |
| php8.2 artisan storage:link | |
| php8.2 artisan optimize | |
| echo "Migrations skipped in production" |