Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Validate individual tasks/stepactions #1447

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/run-task-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Run Task Tests

"on":
pull_request

jobs:
run-task-tests:
runs-on: ubuntu-22.04
steps:
- name: Get all changed files in the PR from task or test directories
id: changed-files
uses: tj-actions/changed-files@v45
with:
# Avoid using single or double quotes for multiline patterns
files: |
task/**
test/**

- name: Free Disk Space
if: steps.changed-files.outputs.any_changed == 'true'
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
docker-images: false

- name: Checkout build-defintions Repository
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/checkout@v3
with:
ref: "${{ github.event.pull_request.head.sha }}"
path: build-definitions

- name: Checkout konflux-ci/konflux-ci Repository
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/checkout@v3
with:
repository: 'konflux-ci/konflux-ci'
path: konflux-ci

- name: Create k8s Kind Cluster
if: steps.changed-files.outputs.any_changed == 'true'
uses: helm/kind-action@v1
with:
config: konflux-ci/kind-config.yaml

- name: Show version information
if: steps.changed-files.outputs.any_changed == 'true'
run: |
kubectl version
kind version

- name: Deploying Dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: |
cd $GITHUB_WORKSPACE/konflux-ci
./deploy-deps.sh

- name: Wait for the dependencies to be ready
if: steps.changed-files.outputs.any_changed == 'true'
run: |
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
./deploy-konflux.sh

- name: List namespaces
if: steps.changed-files.outputs.any_changed == 'true'
run: |
kubectl get namespace

- name: Deploy test resources
if: steps.changed-files.outputs.any_changed == 'true'
run: |
cd $GITHUB_WORKSPACE/konflux-ci
./deploy-test-resources.sh

- name: Run the task tests
if: steps.changed-files.outputs.any_changed == 'true'
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "CHANGED_FILES: ${CHANGED_FILES}"
cd $GITHUB_WORKSPACE/build-definitions
./test/test-tasks.sh
59 changes: 59 additions & 0 deletions hack/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -ex

cd $(git rev-parse --show-toplevel)
source test/common.sh

if [[ -z ${@} || ${1} == "-h" ]];then
cat <<EOF
This script will run a single task to help developers testing directly a
single task without sending it to CI.

You need to specify the resource kind as the first argument, resource name
as the second argument and the resource version as the second argument.

For example :

${0} task git-clone 0.1

will run the tests for the git-clone task

while

${0} stepaction git-clone 0.1

will run the tests for the git-clone stepaction.

EOF
exit 0
fi

TMPF=$(mktemp /tmp/.mm.XXXXXX)
clean() { rm -f ${TMPF}; }
trap clean EXIT

RESOURCE=${1}
NAME=${2}
VERSION=${3}

resourcedir=${RESOURCE}/${NAME}/${VERSION}

if [[ ! -d ${resourcedir}/tests ]];then
echo "No 'tests' directory is located in ${resourcedir}"
exit 1
fi

tns=${NAME}-${VERSION//./-}

# Delete the tns if already exists
${KUBECTL_CMD} delete ns ${tns} >/dev/null 2>/dev/null || :

${KUBECTL_CMD} create namespace ${tns}

#create appstudio-pipeline SA in the test namespace if not already
if ! ${KUBECTL_CMD} get sa appstudio-pipeline -n ${tns} | grep 'appstudio-pipeline'; then
$KUBECTL_CMD create sa appstudio-pipeline -n ${tns}
fi

test_resource_creation ${RESOURCE}/${NAME}/${VERSION}/tests
4 changes: 4 additions & 0 deletions task/git-clone/0.1/tests/pre-apply-task-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "example of pre-apply-task-hook, this script can be used to run kubernetes commands"
${KUBECTL_CMD} get ns
3 changes: 3 additions & 0 deletions task/git-clone/0.1/tests/pre-apply-taskrun-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "an example of pre-apply-taskrun-hook script"
30 changes: 30 additions & 0 deletions task/git-clone/0.1/tests/run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: git-clone-run-noargs
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
params:
- name: url
value: https://github.com/kelseyhightower/nocode
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: git-clone-run-tag
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: revision
value: 1.0.0
Loading
Loading