Skip to content

Commit f3562be

Browse files
authored
Add helm e2e test workflow (#1372)
Add both CICD workflow for helm charts values test. Signed-off-by: ZePan110 <ze.pan@intel.com>
1 parent 7a54064 commit f3562be

File tree

5 files changed

+306
-10
lines changed

5 files changed

+306
-10
lines changed

.github/workflows/_example-workflow.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ on:
2828
default: false
2929
required: false
3030
type: boolean
31-
test_k8s:
31+
test_helmchart:
3232
default: false
3333
required: false
3434
type: boolean
@@ -50,6 +50,7 @@ jobs:
5050
# Image Build
5151
####################################################################################################
5252
build-images:
53+
if: ${{ !(fromJSON(inputs.test_helmchart)) }}
5354
runs-on: "docker-build-${{ inputs.node }}"
5455
steps:
5556
- name: Clean Up Working Directory
@@ -106,20 +107,21 @@ jobs:
106107
tag: ${{ inputs.tag }}
107108
example: ${{ inputs.example }}
108109
hardware: ${{ inputs.node }}
110+
mode: "CD"
109111
secrets: inherit
110112

111113

112114
####################################################################################################
113-
# K8S Test
115+
# helmchart Test
114116
####################################################################################################
115-
test-k8s-manifest:
116-
needs: [build-images]
117-
if: ${{ fromJSON(inputs.test_k8s) }}
118-
uses: ./.github/workflows/_manifest-e2e.yml
117+
test-helmchart:
118+
if: ${{ fromJSON(inputs.test_helmchart) }}
119+
uses: ./.github/workflows/_helm-e2e.yml
119120
with:
120121
example: ${{ inputs.example }}
121122
hardware: ${{ inputs.node }}
122123
tag: ${{ inputs.tag }}
124+
mode: "CD"
123125
secrets: inherit
124126

125127
####################################################################################################

.github/workflows/_helm-e2e.yaml

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Helm Chart E2e Test For Call
5+
permissions: read-all
6+
on:
7+
workflow_call:
8+
inputs:
9+
example:
10+
default: "chatqna"
11+
required: true
12+
type: string
13+
description: "example to test, chatqna or common/asr"
14+
hardware:
15+
default: "xeon"
16+
required: true
17+
type: string
18+
dockerhub:
19+
default: "false"
20+
required: false
21+
type: string
22+
description: "Set to true if you want to use released docker images at dockerhub. By default using internal docker registry."
23+
mode:
24+
default: "CD"
25+
description: "Whether the test range is CI, CD or CICD"
26+
required: false
27+
type: string
28+
tag:
29+
default: "latest"
30+
required: false
31+
type: string
32+
33+
jobs:
34+
get-test-case:
35+
runs-on: ubuntu-latest
36+
outputs:
37+
value_files: ${{ steps.get-test-files.outputs.value_files }}
38+
CHECKOUT_REF: ${{ steps.get-checkout-ref.outputs.CHECKOUT_REF }}
39+
steps:
40+
- name: Get checkout ref
41+
id: get-checkout-ref
42+
run: |
43+
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then
44+
CHECKOUT_REF=refs/pull/${{ github.event.number }}/merge
45+
else
46+
CHECKOUT_REF=${{ github.ref }}
47+
fi
48+
echo "CHECKOUT_REF=${CHECKOUT_REF}" >> $GITHUB_OUTPUT
49+
echo "checkout ref ${CHECKOUT_REF}"
50+
51+
- name: Checkout Repo
52+
uses: actions/checkout@v4
53+
with:
54+
ref: ${{ steps.get-checkout-ref.outputs.CHECKOUT_REF }}
55+
fetch-depth: 0
56+
57+
- name: Get test Services
58+
id: get-test-files
59+
run: |
60+
set -x
61+
if [ "${{ inputs.mode }}" = "CI" ]; then
62+
base_commit=${{ github.event.pull_request.base.sha }}
63+
merged_commit=$(git log -1 --format='%H')
64+
values_files=$(git diff --name-only ${base_commit} ${merged_commit} | \
65+
grep "kubernetes/helm" | \
66+
sort -u)
67+
echo $values_files
68+
elif [ "${{ inputs.mode }}" = "CD" ]; then
69+
value_files=$(ls ${{ inputs.example }}/kubernetes/helm/*values.yaml)
70+
fi
71+
value_files="["
72+
for file in ${values_files}; do
73+
if [ -f "$file" ]; then
74+
filename=$(basename "$file")
75+
if [[ "$filename" == *"gaudi"* ]]; then
76+
if [[ "${{ inputs.hardware }}" == "gaudi" ]]; then
77+
value_files="${value_files}\"${filename}\","
78+
fi
79+
elif [[ "$filename" == *"nv"* ]]; then
80+
continue
81+
else
82+
if [[ "${{ inputs.hardware }}" == "xeon" ]]; then
83+
value_files="${value_files}\"${filename}\","
84+
fi
85+
fi
86+
fi
87+
done
88+
value_files="${value_files%,}]"
89+
90+
echo "value_files=${value_files}"
91+
echo "value_files=${value_files}" >> $GITHUB_OUTPUT
92+
93+
helm-test:
94+
needs: [get-test-case]
95+
strategy:
96+
matrix:
97+
value_file: ${{ fromJSON(needs.get-test-case.outputs.value_files) }}
98+
runs-on: ${{ inputs.hardware }}
99+
continue-on-error: true
100+
steps:
101+
- name: Clean Up Working Directory
102+
run: |
103+
echo "value_file=${{ matrix.value_file }}"
104+
sudo rm -rf ${{github.workspace}}/*
105+
106+
- name: Get checkout ref
107+
id: get-checkout-ref
108+
run: |
109+
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then
110+
CHECKOUT_REF=refs/pull/${{ github.event.number }}/merge
111+
else
112+
CHECKOUT_REF=${{ github.ref }}
113+
fi
114+
echo "CHECKOUT_REF=${CHECKOUT_REF}" >> $GITHUB_OUTPUT
115+
echo "checkout ref ${CHECKOUT_REF}"
116+
117+
- name: Checkout Repo
118+
uses: actions/checkout@v4
119+
with:
120+
ref: ${{ steps.get-checkout-ref.outputs.CHECKOUT_REF }}
121+
fetch-depth: 0
122+
123+
- name: Set variables
124+
env:
125+
example: ${{ inputs.example }}
126+
run: |
127+
CHART_NAME="${example,,}" # CodeGen
128+
echo "CHART_NAME=$CHART_NAME" >> $GITHUB_ENV
129+
echo "RELEASE_NAME=${CHART_NAME}$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
130+
echo "NAMESPACE=${CHART_NAME}-$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
131+
echo "ROLLOUT_TIMEOUT_SECONDS=600s" >> $GITHUB_ENV
132+
echo "TEST_TIMEOUT_SECONDS=600s" >> $GITHUB_ENV
133+
echo "KUBECTL_TIMEOUT_SECONDS=60s" >> $GITHUB_ENV
134+
echo "should_cleanup=false" >> $GITHUB_ENV
135+
echo "skip_validate=false" >> $GITHUB_ENV
136+
echo "CHART_FOLDER=${example}/kubernetes/helm" >> $GITHUB_ENV
137+
138+
- name: Helm install
139+
id: install
140+
env:
141+
GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }}
142+
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
143+
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
144+
HFTOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
145+
value_file: ${{ matrix.value_file }}
146+
run: |
147+
set -xe
148+
echo "should_cleanup=true" >> $GITHUB_ENV
149+
if [[ ! -f ${{ github.workspace }}/${{ env.CHART_FOLDER }}/${value_file} ]]; then
150+
echo "No value file found, exiting test!"
151+
echo "skip_validate=true" >> $GITHUB_ENV
152+
echo "should_cleanup=false" >> $GITHUB_ENV
153+
exit 0
154+
fi
155+
156+
if ! helm install \
157+
--create-namespace \
158+
--namespace $NAMESPACE \
159+
$RELEASE_NAME \
160+
oci://ghcr.io/opea-project/charts/${CHART_NAME} \
161+
--set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} \
162+
--set global.modelUseHostPath=/home/sdp/.cache/huggingface/hub \
163+
--set GOOGLE_API_KEY=${{ env.GOOGLE_API_KEY}} \
164+
--set GOOGLE_CSE_ID=${{ env.GOOGLE_CSE_ID}} \
165+
-f ${{ inputs.example }}/kubernetes/helm/${value_file} \
166+
--version 0-latest \
167+
--wait; then
168+
echo "Failed to install chart ${{ inputs.example }}"
169+
echo "skip_validate=true" >> $GITHUB_ENV
170+
.github/workflows/scripts/k8s-utils.sh dump_pods_status $NAMESPACE
171+
exit 1
172+
fi
173+
174+
- name: Validate e2e test
175+
if: always()
176+
run: |
177+
set -xe
178+
if $skip_validate; then
179+
echo "Skip validate"
180+
else
181+
LOG_PATH=/home/$(whoami)/helm-logs
182+
chart=${{ env.CHART_NAME }}
183+
helm test -n $NAMESPACE $RELEASE_NAME --logs --timeout "$TEST_TIMEOUT_SECONDS" | tee ${LOG_PATH}/charts-${chart}.log
184+
exit_code=$?
185+
if [ $exit_code -ne 0 ]; then
186+
echo "Chart ${chart} test failed, please check the logs in ${LOG_PATH}!"
187+
exit 1
188+
fi
189+
190+
echo "Checking response results, make sure the output is reasonable. "
191+
teststatus=false
192+
if [[ -f $LOG_PATH/charts-${chart}.log ]] && \
193+
[[ $(grep -c "^Phase:.*Failed" $LOG_PATH/charts-${chart}.log) != 0 ]]; then
194+
teststatus=false
195+
${{ github.workspace }}/.github/workflows/scripts/k8s-utils.sh dump_all_pod_logs $NAMESPACE
196+
else
197+
teststatus=true
198+
fi
199+
200+
if [ $teststatus == false ]; then
201+
echo "Response check failed, please check the logs in artifacts!"
202+
exit 1
203+
else
204+
echo "Response check succeeded!"
205+
exit 0
206+
fi
207+
fi
208+
209+
- name: Helm uninstall
210+
if: always()
211+
run: |
212+
if $should_cleanup; then
213+
helm uninstall $RELEASE_NAME --namespace $NAMESPACE
214+
if ! kubectl delete ns $NAMESPACE --timeout=$KUBECTL_TIMEOUT_SECONDS; then
215+
kubectl delete pods --namespace $NAMESPACE --force --grace-period=0 --all
216+
kubectl delete ns $NAMESPACE --force --grace-period=0 --timeout=$KUBECTL_TIMEOUT_SECONDS
217+
fi
218+
fi

.github/workflows/manual-example-workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ on:
3535
description: 'Test examples with docker compose'
3636
required: false
3737
type: boolean
38-
test_k8s:
38+
test_helmchart:
3939
default: false
40-
description: 'Test examples with k8s'
40+
description: 'Test examples with helm charts'
4141
required: false
4242
type: boolean
4343
test_gmc:
@@ -103,7 +103,7 @@ jobs:
103103
tag: ${{ inputs.tag }}
104104
build: ${{ fromJSON(inputs.build) }}
105105
test_compose: ${{ fromJSON(inputs.test_compose) }}
106-
test_k8s: ${{ fromJSON(inputs.test_k8s) }}
106+
test_helmchart: ${{ fromJSON(inputs.test_helmchart) }}
107107
test_gmc: ${{ fromJSON(inputs.test_gmc) }}
108108
opea_branch: ${{ inputs.opea_branch }}
109109
inject_commit: ${{ inputs.inject_commit }}

.github/workflows/pr-chart-e2e.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: E2E Test with Helm Charts
5+
6+
on:
7+
pull_request_target:
8+
branches: [main]
9+
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
10+
paths:
11+
- "!**.md"
12+
- "**/helm/**"
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
job1:
21+
name: Get-Test-Matrix
22+
runs-on: ubuntu-latest
23+
outputs:
24+
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
25+
steps:
26+
- name: Checkout Repo
27+
uses: actions/checkout@v4
28+
with:
29+
ref: "refs/pull/${{ github.event.number }}/merge"
30+
fetch-depth: 0
31+
32+
- name: Get Test Matrix
33+
id: get-test-matrix
34+
run: |
35+
set -x
36+
echo "base_commit=${{ github.event.pull_request.base.sha }}"
37+
base_commit=${{ github.event.pull_request.base.sha }}
38+
merged_commit=$(git log -1 --format='%H')
39+
values_files=$(git diff --name-only ${base_commit} ${merged_commit} | \
40+
grep "values.yaml" | \
41+
sort -u ) #CodeGen/kubernetes/helm/cpu-values.yaml
42+
run_matrix="{\"include\":["
43+
for values_file in ${values_files}; do
44+
if [ -f "$values_file" ]; then
45+
valuefile=$(basename "$values_file") # cpu-values.yaml
46+
example=$(echo "$values_file" | cut -d'/' -f1) # CodeGen
47+
if [[ "$valuefile" == *"gaudi"* ]]; then
48+
hardware="gaudi"
49+
elif [[ "$valuefile" == *"nv"* ]]; then
50+
continue
51+
else
52+
hardware="xeon"
53+
fi
54+
echo "example=${example}, hardware=${hardware}, valuefile=${valuefile}"
55+
if [[ $(echo ${run_matrix} | grep -c "{\"example\":\"${example}\",\"hardware\":\"${hardware}\"},") == 0 ]]; then
56+
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"${hardware}\"},"
57+
echo "------------------ add one values file ------------------"
58+
fi
59+
fi
60+
done
61+
run_matrix="${run_matrix%,}"
62+
run_matrix=$run_matrix"]}"
63+
echo "run_matrix="${run_matrix}""
64+
echo "run_matrix="${run_matrix}"" >> $GITHUB_OUTPUT
65+
66+
helm-chart-test:
67+
needs: [job1]
68+
if: always() && ${{ needs.job1.outputs.run_matrix.example.length > 0 }}
69+
uses: ./.github/workflows/_helm-e2e.yaml
70+
strategy:
71+
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
72+
with:
73+
example: ${{ matrix.example }}
74+
hardware: ${{ matrix.hardware }}
75+
mode: "CI"
76+
secrets: inherit

.github/workflows/scripts/k8s-utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (C) 2024 Intel Corporation
33
# SPDX-License-Identifier: Apache-2.0
44

5-
#set -xe
5+
set -e
66

77
function dump_pod_log() {
88
pod_name=$1

0 commit comments

Comments
 (0)