Skip to content

Commit 737c8ee

Browse files
Refactor CI/CD workflow to improve deployment and rollback processes
1 parent d1c4bf5 commit 737c8ee

File tree

1 file changed

+122
-123
lines changed

1 file changed

+122
-123
lines changed

.github/workflows/main.yml

Lines changed: 122 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,124 @@
1-
name: CI/CD Workflow --> Deploy and Run E2E Tests
2-
3-
on:
4-
pull_request:
5-
push:
6-
branches:
7-
- main
8-
release:
9-
types: [created]
10-
11-
jobs:
12-
deploy:
13-
name: Deploy to Vercel
14-
runs-on: ubuntu-latest
15-
16-
steps:
17-
- name: Checkout Code
18-
uses: actions/checkout@v3
19-
20-
- name: Install Vercel CLI
21-
run: npm install --global vercel@latest
22-
23-
- name: Pull Vercel Environment Information
24-
run: |
25-
if [[ "${{ github.event_name }}" == "release" ]]; then
26-
vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
27-
else
28-
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
29-
fi
30-
31-
- name: Build Project Artifacts
32-
run: |
33-
if [[ "${{ github.event_name }}" == "release" ]]; then
34-
vercel build --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
35-
else
36-
vercel build --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
37-
fi
38-
39-
- name: Deploy to Vercel
40-
id: deploy
41-
run: |
42-
if [[ "${{ github.event_name }}" == "release" ]]; then
43-
DEPLOY_URL=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1)
44-
else
45-
DEPLOY_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1)
46-
fi
47-
echo "DEPLOYMENT_URL=${DEPLOY_URL}" >> $GITHUB_ENV
48-
echo "Deployed to: $DEPLOY_URL"
49-
50-
env:
51-
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
52-
53-
e2e:
54-
name: Run E2E Tests
55-
runs-on: ubuntu-latest
56-
needs: deploy
57-
58-
steps:
59-
- name: Checkout Code
60-
uses: actions/checkout@v3
61-
62-
- name: Install pnpm
63-
run: npm install -g pnpm
64-
65-
- name: Install Dependencies
66-
run: pnpm install
67-
68-
- name: Install Playwright
69-
run: pnpm playwright install
70-
71-
- name: Run Playwright Tests
72-
run: pnpm playwright test
73-
env:
74-
BASE_URL: ${{ env.DEPLOYMENT_URL }}
75-
76-
77-
#notify:
78-
# name: Notify Team on Failure
79-
# runs-on: ubuntu-latest
80-
# needs: e2e
81-
# if: failure()
82-
# steps:
83-
# - name: Send Slack Notification
84-
# uses: slackapi/[email protected]
85-
# with:
86-
# payload: |
87-
# {
88-
# "text": "🚨 Production deployment failed! Check logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
89-
# }
90-
# env:
91-
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
1+
# name: CI/CD Workflow --> Deploy and Run E2E Tests
2+
3+
# on:
4+
# pull_request:
5+
# push:
6+
# branches:
7+
# - main
8+
# release:
9+
# types: [created]
10+
11+
# jobs:
12+
# deploy:
13+
# name: Deploy to Vercel
14+
# runs-on: ubuntu-latest
15+
16+
# steps:
17+
# - name: Checkout Code
18+
# uses: actions/checkout@v3
19+
20+
# - name: Install Vercel CLI
21+
# run: npm install --global vercel@latest
22+
23+
# - name: Pull Vercel Environment Information
24+
# run: |
25+
# if [[ "${{ github.event_name }}" == "release" ]]; then
26+
# vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
27+
# else
28+
# vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
29+
# fi
30+
31+
# - name: Build Project Artifacts
32+
# run: |
33+
# if [[ "${{ github.event_name }}" == "release" ]]; then
34+
# vercel build --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
35+
# else
36+
# vercel build --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
37+
# fi
38+
39+
# - name: Deploy to Vercel
40+
# id: deploy
41+
# run: |
42+
# if [[ "${{ github.event_name }}" == "release" ]]; then
43+
# DEPLOY_URL=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1)
44+
# else
45+
# DEPLOY_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1)
46+
# fi
47+
# echo "DEPLOYMENT_URL=${DEPLOY_URL}" >> $GITHUB_ENV
48+
# echo "Deployed to: $DEPLOY_URL"
49+
50+
# env:
51+
# VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
52+
53+
# e2e:
54+
# name: Run E2E Tests
55+
# runs-on: ubuntu-latest
56+
# needs: deploy
57+
58+
# steps:
59+
# - name: Checkout Code
60+
# uses: actions/checkout@v3
61+
62+
# - name: Install pnpm
63+
# run: npm install -g pnpm
64+
65+
# - name: Install Dependencies
66+
# run: pnpm install
67+
68+
# - name: Install Playwright
69+
# run: pnpm playwright install
70+
71+
# - name: Run Playwright Tests
72+
# run: pnpm playwright test
73+
# env:
74+
# BASE_URL: ${{ env.DEPLOYMENT_URL }}
75+
76+
#notify:
77+
# name: Notify Team on Failure
78+
# runs-on: ubuntu-latest
79+
# needs: e2e
80+
# if: failure()
81+
# steps:
82+
# - name: Send Slack Notification
83+
# uses: slackapi/[email protected]
84+
# with:
85+
# payload: |
86+
# {
87+
# "text": "🚨 Production deployment failed! Check logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
88+
# }
89+
# env:
90+
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
9291

9392
# rollback:
94-
# name: Rollback on Failure
95-
# runs-on: ubuntu-latest
96-
# needs: e2e
97-
# if: failure()
98-
99-
# steps:
100-
# - name: Checkout Code
101-
# uses: actions/checkout@v3
102-
103-
# - name: Install Vercel CLI
104-
# run: npm install --global vercel@latest
105-
106-
# - name: Authenticate Vercel CLI
107-
# run: vercel login --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
108-
109-
# - name: Get Last Successful Production Deployment
110-
# id: get_last_deployment
111-
# run: |
112-
# echo "Fetching last successful production deployment..."
113-
# LAST_DEPLOYMENT=$(vercel list --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | grep -Eo 'https://[a-zA-Z0-9.-]+\.vercel\.app' | tail -1)
114-
# if [[ -z "$LAST_DEPLOYMENT" ]]; then
115-
# echo "❌ No previous successful deployment found! Rollback failed."
116-
# exit 1
117-
# fi
118-
# echo "✅ Last successful deployment found: $LAST_DEPLOYMENT"
119-
# echo "LAST_DEPLOYMENT=$LAST_DEPLOYMENT" >> $GITHUB_ENV
120-
121-
# - name: Rollback to Last Working Deployment
122-
# run: |
123-
# echo "Rolling back to: $LAST_DEPLOYMENT"
124-
# vercel promote $LAST_DEPLOYMENT --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
125-
# echo "✅ Rollback successful! Restored $LAST_DEPLOYMENT"
93+
# name: Rollback on Failure
94+
# runs-on: ubuntu-latest
95+
# needs: e2e
96+
# if: failure()
97+
98+
# steps:
99+
# - name: Checkout Code
100+
# uses: actions/checkout@v3
101+
102+
# - name: Install Vercel CLI
103+
# run: npm install --global vercel@latest
104+
105+
# - name: Authenticate Vercel CLI
106+
# run: vercel login --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
107+
108+
# - name: Get Last Successful Production Deployment
109+
# id: get_last_deployment
110+
# run: |
111+
# echo "Fetching last successful production deployment..."
112+
# LAST_DEPLOYMENT=$(vercel list --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | grep -Eo 'https://[a-zA-Z0-9.-]+\.vercel\.app' | tail -1)
113+
# if [[ -z "$LAST_DEPLOYMENT" ]]; then
114+
# echo "❌ No previous successful deployment found! Rollback failed."
115+
# exit 1
116+
# fi
117+
# echo "✅ Last successful deployment found: $LAST_DEPLOYMENT"
118+
# echo "LAST_DEPLOYMENT=$LAST_DEPLOYMENT" >> $GITHUB_ENV
119+
120+
# - name: Rollback to Last Working Deployment
121+
# run: |
122+
# echo "Rolling back to: $LAST_DEPLOYMENT"
123+
# vercel promote $LAST_DEPLOYMENT --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }}
124+
# echo "✅ Rollback successful! Restored $LAST_DEPLOYMENT"

0 commit comments

Comments
 (0)