From 49db4a59372418e12d5483694c5f429e4e42059b Mon Sep 17 00:00:00 2001 From: Sushanta Das Date: Fri, 15 Nov 2024 13:14:08 +0530 Subject: [PATCH] Add task-lint CI --- .github/workflows/run-task-tests.yaml | 2 +- .github/workflows/task-lint.yaml | 53 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/task-lint.yaml diff --git a/.github/workflows/run-task-tests.yaml b/.github/workflows/run-task-tests.yaml index 342c1f3bd4..8888a83c93 100644 --- a/.github/workflows/run-task-tests.yaml +++ b/.github/workflows/run-task-tests.yaml @@ -36,7 +36,7 @@ jobs: with: repository: 'konflux-ci/konflux-ci' path: konflux-ci - commit: f6d9d0fe8f34199eb118febcbf7f7944ae7772a9 + ref: f6d9d0fe8f34199eb118febcbf7f7944ae7772a9 - name: Create k8s Kind Cluster if: steps.changed-files.outputs.any_changed == 'true' diff --git a/.github/workflows/task-lint.yaml b/.github/workflows/task-lint.yaml new file mode 100644 index 0000000000..7a4f2bec21 --- /dev/null +++ b/.github/workflows/task-lint.yaml @@ -0,0 +1,53 @@ +--- +name: tasklint +"on": + pull_request: + branches: [main] +jobs: + tasklint: + runs-on: ubuntu-latest + steps: + - name: Get all changed files in the PR from task directories + id: changed-files + uses: tj-actions/changed-files@v45 + with: + # Avoid using single or double quotes for multiline patterns + files: | + task/*/*/*.yaml + + - name: Setup Go + if: steps.changed-files.outputs.any_changed == 'true' + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Install tektor + if: steps.changed-files.outputs.any_changed == 'true' + run: | + go install github.com/lcarva/tektor@4e9385885cc638fe337bcb9cc5f3d64cc8c262c5 + + - name: Run tektor linter + if: steps.changed-files.outputs.any_changed == 'true' + env: + CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + echo "Files changed in PR: ${CHANGED_FILES}" + function print_changed_tasks_to_console() { + echo ${CHANGED_FILES} | grep -o 'task/[^\/]*/[^\/]*/*[^/]*.yaml' || true + } + 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 + } + + # Validate task yamls using tektor linter + tasks_changed=$(print_changed_tasks_to_console) + [[ ! -z ${tasks_changed} ]] && { + validate_task_yaml_using_tektor "${tasks_changed}" + }