diff --git a/.github/workflows/run-task-tests.yaml b/.github/workflows/run-task-tests.yaml index e75f73c9f..3296b6aa2 100644 --- a/.github/workflows/run-task-tests.yaml +++ b/.github/workflows/run-task-tests.yaml @@ -23,6 +23,12 @@ jobs: tool-cache: false docker-images: false + - name: Install tektor + if: steps.changed-files.outputs.any_changed == 'true' + run: | + go install github.com/lcarva/tektor@latest + tektor --help + - name: Checkout build-defintions Repository if: steps.changed-files.outputs.any_changed == 'true' uses: actions/checkout@v3 diff --git a/test/common.sh b/test/common.sh index ae6f5e0b1..d72bb4567 100644 --- a/test/common.sh +++ b/test/common.sh @@ -26,14 +26,18 @@ function set_test_return_code() { function detect_changed_e2e_test() { # check if any file from test/ directory is changed - echo ${CHANGED_FILES} |grep "test[/^/]" + echo ${CHANGED_FILES} |grep "test/" } function detect_new_changed_resources() { # detect for changes in tests dir of the task - echo ${CHANGED_FILES} |grep 'task/[^\/]*/[^\/]*/tests/[^/]*'|xargs -I {} dirname {}|sed 's/\(tests\).*/\1/g' + echo ${CHANGED_FILES} |grep -o 'task/[^\/]*/[^\/]*/tests/[^/]*'|xargs -I {} dirname {}|sed 's/\(tests\).*/\1/g' # detect for changes in the task manifest - echo ${CHANGED_FILES} |grep 'task/[^\/]*/[^\/]*/*[^/]*.yaml'|xargs -I {} dirname {}|awk '{print $1"/tests"}' + echo ${CHANGED_FILES} |grep -o 'task/[^\/]*/[^\/]*/*[^/]*.yaml'|xargs -I {} dirname {}|awk '{print $1"/tests"}' +} + +function get_new_changed_tasks() { + echo ${CHANGED_FILES} |grep -o 'task/[^\/]*/[^\/]*/*[^/]*.yaml' } # Signal (as return code and in the logs) that all E2E tests passed. @@ -106,6 +110,17 @@ function test_yaml_can_install() { done } +function validate_task_yaml_using_tektor() { + all_tasks="$*" + for task in ${all_tasks}; do + # Skip if it is kustomize related yaml files + if [[ ${task} == *"kustomization.yaml" || ${task} == *"patch.yaml" || ${task} == *"recipe.yaml" ]]; then + continue + fi + tektor validate ${task} + done +} + function test_resource_creation() { local runtest declare -A resource_to_wait_for diff --git a/test/test-tasks.sh b/test/test-tasks.sh index f03b6c0cd..daad54756 100755 --- a/test/test-tasks.sh +++ b/test/test-tasks.sh @@ -7,7 +7,7 @@ clean() { rm -f ${TMPF}; } trap clean EXIT # Configure the number of parallel tests running at the same time, start from 0 -MAX_NUMBERS_OF_PARALLEL_TASKS=7 # => 8 +MAX_NUMBERS_OF_PARALLEL_TASKS=2 # => 8 # You can ignore some yaml tests by providing the TEST_YAML_IGNORES variable # with the test name separated by a space, for example: @@ -30,8 +30,10 @@ set -o pipefail all_tests=$(echo task/*/*/tests) +# Run all the task tests, if tests are modified [[ -z ${TEST_RUN_ALL_TESTS} ]] && [[ ! -z $(detect_changed_e2e_test) ]] && TEST_RUN_ALL_TESTS=1 +# Run only the tests related to the task modified in the PR if [[ -z ${TEST_RUN_ALL_TESTS} ]];then all_tests=$(detect_new_changed_resources|sort -u || true) [[ -z ${all_tests} ]] && { @@ -40,6 +42,11 @@ if [[ -z ${TEST_RUN_ALL_TESTS} ]];then } fi +# Validate task yamls using tektor linter +tasks_changed=$(get_new_changed_tasks) +validate_task_yaml_using_tektor "${tasks_changed}" + +# Validate task yamls can be installed test_yaml_can_install "${all_tests}" function test_resources {