-
Notifications
You must be signed in to change notification settings - Fork 26
323 lines (318 loc) · 15.1 KB
/
test.yaml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
name: Test Samples
on:
workflow_dispatch:
inputs:
version:
description: 'Radius version number to use (e.g. 0.22.0, 0.23.0-rc1, edge). Defaults to edge.'
required: false
default: 'edge'
type: string
push:
branches:
- v*.*
- edge
paths:
- "quickstarts/**"
- "reference-apps/**"
- "demo/**"
- ".github/workflows/**"
pull_request:
types: [opened, synchronize, reopened]
branches:
- v*.*
# - edge
schedule: # 7:45 AM Pacific Time
- cron: "45 15 * * *"
env:
RAD_CLI_URL: https://get.radapp.dev/tools/rad/install.sh
RUN_IDENTIFIER: samplestest-${{ github.run_id }}-${{ github.run_attempt }}
jobs:
test:
name: Sample tests
runs-on: [self-hosted, 1ES.Pool=1ES-Radius-Samples]
strategy:
fail-fast: false
matrix:
include:
# - name: demo
# runOnPullRequest: true
# app: demo
# path: ./demo/app.bicep
# args: --application demo
# uiTestFile: tests/demo/demo.app.spec.ts
# port: 3000
# container: demo
# enableDapr: false
# - name: dapr
# runOnPullRequest: true
# app: dapr-quickstart
# path: ./quickstarts/dapr/dapr.bicep
# enableDapr: true
# - name: environment-variables
# runOnPullRequest: true
# app: myapp
# path: ./quickstarts/environment-variables/app.bicep
# enableDapr: false
# - name: volumes
# runOnPullRequest: true
# app: myapp
# path: ./quickstarts/volumes/app.bicep
# enableDapr: false
# - name: eshop
# runOnPullRequest: true
# app: eshop
# path: ./reference-apps/eshop/iac/eshop.bicep
# args: -p appName eshop
# uiTestFile: tests/eshop/container.app.spec.ts
# enableDapr: false
# - name: eshop-azure
# runOnPullRequest: false
# app: eshop-azure
# path: ./reference-apps/eshop/iac/eshop.bicep
# args: -p platform=azure -p appName=eshop-azure
# uiTestFile: tests/eshop/container.app.spec.ts
# credential: azure
# enableDapr: false
- name: eshop-aws
runOnPullRequest: false
app: eshop-aws-${{ github.run_id }}-${{ github.run_attempt }}-eshop-aws
path: ./reference-apps/eshop/iac/eshop.bicep
args: -p platform=aws eksClusterName=eks-samplestest-${{ github.run_id }}-${{ github.run_attempt }}-eshop-aws -p appName=eshop-aws-${{ github.run_id }}-${{ github.run_attempt }}-eshop-aws
uiTestFile: tests/eshop/container.app.spec.ts
credential: aws
enableDapr: false
env:
BRANCH: ${{ github.base_ref || github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AZURE_LOCATION: westus3
AWS_REGION: us-west-2
steps:
# Setup the test assets and configuration
- name: Generate output variables
id: gen-id
run: |
RUN_IDENTIFIER=${{ env.RUN_IDENTIFIER }}-${{ matrix.name }}
if [[ "${{ github.event_name }}" == "pull_request" && "${{ matrix.runOnPullRequest }}" == "false" ]]; then
RUN_TEST=false
else
RUN_TEST=true
fi
if [[ "${{ matrix.enableDapr }}" == "true" ]]; then
ENABLE_DAPR=true
else
ENABLE_DAPR=false
fi
# Set output variables to be used in the other jobs
echo "RUN_IDENTIFIER=${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT
echo "TEST_AZURE_RESOURCE_GROUP=rg-samplestest-${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT
echo "TEST_EKS_CLUSTER_NAME=eks-samplestest-${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT
echo "RUN_TEST=${RUN_TEST}" >> $GITHUB_OUTPUT
echo "ENABLE_DAPR=${ENABLE_DAPR}" >> $GITHUB_OUTPUT
- name: Checkout code
if: steps.gen-id.outputs.RUN_TEST == 'true'
uses: actions/checkout@v3
- name: Ensure inputs.version is valid semver
if: inputs.version != '' && steps.gen-id.outputs.RUN_TEST == 'true'
run: |
python ./.github/scripts/validate_semver.py ${{ inputs.version }}
- name: Setup Node
if: steps.gen-id.outputs.RUN_TEST == 'true'
uses: actions/setup-node@v3
with:
node-version: 16
- name: az CLI login
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'azure'
run: |
az login --service-principal \
--username ${{ secrets.AZURE_SP_TESTS_APPID }} \
--password ${{ secrets.AZURE_SP_TESTS_PASSWORD }} \
--tenant ${{ secrets.AZURE_SP_TESTS_TENANTID }}
# Create and install test environment
- name: Create Azure resource group
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'azure'
id: create-azure-resource-group
run: |
current_time=$(date +%s)
az group create \
--location ${{ env.AZURE_LOCATION }} \
--name ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }} \
--subscription $SUBSCRIPTION_ID \
--tags creationTime=$current_time
while [ $(az group exists --name ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }} --subscription ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }}) = false ]; do
echo "Waiting for resource group ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }} to be created..."
sleep 5
done
- name: Configure AWS
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'aws'
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws configure set region ${{ env.AWS_REGION }}
aws configure set output json
- name: Create EKS Cluster
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'aws'
id: create-eks
env:
EKS_CLUSTER_NAME:
run: |
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl create cluster --name ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }} \
--nodes-min 1 --nodes-max 2 --node-type t3.large \
--managed \
--region ${{ env.AWS_REGION }}
while [[ "$(eksctl get cluster ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }} -o json | jq -r .[0].Status)" != "ACTIVE" ]]; do
echo "Waiting for EKS cluster to be created..."
sleep 60
aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }}
done
timeout-minutes: 60
continue-on-error: false
- name: Download k3d
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential != 'aws'
run: wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
- name: Create k3d cluster
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential != 'aws'
run: k3d cluster create --agents 2 -p "80:80@loadbalancer" --k3s-arg "--disable=traefik@server:0"
- name: Install Dapr
if: steps.gen-id.outputs.RUN_TEST == 'true' && steps.gen-id.outputs.ENABLE_DAPR == 'true'
run: |
helm repo add dapr https://dapr.github.io/helm-charts/
helm install dapr dapr/dapr --version=1.6 --namespace dapr-system --create-namespace --wait
- name: Download rad CLI
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
for attempt in 1 2 3 4 5; do
if [[ -n "${{ inputs.version }}" ]]; then
echo "Downloading rad CLI version ${{ inputs.version }}"
wget -q "${{ env.RAD_CLI_URL }}" -O - | /bin/bash -s ${{ inputs.version }}
else
echo "Downloading latest rad CLI"
wget -q "${{ env.RAD_CLI_URL }}" -O - | /bin/bash
fi
if [ $? -eq 0 ]; then
break
fi
done
- name: Initialize local environment
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
if [[ "${{ matrix.credential }}" == "aws" ]]; then
rad install kubernetes
else
rad install kubernetes --set rp.publicEndpointOverride=localhost
fi
rad group create default
rad workspace create kubernetes default --group default
rad group switch default
rad env create default
rad env switch default
rad recipe register default -e default -w default --template-kind bicep --template-path radius.azurecr.io/recipes/dev/rediscaches:latest --resource-type Applications.Datastores/redisCaches
rad recipe register default -e default -w default --template-kind bicep --template-path radius.azurecr.io/recipes/dev/mongodatabases:latest --resource-type Applications.Datastores/mongoDatabases
if [[ "${{ matrix.credential }}" == "azure" ]]; then
rad env update default --azure-subscription-id ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }} --azure-resource-group ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }}
rad credential register azure --client-id ${{ secrets.AZURE_SP_TESTS_APPID }} --client-secret ${{ secrets.AZURE_SP_TESTS_PASSWORD }} --tenant-id ${{ secrets.AZURE_SP_TESTS_TENANTID }}
fi
if [[ "${{ matrix.credential }}" == "aws" ]]; then
rad env update default --aws-region ${{ env.AWS_REGION }} --aws-account-id ${{ secrets.AWS_ACCOUNT_ID }}
rad credential register aws --access-key-id ${{ secrets.AWS_ACCOUNT_ID }} --secret-access-key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
fi
# Deploy application and run tests
- name: Deploy app
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: rad deploy ${{ matrix.path }} ${{ matrix.args }}
- name: Wait for all pods to be ready
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
namespace="default-${{ matrix.app }}"
label="radius.dev/application=${{ matrix.app }}"
kubectl wait --for=condition=Ready pod -l $label -n $namespace --timeout=5m
- name: Run Playwright Test
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.uiTestFile != ''
id: run-playwright-test
run: |
if [[ "${{ matrix.container }}" != "" ]]; then
rad resource expose containers ${{ matrix.container }} ${{ matrix.args }} --port ${{ matrix.port }} &
fi
cd ui-tests/
npm ci
npx playwright install --with-deps
if [[ "${{ matrix.app }}" == "eshop" ]]; then
endpoint="$(rad app status -a ${{ matrix.app }} | sed 's/ /\n/g' | grep http)"
echo $endpoint
ENDPOINT=$endpoint
npx playwright test ${{ matrix.uiTestFile }} --retries 3
- name: Upload Playwright Results
uses: actions/upload-artifact@v3
if: always() && ( steps.run-playwright-test.outcome == 'success' || steps.run-playwright-test.outcome == 'failure' )
with:
name: playwright-report-${{ matrix.name }}
path: ui-tests/playwright-report/
retention-days: 30
if-no-files-found: error
# Handle failures
- name: Get Pod logs for failed tests
id: get-pod-logs
if: failure() && steps.run-playwright-test.outcome == 'failure'
run: |
# Create pod-logs directory
mkdir -p ui-tests/pod-logs/${{ matrix.name }}
# Get pod logs and save to file
namespace="default-${{ matrix.app }}"
label="radius.dev/application=${{ matrix.app }}"
if [[ "${{ matrix.credential }}" == "aws" ]]; then
namespace="default-${{ matrix.app }}""
label="radius.dev/application=${{ matrix.app }}"
fi
pod_names=($(kubectl get pods -l $label -n $namespace -o jsonpath='{.items[*].metadata.name}'))
for pod_name in "${pod_names[@]}"; do
kubectl logs $pod_name -n $namespace > ui-tests/pod-logs/${{ matrix.name }}/${pod_name}.txt
done
echo "Pod logs saved to ui-tests/pod-logs/${{ matrix.name }}/"
# Get kubernetes events and save to file
kubectl get events -n $namespace > ui-tests/pod-logs/${{ matrix.name }}/events.txt
- name: Upload Pod logs for failed tests
uses: actions/upload-artifact@v3
if: failure() && steps.get-pod-logs.outcome == 'success'
with:
name: ${{ matrix.name }}-pod-logs
path: ui-tests/pod-logs/${{ matrix.name }}
retention-days: 30
if-no-files-found: error
- name: Create GitHub issue on failure
if: failure() && github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
run: gh issue create --title "Samples deployment failed for ${{ matrix.app }}" --body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." --repo ${{ github.repository }}
# Cleanup
- name: Delete app
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
rad app delete -y
- name: Delete Azure resource group
if: always() && steps.create-azure-resource-group.outcome == 'success'
env:
RESOURCE_GROUP: ${{ steps.gen-id.outputs.TEST_RESOURCE_GROUP_PREFIX }}-${{ matrix.name }}
SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }}
run: |
# if deletion fails, purge workflow will purge the resource group and its resources later
az group delete \
--subscription $SUBSCRIPTION_ID \
--name $RESOURCE_GROUP \
--yes
- name: Delete EKS Cluster
if: always() && matrix.credential == 'aws'
env:
EKS_CLUSTER_NAME: ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }}
run: |
# Uninstall Radius from EKS cluster
rad uninstall kubernetes
# Delete EKS cluster
echo "Deleting EKS cluster: $EKS_CLUSTER_NAME"
eksctl delete cluster --name $EKS_CLUSTER_NAME --region ${{ env.AWS_REGION }} --wait
- name: Delete AWS Resources
if: always() && matrix.credential == 'aws'
run: |
# if deletion fails, purge workflow will purge the resource group and its resources later
./.github/scripts/delete-aws-resources.sh ${{ matrix.app }}
- name: Create GitHub issue on failure
if: failure() && github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
run: gh issue create --title "Samples deployment failed for ${{ matrix.app }}" --body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." --repo ${{ github.repository }}