Skip to content

Commit

Permalink
Merge branch 'main' into paketo-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoulliard authored Dec 5, 2024
2 parents b48867b + 8720787 commit 6bc3dbb
Show file tree
Hide file tree
Showing 102 changed files with 5,049 additions and 613 deletions.
12 changes: 12 additions & 0 deletions .github/actions/install-tkn/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yamllint disable-file
---
name: Install tkn
runs:
using: "composite"
steps:
- run: |
curl -LO "https://github.com/tektoncd/cli/releases/download/v${TKN_CLI_VERSION}/tektoncd-cli-${TKN_CLI_VERSION}_Linux-64bit.deb"
sudo dpkg -i ./tektoncd-cli-${TKN_CLI_VERSION}_Linux-64bit.deb
shell: bash
env:
TKN_CLI_VERSION: 0.38.1
7 changes: 7 additions & 0 deletions .github/resources/workspace-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi
187 changes: 187 additions & 0 deletions .github/scripts/test_tekton_tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#!/bin/bash

set -e
# This script will run task tests for all task directories
# provided either via TEST_ITEMS env var, or as arguments
# when running the script.
#
# Requirements:
# - Connection to a running k8s cluster (e.g. kind)
# - upstream konflux-ci installed on the cluster ( Follow steps from: https://github.com/konflux-ci/konflux-ci?tab=readme-ov-file#bootstrapping-the-cluster)
# - tkn installed
#
# Examples of usage:
# export TEST_ITEMS="task/git-clone/0.1 some/other/dir"
# ./test_tekton_tasks.sh
#
# or
#
# ./test_tekton_tasks.sh task/git-clone/0.1 some/other/dir

# Define a custom kubectl path if you like
KUBECTL_CMD=${KUBECTL_CMD:-kubectl}

# yield empty strings for unmatched patterns
shopt -s nullglob

WORKSPACE_TEMPLATE=${BASH_SOURCE%/*/*}/resources/workspace-template.yaml

if [[ -z $@ || ${1} == "-h" ]]; then
cat <<EOF
Error: No task directories.
Usage:
$0 [item1] [item2] [...]
Example: ./.github/scripts/test_tekton_tasks.sh task/git-clone/0.1
or
export TEST_ITEMS="item1 item2 ..."
$0
Items can be task directories including version or paths to task test yaml files (useful when working on a single test)
EOF
exit 1
fi

if [ $# -gt 0 ]; then
TEST_ITEMS=$@
fi

# Check that all directories or test yamls exist. If not, fail
for ITEM in $TEST_ITEMS; do
if [[ "$ITEM" == *tests/test-*.yaml && -f "$ITEM" ]]; then
true
elif [[ -d "$ITEM" ]]; then
true
else
echo "Error: Invalid test yaml file or task directory: $ITEM"
exit 1
fi
done

for ITEM in $TEST_ITEMS; do
echo "Test item: $ITEM"
TASK_DIR=$(echo $ITEM | cut -d '/' -f -3)
TASK_NAME=$(echo $ITEM | cut -d '/' -f 2)
TASK_VERSION=$(echo $ITEM | cut -d '/' -f 3)
echo "DEBUG: Task name: $TASK_NAME"
echo "DEBUG: Task version: $TASK_VERSION"

TASK_VERSION_WITH_HYPHEN="$(echo $TASK_VERSION | tr '.' '-')"
TEST_NS="${TASK_NAME}-${TASK_VERSION_WITH_HYPHEN}"

TASK_PATH=${TASK_DIR}/${TASK_NAME}.yaml
# check if task file exists or not
if [ ! -f $TASK_PATH ]; then
echo "ERROR: Task file does not exist: $TASK_PATH"
exit 1
fi

# Check if tests dir exists under task dir
TESTS_DIR=${TASK_DIR}/tests
if [ ! -d $TESTS_DIR ]; then
echo "ERROR: tests dir does not exist: $TESTS_DIR"
exit 1
fi

# check if tests yamls exists
if [[ "$ITEM" == *tests/test-*.yaml ]]; then
TEST_PATHS=($ITEM)
else
TEST_PATHS=($TESTS_DIR/test-*.yaml)
fi
if [ ${#TEST_PATHS[@]} -eq 0 ]; then
echo "WARNING: No tests for test item $ITEM ... Skipping..."
continue
fi

# Use a copy of the task file to prevent modifying the original task file
TASK_COPY=$(mktemp /tmp/task.XXXXXX)
clean() { rm -f ${TASK_COPY}; }
trap clean EXIT

cp "$TASK_PATH" "$TASK_COPY"

# run the pre-apply-task-hook.sh if exists
if [ -f ${TESTS_DIR}/pre-apply-task-hook.sh ]
then
echo "Found pre-apply-task-hook.sh file in dir: $TESTS_DIR. Executing..."
${TESTS_DIR}/pre-apply-task-hook.sh "$TASK_COPY"
fi

# Create test namespace
${KUBECTL_CMD} create namespace ${TEST_NS}

# Create the service account appstudio-pipeline (konflux spedific requirement)
$KUBECTL_CMD create sa appstudio-pipeline -n ${TEST_NS}

# dry-run this YAML to validate and also get formatting side-effects.
${KUBECTL_CMD} -n ${TEST_NS} create -f ${TASK_COPY} --dry-run=client -o yaml

echo "INFO: Installing task"
${KUBECTL_CMD} apply -f "$TASK_COPY" -n "$TEST_NS"

for TEST_PATH in ${TEST_PATHS[@]}; do
echo "========== Starting Test Pipeline: $TEST_PATH =========="
echo "INFO: Installing test pipeline: $TEST_PATH"
${KUBECTL_CMD} -n ${TEST_NS} apply -f $TEST_PATH
TEST_NAME=$(yq '.metadata.name' $TEST_PATH)

# Sometimes the pipeline is not available immediately
while ! ${KUBECTL_CMD} -n ${TEST_NS} get pipeline $TEST_NAME > /dev/null 2>&1; do
echo "DEBUG: Pipeline $TEST_NAME not ready. Waiting 5s..."
sleep 5
done

PIPELINERUN=$(tkn p start $TEST_NAME -n ${TEST_NS} -w name=tests-workspace,volumeClaimTemplateFile=$WORKSPACE_TEMPLATE -o json | jq -r '.metadata.name')
echo "INFO: Started pipelinerun: $PIPELINERUN"
sleep 1 # allow a second for the prun object to appear (including a status condition)
while [ "$(${KUBECTL_CMD} get pr $PIPELINERUN -n ${TEST_NS} -o=jsonpath='{.status.conditions[0].status}')" == "Unknown" ]; do
echo "DEBUG: PipelineRun $PIPELINERUN is in progress (status Unknown). Waiting for update..."
sleep 5
done
tkn pr logs $PIPELINERUN -n ${TEST_NS}

PR_STATUS=$(${KUBECTL_CMD} get pr $PIPELINERUN -n ${TEST_NS} -o=jsonpath='{.status.conditions[0].status}')

ASSERT_TASK_FAILURE=$(yq '.metadata.annotations.test/assert-task-failure' < $TEST_PATH)
if [ "$ASSERT_TASK_FAILURE" != "null" ]; then
if [ "$PR_STATUS" == "True" ]; then
echo "INFO: Pipeline $TEST_NAME is succeeded but was expected to fail"
exit 1
else
echo "DEBUG: Pipeline $TEST_NAME failed (expected). Checking that it failed in task ${ASSERT_TASK_FAILURE}..."

# Check that the pipelinerun failed on the tested task and not somewhere else
TASKRUN=$(${KUBECTL_CMD} get pr $PIPELINERUN -n ${TEST_NS} -o json|jq -r ".status.childReferences[] | select(.pipelineTaskName == \"${ASSERT_TASK_FAILURE}\") | .name")
if [ -z "$TASKRUN" ]; then
echo "ERROR: Unable to find task $ASSERT_TASK_FAILURE in childReferences of pipelinerun $PIPELINERUN. Pipelinerun failed earlier?"
exit 1
else
echo "DEBUG: Found taskrun $TASKRUN"
fi
if [ $(${KUBECTL_CMD} get tr $TASKRUN -n ${TEST_NS} -o=jsonpath='{.status.conditions[0].status}') != "False" ]; then
echo "ERROR: Taskrun did not fail - pipelinerun failed later on?"
exit 1
else
echo "INFO: Taskrun failed as expected"
fi

fi
else
if [ "$PR_STATUS" == "True" ]; then
echo "INFO: Pipelinerun $TEST_NAME succeeded"
else
echo "ERROR: Pipelinerun $TEST_NAME failed"
exit 1
fi
fi

echo "========== Completed: $TEST_PATH =========="
done

done
4 changes: 2 additions & 2 deletions .github/workflows/check-buildah-remote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
name: Check Buildah Remote
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
with:
go-version-file: './task-generator/remote/go.mod'
- name: Check buildah remote
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-version-file: './${{matrix.path}}/go.mod'
cache-dependency-path: ./${{matrix.path}}/go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@eab1d2f3d76f26c09e2ab8c957fe5bb64bf46b89
uses: golangci/golangci-lint-action@9e66d46e22c9991dbf33ddab82b6b28b69052dec
with:
working-directory: ${{matrix.path}}
args: "--timeout=10m --build-tags='normal periodic'"
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: '-tags normal,periodic -no-fail -fmt sarif -out results.sarif ${{matrix.path}}/...'
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@3d3d628990a5f99229dd9fa1821cc5a4f31b613b
uses: github/codeql-action/upload-sarif@978ed829bdde7389737ac17d6b144aeed5f9bdad
with:
# Path to SARIF file relative to the root of the repository
sarif_file: results.sarif
92 changes: 92 additions & 0 deletions .github/workflows/run-task-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Run Task Tests

"on":
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
run-task-tests:
runs-on: ubuntu-22.04
# Skipping it temporarily till we fix this workflow
if: false
steps:
- name: Get all changed files in the PR from task directory
id: changed-dirs
uses: tj-actions/changed-files@v45
with:
files: |
task/**
dir_names: "true"
dir_names_max_depth: "3"

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

- name: Install tkn
if: steps.changed-dirs.outputs.any_changed == 'true'
uses: ./build-definitions/.github/actions/install-tkn

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

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

- name: Show version information
if: steps.changed-dirs.outputs.any_changed == 'true'
run: |
kubectl version
kind version
- name: Deploying Dependencies
if: steps.changed-dirs.outputs.any_changed == 'true'
run: |
cd $GITHUB_WORKSPACE/konflux-ci
./deploy-deps.sh
- name: Wait for the dependencies to be ready
if: steps.changed-dirs.outputs.any_changed == 'true'
run: |
cd $GITHUB_WORKSPACE/konflux-ci
./wait-for-all.sh
- name: Deploying Konflux
if: steps.changed-dirs.outputs.any_changed == 'true'
run: |
cd $GITHUB_WORKSPACE/konflux-ci
./deploy-konflux.sh
- name: List namespaces
if: steps.changed-dirs.outputs.any_changed == 'true'
run: |
kubectl get namespace
- name: Deploy test resources
if: steps.changed-dirs.outputs.any_changed == 'true'
run: |
cd $GITHUB_WORKSPACE/konflux-ci
./deploy-test-resources.sh
- name: Run the task tests
if: steps.changed-dirs.outputs.any_changed == 'true'
env:
CHANGED_DIRS: ${{ steps.changed-dirs.outputs.all_changed_files }}
run: |
echo "Task Dirs changed in PR: ${CHANGED_DIRS}"
cd $GITHUB_WORKSPACE/build-definitions
./.github/scripts/test_tekton_tasks.sh ${CHANGED_DIRS}
4 changes: 2 additions & 2 deletions .tekton/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ spec:
taskRef:
name: task-switchboard
params:
- name: pr_number
value: "{{ pull_request_number }}"
- name: revision
value: $(params.revision)
- name: utils_image
value: quay.io/konflux-ci/pull-request-builds:appstudio-utils-{{revision}}
- name: expressions
Expand Down
2 changes: 1 addition & 1 deletion .tekton/tasks/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
type: string
steps:
- name: e2e-test
image: quay.io/redhat-user-workloads/konflux-qe-team-tenant/konflux-e2e/konflux-e2e-tests:4e5e1cded3e2790a328f2c8ce779bd772c602501
image: quay.io/redhat-user-workloads/konflux-qe-team-tenant/konflux-e2e/konflux-e2e-tests:a666fc1761e539cb9ea4f411edc1346430c774ae
command: ["/konflux-e2e/konflux-e2e.test"]
# a la infra-deployment updates, when PRs merge in e2e-tests, PRs will be opened
# against build-definitions to update this tag
Expand Down
Loading

0 comments on commit 6bc3dbb

Please sign in to comment.