Skip to content

Commit

Permalink
Add tektor linter integration
Browse files Browse the repository at this point in the history
  • Loading branch information
tisutisu committed Nov 11, 2024
1 parent a3dec77 commit c703f5d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/run-task-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions test/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion test/test-tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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} ]] && {
Expand All @@ -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 {
Expand Down

0 comments on commit c703f5d

Please sign in to comment.