forked from dust-tt/dust
-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (137 loc) · 5.81 KB
/
deploy-and-test-front-qa.yml
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Deploy And test Front Qa
on:
pull_request:
types: [closed]
branches:
- main
paths-ignore:
- "**.md"
workflow_dispatch:
concurrency:
group: deploy_front_qa
cancel-in-progress: false
env:
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
IMAGE_NAME: front-qa
jobs:
build-and-deploy:
runs-on: ubuntu-latest
# We skip running the build and deploy if the PR contains a migration represented by the 'migration-ack' label.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'migration-ack') }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get short sha
id: short_sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: "Authenticate with Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCLOUD_SA_KEY }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
- name: Install gke-gcloud-auth-plugin
run: |
gcloud components install gke-gcloud-auth-plugin
- name: Setup kubectl
run: |
gcloud container clusters get-credentials dust-kube --region us-central1
- name: Build the image on Cloud Build
run: |
chmod +x ./k8s/cloud-build.sh
./k8s/cloud-build.sh --image-name=$IMAGE_NAME --dockerfile-path=./front/Dockerfile --working-dir=./ --dust-client-facing-url=https://front-qa.dust.tt
- name: Deploy the image on Kubernetes
run: |
chmod +x ./k8s/deploy-image.sh
./k8s/deploy-image.sh gcr.io/$GCLOUD_PROJECT_ID/$IMAGE_NAME-image:${{ steps.short_sha.outputs.short_sha }} front-qa-deployment
- name: Wait for rollout to complete
run: kubectl rollout status deployment/front-qa-deployment --timeout=10m
run-playwright-tests:
needs: build-and-deploy
runs-on: ubuntu-latest
# We skip running the build and deploy if the PR contains a migration represented by the 'migration-ack' label.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'migration-ack') }}
steps:
- name: Run Playwright Tests
id: trigger-tests
env:
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
response=$(curl -s -w "\n%{http_code}" -X POST "https://webhook.ranger.net/api/v1/tests/run" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.RANGER_API_TOKEN }}" \
-d '{
"targetUrl": "https://front-qa.dust.tt/",
"ghOwner": "'$REPO_OWNER'",
"ghRepo": "'$REPO_NAME'",
"ghCommitSha": "${{ github.sha }}"
}')
echo "$response"
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" != "202" ]; then
error=$(echo "$body" | jq -r '.error // "Unknown error"')
echo "Error: $error"
exit 1
fi
check_id=$(echo "$body" | jq -r '.data.checkId')
echo "Check ID: $check_id"
echo "CHECK_ID=$check_id" >> $GITHUB_ENV
- name: Wait for Playwright Tests To Complete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
end_time=$((SECONDS + 2700)) # 45 minutes = 2700 seconds
while [ $SECONDS -lt $end_time ]; do
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/check-runs/${CHECK_ID}")
status=$(echo "$response" | jq -r .status)
if [ "$status" = "completed" ]; then
conclusion=$(echo "$response" | jq -r .conclusion)
echo "Playwright tests completed with conclusion: $conclusion"
output=$(echo "$response" | jq -r .output)
title=$(echo "$output" | jq -r .title)
summary=$(echo "$output" | jq -r .summary)
echo "Title: $title"
echo "Summary: $summary"
if [ "$conclusion" != "success" ]; then
exit 1
fi
exit 0
fi
echo "Tests still running. Waiting 30 seconds before next check..."
sleep 30
done
echo "Timeout: Playwright tests did not complete within 45 minutes"
exit 1
- name: Post Failure Message to Slack
id: slack-notification
if: failure()
uses: slackapi/[email protected]
with:
payload: |
{
"text": "⚠️ Playwright tests failed! Commit: ${{ github.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}",
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "⚠️ Playwright tests failed! Commit: ${{ github.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}",
"emoji": true
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View Report"
},
"url": "$PLAYWRIGHT_REPORT_URL"
}
}
]
}
env:
PLAYWRIGHT_REPORT_URL: ${{ secrets.PLAYWRIGHT_REPORT_BASE_URL }}/${{ env.CHECK_ID }}/playwright-report/index.html
SLACK_WEBHOOK_URL: ${{ secrets.PLAYWRIGHT_TESTS_SLACK_WEBHOOK_URL }}