Skip to content

fix indentation

fix indentation #25

name: Deploy to Vapor and Frontend
on:
push:
branches:
- main
- feat/front-end-deployment
jobs:
backend:
name: Deploy Backend to Vapor
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2
coverage: none
- name: Prepare Laravel Environment
working-directory: ./backend
run: |
mkdir -p bootstrap/cache
chmod -R 775 bootstrap/cache
- name: Prepare HTMLPurifier Cache Directory
working-directory: ./backend
run: |
mkdir -p storage/app/htmlpurifier
chmod -R 775 storage/app/htmlpurifier
- name: Install Dependencies
working-directory: ./backend
run: composer install --no-dev --no-progress --no-scripts --optimize-autoloader
- name: Install Vapor CLI
run: composer global require laravel/vapor-cli
- name: Log Branch
run: echo "Deploying branch ${{ github.ref_name }} to Vapor"
- name: Deploy to Vapor Production
working-directory: ./backend
run: vapor deploy production
env:
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
frontend:
name: Deploy Frontend
runs-on: ubuntu-latest
needs: backend
steps:
- uses: actions/checkout@v2
- name: Trigger Deployment on DigitalOcean
id: trigger_deployment
run: |
RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X POST "https://api.digitalocean.com/v2/apps/${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}/deployments" \
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}" \
-H "Content-Type: application/json")
if [ "$RESPONSE" -ne 200 ]; then
echo "Failed to trigger deployment. HTTP Status: $RESPONSE"
cat response.json
exit 1
fi
DEPLOYMENT_ID=$(jq -r '.deployment.id' response.json)
if [ "$DEPLOYMENT_ID" == "null" ]; then
echo "Failed to extract deployment ID."
cat response.json
exit 1
fi
echo "Deployment triggered successfully: $DEPLOYMENT_ID"
echo "deployment_id=$DEPLOYMENT_ID" >> "$GITHUB_ENV"
- name: Poll Deployment Status
run: |
MAX_RETRIES=20 # Max polling attempts (~10 minutes)
SLEEP_TIME=30 # Time (in seconds) between each poll
COUNTER=0
while [ $COUNTER -lt $MAX_RETRIES ]; do
RESPONSE=$(curl -s -X GET "https://api.digitalocean.com/v2/apps/${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}/deployments/${{ env.deployment_id }}" \
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}" \
-H "Content-Type: application/json")
STATUS=$(echo "$RESPONSE" | jq -r '.deployment.phase')
echo "Current Deployment Status: $STATUS"
if [ "$STATUS" == "ACTIVE" ]; then
echo "Deployment completed successfully."
exit 0
elif [[ "$STATUS" == "FAILED" || "$STATUS" == "CANCELLED" ]]; then
echo "Deployment failed or was cancelled."
exit 1
fi
COUNTER=$((COUNTER + 1))
echo "Retrying in $SLEEP_TIME seconds... ($COUNTER/$MAX_RETRIES)"
sleep $SLEEP_TIME
done
echo "Deployment timed out."
exit 1