Skip to content

Instantly share code, notes, and snippets.

@abdullahainun
Last active June 18, 2026 09:28
Show Gist options
  • Select an option

  • Save abdullahainun/e074729011ad39e786fbbb067a944b37 to your computer and use it in GitHub Desktop.

Select an option

Save abdullahainun/e074729011ad39e786fbbb067a944b37 to your computer and use it in GitHub Desktop.
name: CI/CD
on:
push:
branches: [main]
tags: ["v*.*.*"]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, pdo, pdo_mysql, bcmath, ctype, fileinfo
coverage: none
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
restore-keys: composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Copy .env
run: cp .env.example .env
- name: Generate app key
run: php artisan key:generate
- name: Lint (Laravel Pint)
run: ./vendor/bin/pint --test
- name: Run tests
run: php artisan test --parallel
deploy-dev-stg:
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: staging
steps:
- name: Deploy to Dev & Staging
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT || 22 }}
script: |
set -e
echo "=== Deploy Dev ==="
cd ${{ secrets.APP_DEV_PATH }}
git pull origin main
composer install --no-dev --optimize-autoloader --no-interaction
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
php artisan queue:restart
echo "Dev selesai: $(date)"
echo "=== Deploy Staging ==="
cd ${{ secrets.APP_STG_PATH }}
git pull origin main
composer install --no-dev --optimize-autoloader --no-interaction
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
php artisan queue:restart
echo "Staging selesai: $(date)"
deploy-prod:
needs: test
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
environment: production
steps:
- name: Deploy to Production
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT || 22 }}
script: |
set -e
echo "=== Deploy Production (${{ github.ref_name }}) ==="
cd ${{ secrets.APP_PROD_PATH }}
git pull origin main
composer install --no-dev --optimize-autoloader --no-interaction
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
php artisan queue:restart
echo "Production selesai: $(date)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment