forked from opea-project/GenAIComps
-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (89 loc) · 4.46 KB
/
reuse-get-test-matrix.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
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
# Support push and pull_request events
name: Get Test Matrix
permissions: read-all
on:
workflow_call:
outputs:
run_matrix:
description: "The matrix string"
value: ${{ jobs.job1.outputs.run_matrix }}
jobs:
job1:
name: Get-test-matrix
runs-on: ubuntu-latest
outputs:
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
steps:
- name: Get checkout ref
run: |
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then
echo "CHECKOUT_REF=refs/pull/${{ github.event.number }}/merge" >> $GITHUB_ENV
else
echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_ENV
fi
echo "checkout ref ${{ env.CHECKOUT_REF }}"
- name: Checkout out Repo
uses: actions/checkout@v4
with:
ref: ${{ env.CHECKOUT_REF }}
fetch-depth: 0
- name: Get test matrix
id: get-test-matrix
run: |
set -xe
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then
base_commit=${{ github.event.pull_request.base.sha }}
else
base_commit=$(git rev-parse HEAD~1) # push event
fi
merged_commit=$(git log -1 --format='%H')
changed_files="$(git diff --name-only ${base_commit} ${merged_commit} | \
grep 'comps/' | grep -vE '*.md|*.txt|comps/cores')" || true
services=$(printf '%s\n' "${changed_files[@]}" | cut -d'/' -f2 | grep -vE '*.py' | sort -u) || true
path_level_1=("asr" "tts")
path_level_3=("llms/summarization" "llms/text-generation" "dataprep/redis" "retrievers/langchain")
run_matrix="{\"include\":["
for service in ${services}; do
hardware="gaudi" # default hardware, set based on the changed files
if [[ "${path_level_1[@]}" =~ "${service}" ]]; then
run_matrix="${run_matrix}{\"service\":\"${service}\",\"hardware\":\"${hardware}\"},"
else
vendors=$(printf '%s\n' "${changed_files[@]}" | grep ${service} | cut -d'/' -f3 | grep -vE '*.py|Dockerfile|*.md|*.sh' | sort -u)
for vendor in ${vendors}; do
if [[ "${path_level_3[@]}" =~ "${service}/${vendor}" ]]; then
sub_vendors=$(printf '%s\n' "${changed_files[@]}" | grep ${service} | grep ${vendor} | cut -d'/' -f4 | grep -vE '*.py' | sort -u)
for sub_vendor in ${sub_vendors}; do
run_matrix="${run_matrix}{\"service\":\"${service}/${vendor}/${sub_vendor}\",\"hardware\":\"${hardware}\"},"
done
else
run_matrix="${run_matrix}{\"service\":\"${service}/${vendor}\",\"hardware\":\"${hardware}\"},"
fi
done
fi
done
# add test for comps/dataprep/utils.py
if [[ "${changed_files[@]}" =~ "comps/dataprep/utils.py" ]]; then
service_list=("dataprep/qdrant" "dataprep/redis/langchain")
hardware="gaudi" # default hardware, set based on the changed files
for service in ${service_list[@]}; do
if [ $(echo ${run_matrix} | grep -c ${service}) == 0 ]; then
run_matrix="${run_matrix}{\"service\":\"${service}\",\"hardware\":\"${hardware}\"},"
fi
done
fi
# add test for test scripts update
changed_files="$(git diff --name-only ${base_commit} ${merged_commit} | \
grep 'tests/' | grep -vE '*.md|*.txt|tests/cores')" || true
run_matrix_match=$(echo $run_matrix | tr '/' '_')
test_files=$(printf '%s\n' "${changed_files[@]}" | grep -E "tests/test_*" | grep -E "*.sh") || true
for test_file in ${test_files}; do
service=$(echo $test_file | cut -d'/' -f2 | cut -d'.' -f1 | cut -c6-)
hardware="gaudi" # default hardware, set based on the changed files
if [ $(echo ${run_matrix_match} | grep -c ${service}) == 0 ]; then
run_matrix="${run_matrix}{\"service\":\"${service}\",\"hardware\":\"${hardware}\"},"
fi
done
run_matrix=$run_matrix"]}"
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT