Skip to content

Commit 8ed85a4

Browse files
committed
Update deploy.yml
1 parent 3229c98 commit 8ed85a4

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed
Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@ on:
55
branches:
66
- main
77
- develop
8+
workflow_dispatch:
9+
inputs:
10+
environment:
11+
description: 'Environment to deploy to'
12+
required: true
13+
default: 'staging'
14+
type: choice
15+
options:
16+
- staging
17+
- production
18+
test_mode:
19+
description: 'Run in test mode (no actual deployment)'
20+
required: false
21+
default: false
22+
type: boolean
823

924
jobs:
1025
backend:
1126
name: Deploy Backend
1227
runs-on: ubuntu-latest
1328

1429
steps:
15-
- uses: actions/checkout@v2
30+
- uses: actions/checkout@v3
1631

1732
- name: Setup PHP
1833
uses: shivammathur/setup-php@v2
@@ -42,19 +57,34 @@ jobs:
4257

4358
- name: Set Deployment Environment
4459
run: |
45-
if [[ "${{ github.ref_name }}" == "develop" ]]; then
60+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
61+
echo "VAPOR_ENV=${{ github.event.inputs.environment }}" >> "$GITHUB_ENV"
62+
echo "TEST_MODE=${{ github.event.inputs.test_mode }}" >> "$GITHUB_ENV"
63+
elif [[ "${{ github.ref_name }}" == "develop" ]]; then
4664
echo "VAPOR_ENV=staging" >> "$GITHUB_ENV"
65+
echo "TEST_MODE=false" >> "$GITHUB_ENV"
4766
else
4867
echo "VAPOR_ENV=production" >> "$GITHUB_ENV"
68+
echo "TEST_MODE=false" >> "$GITHUB_ENV"
4969
fi
5070
5171
- name: Log Branch and Environment
5272
run: |
53-
echo "🚀 Deploying branch ${{ github.ref_name }} to Vapor environment: $VAPOR_ENV"
73+
echo "🚀 Deploying branch ${{ github.ref_name }} to Vapor environment: ${{ env.VAPOR_ENV }}"
74+
echo "🧪 Test mode: ${{ env.TEST_MODE }}"
75+
76+
- name: Validate Deployment Configuration
77+
working-directory: ./backend
78+
run: |
79+
if [[ "${{ env.TEST_MODE }}" == "true" ]]; then
80+
echo "✅ TEST MODE: Would deploy to ${{ env.VAPOR_ENV }} environment"
81+
echo "vapor deploy ${{ env.VAPOR_ENV }} --dry-run"
82+
exit 0
83+
fi
5484
5585
- name: Deploy to Vapor
5686
working-directory: ./backend
57-
run: vapor deploy $VAPOR_ENV
87+
run: vapor deploy ${{ env.VAPOR_ENV }}
5888
env:
5989
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
6090

@@ -64,24 +94,46 @@ jobs:
6494
needs: backend
6595

6696
steps:
67-
- uses: actions/checkout@v2
97+
- uses: actions/checkout@v3
6898

6999
- name: Set Deployment Environment
70100
run: |
71-
if [[ "${{ github.ref_name }}" == "develop" ]]; then
101+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
102+
if [[ "${{ github.event.inputs.environment }}" == "staging" ]]; then
103+
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_STAGING_APP_ID }}" >> "$GITHUB_ENV"
104+
else
105+
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}" >> "$GITHUB_ENV"
106+
fi
107+
echo "TEST_MODE=${{ github.event.inputs.test_mode }}" >> "$GITHUB_ENV"
108+
elif [[ "${{ github.ref_name }}" == "develop" ]]; then
72109
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_STAGING_APP_ID }}" >> "$GITHUB_ENV"
110+
echo "TEST_MODE=false" >> "$GITHUB_ENV"
73111
else
74112
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}" >> "$GITHUB_ENV"
113+
echo "TEST_MODE=false" >> "$GITHUB_ENV"
75114
fi
76115
116+
- name: Log Environment Settings
117+
run: |
118+
echo "🚀 Deploying frontend to DigitalOcean App: ${{ env.DO_APP_ID }}"
119+
echo "🧪 Test mode: ${{ env.TEST_MODE }}"
120+
121+
- name: Validate Deployment Configuration (Test Mode)
122+
if: env.TEST_MODE == 'true'
123+
run: |
124+
echo "✅ TEST MODE: Would trigger deployment for DigitalOcean App: ${{ env.DO_APP_ID }}"
125+
echo "curl -X POST 'https://api.digitalocean.com/v2/apps/${{ env.DO_APP_ID }}/deployments'"
126+
exit 0
127+
77128
- name: Trigger Deployment on DigitalOcean
129+
if: env.TEST_MODE != 'true'
78130
id: trigger_deployment
79131
run: |
80132
RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X POST "https://api.digitalocean.com/v2/apps/$DO_APP_ID/deployments" \
81133
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_API_TOKEN }}" \
82134
-H "Content-Type: application/json")
83135
84-
if [ "$RESPONSE" -ne 200 ]; then
136+
if [ "$RESPONSE" -ne 201 ] && [ "$RESPONSE" -ne 200 ]; then
85137
ERROR_MSG=$(jq -r '.message // "Unknown error occurred."' response.json)
86138
echo "❌ Failed to trigger deployment. HTTP Status: $RESPONSE. Error: $ERROR_MSG"
87139
exit 1
@@ -99,7 +151,9 @@ jobs:
99151
echo "deployment_id=$DEPLOYMENT_ID" >> "$GITHUB_ENV"
100152
101153
- name: Poll Deployment Status
154+
if: env.TEST_MODE != 'true'
102155
run: |
156+
# Increase MAX_RETRIES or SLEEP_TIME if your deployments take longer
103157
MAX_RETRIES=30
104158
SLEEP_TIME=10
105159
COUNTER=0

0 commit comments

Comments
 (0)