Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tisutisu committed Nov 15, 2024
1 parent 4a28349 commit 9dd1446
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 139 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/run-task-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ jobs:
tool-cache: false
docker-images: false

- name: Setup Go
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@latest
- name: Checkout build-defintions Repository
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/checkout@v3
Expand All @@ -46,6 +36,7 @@ jobs:
with:
repository: 'konflux-ci/konflux-ci'
path: konflux-ci
ref: f6d9d0fe8f34199eb118febcbf7f7944ae7772a9

- name: Create k8s Kind Cluster
if: steps.changed-files.outputs.any_changed == 'true'
Expand All @@ -68,13 +59,13 @@ jobs:
- name: Wait for the dependencies to be ready
if: steps.changed-files.outputs.any_changed == 'true'
run: |
#cd $GITHUB_WORKSPACE/konflux-ci
cd $GITHUB_WORKSPACE/konflux-ci
./wait-for-all.sh
- name: Deploying Konflux
if: steps.changed-files.outputs.any_changed == 'true'
run: |
#cd $GITHUB_WORKSPACE/konflux-ci
cd $GITHUB_WORKSPACE/konflux-ci
./deploy-konflux.sh
- name: List namespaces
Expand All @@ -85,7 +76,7 @@ jobs:
- name: Deploy test resources
if: steps.changed-files.outputs.any_changed == 'true'
run: |
#cd $GITHUB_WORKSPACE/konflux-ci
cd $GITHUB_WORKSPACE/konflux-ci
./deploy-test-resources.sh
- name: Run the task tests
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/task-lint.yaml
Original file line number Diff line number Diff line change
@@ -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/**
- 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: |
#!/bin/bash
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}"
}
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ Specify the Quay repository using the `QUAY_NAMESPACE` environment variable in t
./hack/test-shellspec.sh`
```
## Testing Tasks
Tasks can be validated in the GithubActions CI setup with this repository.
If you have a directory called `tests/` inside the task directory, CI will create a random `Namespace`, apply the task first in the namespace and then all the test yaml files (containing TaskRun or PipelineRun) inside the `tests` directory.
We can use the functionality of running scripts before applying the tested task or the other yaml files. There are two different scripts that are automatically applied if present. These are applied using the `source` bash script:
- `pre-apply-task-hook.sh`: Script to run before applying the task, it can include `kubectl` commands to apply any kubernetes resources in the cluster
- `pre-apply-taskrun-hook.sh`: Script to run before applying the task run or pipeline run yaml files, it can also include `kubectl` commands to apply any kubernetes resources in the cluster
For example refer: Git Clone task [tests](./task/git-clone/0.1/tests/run.yaml)
CI also validates the task yamls using [tektor](https://github.com/lcarva/tektor)
### Running Task tests locally
Prerequisites: Deploy [upstream konflux](https://github.com/konflux-ci/konflux-ci?tab=readme-ov-file#bootstrapping-the-cluster) locally.
A helper script called `run-test.sh` is present inside `test` directory to help the developer run the test. Just specify resource type as first argument, resource name as second argument and the version as third argument i.e:
```
./test/run-test.sh task git-clone 0.1
```
and it will use your current kubernetes context to run the test and show you the outputs similar to the CI.
### Compliance
Task definitions must comply with the [Enterprise Contract](https://enterprisecontract.dev/) policies.
Expand Down
59 changes: 0 additions & 59 deletions hack/run-test.sh

This file was deleted.

2 changes: 1 addition & 1 deletion task/git-clone/0.1/tests/pre-apply-taskrun-hook.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

echo "an example of pre-apply-taskrun-hook script"
echo "an example of pre-apply-taskrun-hook script"
Loading

0 comments on commit 9dd1446

Please sign in to comment.