Skip to content

Commit

Permalink
Create reuse workflow for get-test-matrix in CI (#283)
Browse files Browse the repository at this point in the history
Signed-off-by: Yingchun Guo <yingchun.guo@intel.com>
  • Loading branch information
daisy-ycguo authored Jun 14, 2024
1 parent 2fb070d commit 961abb3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 69 deletions.
34 changes: 3 additions & 31 deletions .github/workflows/E2E_test_with_compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,9 @@ concurrency:

jobs:
job1:
name: Get-test-matrix
runs-on: ubuntu-latest
outputs:
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
steps:
- name: Checkout out Repo
uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.number }}/merge"
fetch-depth: 0

- name: Get test matrix
id: get-test-matrix
run: |
set -xe
merged_commit=$(git log -1 --format='%H')
changed_files="$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${merged_commit} | \
grep -vE '.github|README.md|*.txt|deprecate|kubernetes|manifest')" || true
examples=$(printf '%s\n' "${changed_files[@]}" | grep '/' | cut -d'/' -f1 | sort -u)
run_matrix="{\"include\":["
for example in ${examples}; do
run_hardware=""
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c gaudi) != 0 ]; then run_hardware="gaudi"; fi
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c xeon) != 0 ]; then run_hardware="xeon ${run_hardware}"; fi
if [ "$run_hardware" = "" ]; then run_hardware="xeon"; fi
for hw in ${run_hardware}; do
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"${hw}\"},"
done
done
run_matrix=$run_matrix"]}"
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
uses: ./.github/workflows/reuse-get-test-matrix.yml
with:
diff-excluded-files: '.github|README.md|*.txt|deprecate|kubernetes|manifest|assets'

Example-test:
needs: job1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- "**/kubernetes/manifests/**"
- "**/tests/**"
- "**/tests/test_manifest**"
- "!**.md"
- "!**.txt"
- .github/workflows/manifest-e2e.yml
Expand All @@ -21,47 +21,17 @@ concurrency:

jobs:
job1:
name: Get-test-matrix
runs-on: ubuntu-latest
outputs:
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
steps:
- name: Checkout out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get test matrix
id: get-test-matrix
run: |
set -xe
changed_files="$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | \
grep -E "/kubernetes/manifests/|test_manifest" | \
grep -vE '.github|deprecated|docker')" || true
examples=$(printf '%s\n' "${changed_files[@]}" | grep '/' | cut -d'/' -f1 | sort -u)
run_matrix="{\"include\":["
for example in ${examples}; do
run_hardware=""
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c gaudi) != 0 ]; then run_hardware="gaudi"; fi
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c xeon) != 0 ]; then run_hardware="xeon ${run_hardware}"; fi
if [[ -z "$run_hardware" ]]; then run_hardware="xeon"; fi
for hw in ${run_hardware}; do
if [ $hw = "gaudi" ]; then
continue # skip gaudi for K8s test temporarily
else
#lower_example=$(echo "${example}" | tr '[:upper:]' '[:lower:]')
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"k8s\"},"
fi
done
done
run_matrix=$run_matrix"]}"
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
uses: ./.github/workflows/reuse-get-test-matrix.yml
with:
diff-excluded-files: '.github|deprecated|docker|assets'
xeon-server-lable: 'k8s'
gaudi-server-lable: ""

mega-image-build:
needs: job1
strategy:
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
uses: ./.github/workflows/image-build.yaml
uses: ./.github/workflows/reuse-image-build.yml
with:
image-tag: ${{ github.event.pull_request.head.sha }}
mega-service: "${{ matrix.example }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- "**/kubernetes/manifests/**"
- .github/workflows/manifest-validate.yaml
- .github/workflows/manifest-validate.yml
workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/reuse-get-test-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

name: Get Test Matrix
permissions: read-all
on:
workflow_call:
inputs:
diff-excluded-files:
required: false
type: string
default: '.github|README.md|*.txt'
xeon-server-lable:
required: false
type: string
default: 'xeon'
gaudi-server-lable:
required: false
type: string
default: 'gaudi'
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: Checkout out Repo
uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.number }}/merge"
fetch-depth: 0

- name: Get test matrix
id: get-test-matrix
run: |
set -xe
merged_commit=$(git log -1 --format='%H')
changed_files="$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${merged_commit} | \
grep -vE '${{ inputs.diff-excluded-files }}')" || true
examples=$(printf '%s\n' "${changed_files[@]}" | grep '/' | cut -d'/' -f1 | sort -u)
run_matrix="{\"include\":["
for example in ${examples}; do
run_hardware=""
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c gaudi) != 0 ]; then run_hardware="gaudi"; fi
if [ $(printf '%s\n' "${changed_files[@]}" | grep ${example} | grep -c xeon) != 0 ]; then run_hardware="xeon ${run_hardware}"; fi
if [ "$run_hardware" = "" ]; then run_hardware="xeon"; fi
for hw in ${run_hardware}; do
if [ $hw = "gaudi" && ${{ inputs.gaudi-server-lable }} != ""]; then
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"${{ inputs.gaudi-server-lable }}\"},"
elif [ ${{ inputs.xeon-server-lable }} != "" ]; then
run_matrix="${run_matrix}{\"example\":\"${example}\",\"hardware\":\"${{ inputs.xeon-server-lable }}\"},"
fi
done
done
run_matrix=$run_matrix"]}"
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
File renamed without changes.

0 comments on commit 961abb3

Please sign in to comment.