|
| 1 | +name: Deploy Main Branch |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + # 1. Checkout the repository |
| 14 | + - name: Checkout Code |
| 15 | + uses: actions/checkout@v3 |
| 16 | + |
| 17 | + # 2. Set up PHP |
| 18 | + - name: Setup PHP |
| 19 | + uses: shivammathur/setup-php@v2 |
| 20 | + with: |
| 21 | + php-version: '8.3' |
| 22 | + |
| 23 | + # 3. Install Composer dependencies |
| 24 | + - name: Install Composer Dependencies |
| 25 | + run: composer install --prefer-dist --optimize-autoloader |
| 26 | + |
| 27 | + # 4. Set up the environment file and generate an application key |
| 28 | + - name: Setup .env |
| 29 | + run: | |
| 30 | + cp .env.example .env |
| 31 | + php artisan key:generate --force |
| 32 | +
|
| 33 | + # 5. Set up Bun and build front-end assets |
| 34 | + - name: Setup Bun |
| 35 | + uses: oven-sh/setup-bun@v2 |
| 36 | + |
| 37 | + - name: Install Dependencies and Build |
| 38 | + run: | |
| 39 | + bun install |
| 40 | + bun run build |
| 41 | +
|
| 42 | + # 6. Deploy via rsync over SSH |
| 43 | + - name: Deploy via Rsync over SSH |
| 44 | + uses: burnett01/rsync-deployments@7.0.2 |
| 45 | + with: |
| 46 | + switches: -avzr --delete --exclude='.env' --exclude='.htaccess' --exclude='node_modules' |
| 47 | + path: './' # Local directory to deploy |
| 48 | + remote_path: ${{ secrets.SSH_PATH }}/ |
| 49 | + remote_host: ${{ secrets.SSH_HOST }} |
| 50 | + remote_user: ${{ secrets.SSH_USERNAME }} |
| 51 | + remote_key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 52 | + remote_port: ${{ secrets.SSH_PORT }} |
| 53 | + |
| 54 | + # 7. Run remote SSH commands to finalize deployment |
| 55 | + - name: Run Remote SSH Commands |
| 56 | + uses: appleboy/ssh-action@v0.1.8 |
| 57 | + with: |
| 58 | + host: ${{ secrets.SSH_HOST }} |
| 59 | + username: ${{ secrets.SSH_USERNAME }} |
| 60 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 61 | + port: ${{ secrets.SSH_PORT }} |
| 62 | + script: | |
| 63 | + cd ${{ secrets.SSH_PATH }} |
| 64 | + php artisan migrate --force |
| 65 | + php artisan optimize:clear |
| 66 | + php artisan storage:link |
| 67 | + php artisan optimize |
| 68 | +
|
| 69 | + # 8. Set Permissions on Directories |
| 70 | + - name: Set Permissions on Directories |
| 71 | + run: | |
| 72 | + chmod -R 775 storage bootstrap/cache |
| 73 | + chmod -R 775 storage/logs |
0 commit comments