-
Notifications
You must be signed in to change notification settings - Fork 321
120 lines (103 loc) · 4.06 KB
/
Copy pathrollback.yml
File metadata and controls
120 lines (103 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Rollback Deployment
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to rollback'
required: true
default: 'staging'
type: choice
options:
- staging
- production
version:
description: 'Version to rollback to'
required: true
type: string
reason:
description: 'Reason for rollback'
required: false
type: string
jobs:
rollback:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build
env:
NEXT_PUBLIC_APP_ENV: ${{ github.event.inputs.environment }}
NEXT_PUBLIC_API_BASE_URL: ${{ github.event.inputs.environment == 'production' && secrets.PRODUCTION_API_URL || secrets.STAGING_API_URL }}
- name: Deploy rollback to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: ${{ github.event.inputs.environment == 'production' && '--prod' || '' }}
- name: Verify rollback
run: |
sleep 30 # Wait for deployment to propagate
if [ "${{ github.event.inputs.environment }}" == "production" ]; then
url="https://stellarlend.com"
else
url="https://stellarlend-staging.vercel.app"
fi
response=$(curl -s -o /dev/null -w "%{http_code}" $url)
if [ "$response" != "200" ]; then
echo "Rollback verification failed - site not responding"
exit 1
fi
echo "Rollback verification successful"
- name: Create rollback issue
uses: actions/github-script@v7
with:
script: |
const { data: issue } = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `🔄 Rollback: ${{ github.event.inputs.environment }} to ${{ github.event.inputs.version }}`,
body: `## Rollback Executed
**Environment:** ${{ github.event.inputs.environment }}
**Rolled back to:** ${{ github.event.inputs.version }}
**Reason:** ${{ github.event.inputs.reason || 'Not specified' }}
**Executed by:** @${{ github.actor }}
**Timestamp:** ${new Date().toISOString()}
## Next Steps
- [ ] Verify rollback is working correctly
- [ ] Investigate root cause of the issue
- [ ] Plan fix for the original problem
- [ ] Schedule re-deployment when ready
## Verification
- ✅ Deployment completed successfully
- ✅ Health check passed
`,
labels: ['rollback', 'urgent', '${{ github.event.inputs.environment }}']
});
- name: Notify team of rollback
if: always() && env.SLACK_WEBHOOK_URL != ''
uses: 8398a7/action-slack@v3
with:
status: success
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
text: |
🔄 **Rollback Completed**
**Environment:** ${{ github.event.inputs.environment }}
**Version:** ${{ github.event.inputs.version }}
**Reason:** ${{ github.event.inputs.reason || 'Not specified' }}
**Executed by:** ${{ github.actor }}
Please verify the rollback and investigate the original issue.