Skip to content

Commit 961abb3

Browse files
authored
Create reuse workflow for get-test-matrix in CI (opea-project#283)
Signed-off-by: Yingchun Guo <yingchun.guo@intel.com>
1 parent 2fb070d commit 961abb3

5 files changed

Lines changed: 73 additions & 69 deletions

File tree

.github/workflows/E2E_test_with_compose.yml

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,9 @@ concurrency:
2323

2424
jobs:
2525
job1:
26-
name: Get-test-matrix
27-
runs-on: ubuntu-latest
28-
outputs:
29-
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
30-
steps:
31-
- name: Checkout out Repo
32-
uses: actions/checkout@v4
33-
with:
34-
ref: "refs/pull/${{ github.event.number }}/merge"
35-
fetch-depth: 0
36-
37-
- name: Get test matrix
38-
id: get-test-matrix
39-
run: |
40-
set -xe
41-
merged_commit=$(git log -1 --format='%H')
42-
changed_files="$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${merged_commit} | \
43-
grep -vE '.github|README.md|*.txt|deprecate|kubernetes|manifest')" || true
44-
examples=$(printf '%s\n' "${changed_files[@]}" | grep '/' | cut -d'/' -f1 | sort -u)
45-
run_matrix="{\"include\":["
46-
for example in ${examples}; do
47-
run_hardware=""
48-
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c gaudi) != 0 ]; then run_hardware="gaudi"; fi
49-
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c xeon) != 0 ]; then run_hardware="xeon ${run_hardware}"; fi
50-
if [ "$run_hardware" = "" ]; then run_hardware="xeon"; fi
51-
for hw in ${run_hardware}; do
52-
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"${hw}\"},"
53-
done
54-
done
55-
run_matrix=$run_matrix"]}"
56-
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
26+
uses: ./.github/workflows/reuse-get-test-matrix.yml
27+
with:
28+
diff-excluded-files: '.github|README.md|*.txt|deprecate|kubernetes|manifest|assets'
5729

5830
Example-test:
5931
needs: job1
Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
1010
paths:
1111
- "**/kubernetes/manifests/**"
12-
- "**/tests/**"
12+
- "**/tests/test_manifest**"
1313
- "!**.md"
1414
- "!**.txt"
1515
- .github/workflows/manifest-e2e.yml
@@ -21,47 +21,17 @@ concurrency:
2121

2222
jobs:
2323
job1:
24-
name: Get-test-matrix
25-
runs-on: ubuntu-latest
26-
outputs:
27-
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
28-
steps:
29-
- name: Checkout out Repo
30-
uses: actions/checkout@v4
31-
with:
32-
fetch-depth: 0
33-
34-
- name: Get test matrix
35-
id: get-test-matrix
36-
run: |
37-
set -xe
38-
changed_files="$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | \
39-
grep -E "/kubernetes/manifests/|test_manifest" | \
40-
grep -vE '.github|deprecated|docker')" || true
41-
examples=$(printf '%s\n' "${changed_files[@]}" | grep '/' | cut -d'/' -f1 | sort -u)
42-
run_matrix="{\"include\":["
43-
for example in ${examples}; do
44-
run_hardware=""
45-
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c gaudi) != 0 ]; then run_hardware="gaudi"; fi
46-
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c xeon) != 0 ]; then run_hardware="xeon ${run_hardware}"; fi
47-
if [[ -z "$run_hardware" ]]; then run_hardware="xeon"; fi
48-
for hw in ${run_hardware}; do
49-
if [ $hw = "gaudi" ]; then
50-
continue # skip gaudi for K8s test temporarily
51-
else
52-
#lower_example=$(echo "${example}" | tr '[:upper:]' '[:lower:]')
53-
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"k8s\"},"
54-
fi
55-
done
56-
done
57-
run_matrix=$run_matrix"]}"
58-
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
24+
uses: ./.github/workflows/reuse-get-test-matrix.yml
25+
with:
26+
diff-excluded-files: '.github|deprecated|docker|assets'
27+
xeon-server-lable: 'k8s'
28+
gaudi-server-lable: ""
5929

6030
mega-image-build:
6131
needs: job1
6232
strategy:
6333
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
64-
uses: ./.github/workflows/image-build.yaml
34+
uses: ./.github/workflows/reuse-image-build.yml
6535
with:
6636
image-tag: ${{ github.event.pull_request.head.sha }}
6737
mega-service: "${{ matrix.example }}"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
1010
paths:
1111
- "**/kubernetes/manifests/**"
12-
- .github/workflows/manifest-validate.yaml
12+
- .github/workflows/manifest-validate.yml
1313
workflow_dispatch:
1414

1515
# If there is a new commit, the previous jobs will be canceled
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Get Test Matrix
5+
permissions: read-all
6+
on:
7+
workflow_call:
8+
inputs:
9+
diff-excluded-files:
10+
required: false
11+
type: string
12+
default: '.github|README.md|*.txt'
13+
xeon-server-lable:
14+
required: false
15+
type: string
16+
default: 'xeon'
17+
gaudi-server-lable:
18+
required: false
19+
type: string
20+
default: 'gaudi'
21+
outputs:
22+
run_matrix:
23+
description: "The matrix string"
24+
value: ${{ jobs.job1.outputs.run_matrix }}
25+
26+
jobs:
27+
job1:
28+
name: Get-test-matrix
29+
runs-on: ubuntu-latest
30+
outputs:
31+
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
32+
steps:
33+
- name: Checkout out Repo
34+
uses: actions/checkout@v4
35+
with:
36+
ref: "refs/pull/${{ github.event.number }}/merge"
37+
fetch-depth: 0
38+
39+
- name: Get test matrix
40+
id: get-test-matrix
41+
run: |
42+
set -xe
43+
merged_commit=$(git log -1 --format='%H')
44+
changed_files="$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${merged_commit} | \
45+
grep -vE '${{ inputs.diff-excluded-files }}')" || true
46+
examples=$(printf '%s\n' "${changed_files[@]}" | grep '/' | cut -d'/' -f1 | sort -u)
47+
run_matrix="{\"include\":["
48+
for example in ${examples}; do
49+
run_hardware=""
50+
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c gaudi) != 0 ]; then run_hardware="gaudi"; fi
51+
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c xeon) != 0 ]; then run_hardware="xeon ${run_hardware}"; fi
52+
if [ "$run_hardware" = "" ]; then run_hardware="xeon"; fi
53+
for hw in ${run_hardware}; do
54+
if [ $hw = "gaudi" && ${{ inputs.gaudi-server-lable }} != ""]; then
55+
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"${{ inputs.gaudi-server-lable }}\"},"
56+
elif [ ${{ inputs.xeon-server-lable }} != "" ]; then
57+
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"${{ inputs.xeon-server-lable }}\"},"
58+
fi
59+
done
60+
done
61+
run_matrix=$run_matrix"]}"
62+
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)