Skip to content

Commit

Permalink
tests for inidividual tasks/stepactions
Browse files Browse the repository at this point in the history
  • Loading branch information
tisutisu committed Nov 4, 2024
1 parent 421ee9f commit 59f79e3
Show file tree
Hide file tree
Showing 8 changed files with 560 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/run-task-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Run Task Tests

"on":
pull_request

jobs:
run-task-tests:
runs-on: ubuntu-22.04
steps:
- name: Get all changed files related to task and test
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 git-clone task test
if: steps.changed-files.outputs.any_changed == 'true'
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "CHANGED_FILES IN THE PR: ${CHANGED_FILES}"
cd $GITHUB_WORKSPACE/build-definitions
# ./test/run-test.sh task git-clone 0.1
./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

0 comments on commit 59f79e3

Please sign in to comment.