Skip to content

Commit 268f295

Browse files
committed
Add staging
1 parent 5138974 commit 268f295

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

.github/workflows/deploy-production.yml

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ on:
44
push:
55
branches:
66
- main
7+
- develop
78
- feat/front-end-deployment
89

910
jobs:
1011
backend:
11-
name: Deploy Backend to Vapor
12+
name: Deploy Backend
1213
runs-on: ubuntu-latest
1314

1415
steps:
@@ -40,14 +41,24 @@ jobs:
4041
- name: Install Vapor CLI
4142
run: composer global require laravel/vapor-cli
4243

43-
- name: Log Branch
44-
run: echo "Deploying branch ${{ github.ref_name }} to Vapor"
44+
- name: Set Deployment Environment
45+
run: |
46+
if [[ "${{ github.ref_name }}" == "develop" ]]; then
47+
echo "VAPOR_ENV=staging" >> "$GITHUB_ENV"
48+
else
49+
echo "VAPOR_ENV=production" >> "$GITHUB_ENV"
50+
fi
4551
46-
- name: Deploy to Vapor Production
52+
- name: Log Branch and Environment
53+
run: |
54+
echo "🚀 Deploying branch ${{ github.ref_name }} to Vapor environment: $VAPOR_ENV"
55+
56+
- name: Deploy to Vapor
4757
working-directory: ./backend
48-
run: vapor deploy production
58+
run: vapor deploy $VAPOR_ENV
4959
env:
5060
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
61+
5162
frontend:
5263
name: Deploy Frontend
5364
runs-on: ubuntu-latest
@@ -56,56 +67,65 @@ jobs:
5667
steps:
5768
- uses: actions/checkout@v2
5869

70+
- name: Set Deployment Environment
71+
run: |
72+
if [[ "${{ github.ref_name }}" == "develop" ]]; then
73+
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_STAGING_APP_ID }}" >> "$GITHUB_ENV"
74+
else
75+
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}" >> "$GITHUB_ENV"
76+
fi
77+
5978
- name: Trigger Deployment on DigitalOcean
6079
id: trigger_deployment
6180
run: |
62-
RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X POST "https://api.digitalocean.com/v2/apps/${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}/deployments" \
81+
RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X POST "https://api.digitalocean.com/v2/apps/$DO_APP_ID/deployments" \
6382
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_API_TOKEN }}" \
6483
-H "Content-Type: application/json")
65-
84+
6685
if [ "$RESPONSE" -ne 200 ]; then
67-
echo "Failed to trigger deployment. HTTP Status: $RESPONSE"
68-
cat response.json
86+
ERROR_MSG=$(jq -r '.message // "Unknown error occurred."' response.json)
87+
echo "❌ Failed to trigger deployment. HTTP Status: $RESPONSE. Error: $ERROR_MSG"
6988
exit 1
7089
fi
71-
90+
7291
DEPLOYMENT_ID=$(jq -r '.deployment.id' response.json)
7392
if [ "$DEPLOYMENT_ID" == "null" ]; then
74-
echo "Failed to extract deployment ID."
75-
cat response.json
93+
echo "❌ Failed to extract deployment ID."
7694
exit 1
7795
fi
78-
79-
echo "Deployment triggered successfully: $DEPLOYMENT_ID"
96+
97+
echo "::add-mask::$DEPLOYMENT_ID"
98+
echo "✅ Deployment triggered successfully."
99+
80100
echo "deployment_id=$DEPLOYMENT_ID" >> "$GITHUB_ENV"
81101
82102
- name: Poll Deployment Status
83103
run: |
84-
MAX_RETRIES=30
85-
SLEEP_TIME=10
104+
MAX_RETRIES=30
105+
SLEEP_TIME=10
86106
COUNTER=0
87-
107+
88108
while [ $COUNTER -lt $MAX_RETRIES ]; do
89-
RESPONSE=$(curl -s -X GET "https://api.digitalocean.com/v2/apps/${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}/deployments/${{ env.deployment_id }}" \
109+
RESPONSE=$(curl -s -X GET "https://api.digitalocean.com/v2/apps/$DO_APP_ID/deployments/${{ env.deployment_id }}" \
90110
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_API_TOKEN }}" \
91111
-H "Content-Type: application/json")
92-
112+
93113
STATUS=$(echo "$RESPONSE" | jq -r '.deployment.phase')
94-
95-
echo "Current Deployment Status: $STATUS"
96-
114+
115+
echo "🔄 Deployment Status: $STATUS"
116+
97117
if [ "$STATUS" == "ACTIVE" ]; then
98-
echo "Deployment completed successfully."
118+
echo "Deployment completed successfully."
99119
exit 0
100120
elif [[ "$STATUS" == "FAILED" || "$STATUS" == "CANCELLED" ]]; then
101-
echo "Deployment failed or was cancelled."
121+
echo "Deployment failed or was cancelled."
102122
exit 1
103123
fi
104-
124+
105125
COUNTER=$((COUNTER + 1))
106-
echo "Retrying in $SLEEP_TIME seconds... ($COUNTER/$MAX_RETRIES)"
126+
echo "Retrying in $SLEEP_TIME seconds... ($COUNTER/$MAX_RETRIES)"
107127
sleep $SLEEP_TIME
108128
done
109-
110-
echo "Deployment timed out."
129+
130+
echo "Deployment timed out."
111131
exit 1

0 commit comments

Comments
 (0)