Skip to content

Commit

Permalink
KOGITO-7101 Correct DSL tests (apache#435)
Browse files Browse the repository at this point in the history
* KOGITO-7101 Correct DSL tests

* correction

* update
  • Loading branch information
radtriste committed May 5, 2022
1 parent e813883 commit f56a5e3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 48 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/jenkins-dsl-downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,15 @@ jobs:
with:
java-version: 11

- name: Setup base branch
if: matrix.repository != 'optaplanner-quickstarts' || github.base_ref != 'main'
run: |
echo 'BASE_BRANCH=${{ github.base_ref }}' >> $GITHUB_ENV
- name: Setup correct base branch for optaplanner-quickstarts
if: github.base_ref == 'main' && matrix.repository == 'optaplanner-quickstarts'
run: |
echo 'BASE_BRANCH=development' >> $GITHUB_ENV
- name: Test DSL
run: cd .ci/jenkins/dsl && ./test.sh -r ${{ matrix.repository }} -b ${{ github.head_ref }} -o ${{ github.event.pull_request.user.login }} -t ${{ github.base_ref }} -a ${{ github.event.pull_request.base.user.login }} .ci/jenkins/dsl
run: .ci/jenkins/dsl/test.sh -o ${{ matrix.repository }} -h ${{ github.head_ref }} -r ${{ github.event.pull_request.head.repo.full_name }} -b ${{ env.BASE_BRANCH }} -t ${{ github.event.pull_request.base.repo.full_name }} .ci/jenkins/dsl
2 changes: 1 addition & 1 deletion .github/workflows/jenkins-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ jobs:
java-version: 11

- name: Test DSL
run: cd .ci/jenkins/dsl && ./test.sh -b ${{ github.head_ref }} -o ${{ github.event.pull_request.user.login }} -t ${{ github.base_ref }} -a ${{ github.event.pull_request.base.user.login }}
run: .ci/jenkins/dsl/test.sh -h ${{ github.head_ref }} -r ${{ github.event.pull_request.head.repo.full_name }} -b ${{ github.base_ref }} -t ${{ github.event.pull_request.base.repo.full_name }} .ci/jenkins/dsl
4 changes: 2 additions & 2 deletions dsl/seed/scripts/copy_jobs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

script_dir_path=`dirname "${BASH_SOURCE[0]}"`
script_dir_path=$(cd `dirname "${BASH_SOURCE[0]}"`; pwd -P)
seed_dir="${script_dir_path}/.."

echo '----- Copying jobs.groovy for testing'
echo "----- Copying jobs.groovy for testing from $(pwd)"
cp jobs.groovy ${seed_dir}/jobs/
94 changes: 54 additions & 40 deletions dsl/seed/scripts/seed_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash

### This script should be launch by any dependent DSL scripts generation repo for local testing of changes
### Ideal dependent repo should have a `local_test.sh` script located in `.ci/jenkins/dsl` folder
Expand All @@ -10,7 +10,7 @@
# chmod u+x ${file}
# ${file} $1

SCRIPT_DIR_PATH=`dirname "${BASH_SOURCE[0]}"`
script_dir_path=$(cd `dirname "${BASH_SOURCE[0]}"`; pwd -P)

TEMP_DIR=`mktemp -d`
GIT_SERVER='github.com'
Expand All @@ -19,57 +19,54 @@ usage() {
echo "Usage: $(basename $0) [-b BRANCH] [-o GIT_OWNER] [PATH]"
echo
echo 'Options: (only used for any repository different from current pipelines)'
echo ' -b BRANCH Git Branch to checkout'
echo ' -o OWNER Git Owner to checkout'
echo ' -t TARGET BRANCH PR target branch'
echo ' -a TARGET_AUTHOR PR target author'
echo ' -r FULL_REPOSITORY Full name of the repository, aka `owner/repo`'
echo ' -o OVERRIDE_REPOSITORY Override the repository to check'
echo ' -h BRANCH Git Branch to checkout'
echo ' -t TARGET FULL_REPOSITORY Full name of the PR target repository, aka `owner/repo`'
echo ' -b TARGET_BRANCH PR target branch'
echo ' -r REPOSITORY Repository to test jobs from. Please reference the PATH if the jobs.groovy file is not present at the root of the project'
echo ' -p PATH_TO_PIPELINES Absolute path to local pipelines repository. Else the pipelines repository will be checked out'
echo ' PATH Path to test'
echo
}

retrieve_current_repository() {
sub_git_url=$(echo ${git_url} | awk -F"${GIT_SERVER}" '{print $2}')
[[ ${sub_git_url} = :* ]] && sub_git_url="${sub_git_url:1}"
[[ ${sub_git_url} = /* ]] && sub_git_url="${sub_git_url:1}"
local current_repository=$(echo ${sub_git_url} | awk -F'/' '{print $2}' | awk -F'.' '{print $1}')
echo "${current_repository}"
}

checkout_repository() {
local repository=$1
local output_dir=$2

echo "----- Cloning ${repository} repo from ${owner} on branch ${branch}"
git clone --single-branch --depth 1 --branch ${branch} ${git_server}${owner}/${repository}.git ${output_dir}
echo "----- Cloning ${git_server}${owner}/${repository} repo on branch ${branch}"
git clone --single-branch --depth 1 --branch ${branch} ${git_server}${owner}/${repository} ${output_dir}
clone_status=$?

set -e

if [ "${clone_status}" != '0' ]; then
echo "[WARN] Error cloning ${repository} repo from ${target_author} on branch ${target_branch}"
echo "----- Cloning ${repository} repo from ${target_author} on branch ${target_branch}"
git clone --single-branch --depth 1 --branch ${target_branch} ${git_server}${target_author}/${repository}.git ${output_dir}
echo "[WARN] Error cloning ${git_server}${owner}/${repository} on branch ${target_branch}"
echo "----- Cloning ${git_server}${target_owner}/${target_repository} on branch ${target_branch}"
git clone --single-branch --depth 1 --branch ${target_branch} ${git_server}${target_owner}/${target_repository} ${output_dir}
else
echo "Clone succeeded"
fi

set +e
}

full_repository=
repository=
branch=
owner=
target_full_repository=
target_branch='main'
target_author='kiegroup'
repository=
pipelines_repo=

while getopts "b:o:t:a:r:p:h" i
while getopts "r:o:h:t:b:p:h" i
do
case "$i"
in
b) branch=${OPTARG} ;;
o) owner=${OPTARG} ;;
t) target_branch=${OPTARG} ;;
o) target_author=${OPTARG} ;;
r) repository=${OPTARG} ;;
r) full_repository=${OPTARG} ;;
o) repository=${OPTARG}; target_repository=${repository} ;;
h) branch=${OPTARG} ;;
t) target_full_repository=${OPTARG} ;;
b) target_branch=${OPTARG} ;;
p) pipelines_repo=${OPTARG} ;;
h) usage; exit 0 ;;
\?) usage; exit 1 ;;
Expand Down Expand Up @@ -101,38 +98,55 @@ if [ -z "${branch}" ]; then
echo "Got current branch = ${branch}"
fi

# retrieve owner
if [ -z "${owner}" ]; then
owner=$(echo ${git_url} | awk -F"${git_server}" '{print $2}' | awk -F'/' '{print $1}')
echo "Got current owner = ${owner}"
# parse full repository
if [ -z "${full_repository}" ]; then
full_repository=$(echo ${git_url} | awk -F"${git_server}" '{print $2}')
fi
owner=$(echo ${full_repository} | awk -F/ '{print $1}')
if [ -z "${repository}" ]; then
repository=$(echo ${full_repository} | awk -F/ '{print $2}' | awk -F'.' '{print $1}')
fi

echo "branch...................${branch}"
if [ -z "${target_full_repository}" ]; then
target_owner="kiegroup"
target_repository=${repository}
else
target_owner=$(echo ${target_full_repository} | awk -F/ '{print $1}')
if [ -z "${target_repository}" ]; then
target_repository=$(echo ${target_full_repository} | awk -F/ '{print $2}' | awk -F'.' '{print $1}')
fi
fi

echo "git_server...............${git_server}"
echo "owner....................${owner}"
echo "target_branch............${target_branch}"
echo "target_author............${target_author}"
echo "repository...............${repository}"
echo "branch...................${branch}"
echo "target_owner.............${target_owner}"
echo "target_repository........${target_repository}"
echo "target_branch............${target_branch}"
echo "pipelines_repo...........${pipelines_repo}"

current_repository="$(echo ${git_url} | awk -F"${git_server}" '{print $2}' | awk -F'/' '{print $2}' | awk -F'.' '{print $1}')"
echo "Got current repository = ${current_repository}"

# retrieve repository
if [ -z ${repository} ]; then
repository="$(retrieve_current_repository)"
echo "Got current repository = ${repository}"
else
if [ "${repository}" != "${current_repository}" ]; then
echo "Current repository is not the right one, checking out ${repository}"
repo_tmp_dir=`mktemp -d`
checkout_repository "${repository}" "${repo_tmp_dir}"
echo "Going into ${repository} directory"
cd ${repo_tmp_dir}
fi

if [ ! -z "${dsl_path}" ]; then
echo "Moving to ${dsl_path}"
cd ${dsl_path}
fi

if [ "${repository}" = 'kogito-pipelines' ]; then
echo '----- Copying seed repo'
mkdir -p ${TEMP_DIR}/dsl
cp -r ${SCRIPT_DIR_PATH}/../../../dsl/seed ${TEMP_DIR}/dsl
cp -r ${script_dir_path}/../../../dsl/seed ${TEMP_DIR}/dsl
else
if [ -z ${pipelines_repo} ]; then
checkout_repository 'kogito-pipelines' "${TEMP_DIR}"
Expand Down
9 changes: 5 additions & 4 deletions dsl/seed/scripts/test_jobs.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash -e

script_dir_path=`dirname "${BASH_SOURCE[0]}"`
script_dir_path=$(cd `dirname "${BASH_SOURCE[0]}"`; pwd -P)
seed_dir="${script_dir_path}/.."

echo '----- Launch tests'
echo "Results will be available here after execution: ${seed_dir}/build/reports/tests/test/classes/org.kie.jenkins.jobdsl.JobScriptsSpec.html"
cd ${seed_dir} && ./gradlew clean test
cd ${seed_dir}
echo "----- Launch tests in $(pwd)"
echo "Results will be available here after execution: $(pwd)/build/reports/tests/test/classes/org.kie.jenkins.jobdsl.JobScriptsSpec.html"
./gradlew clean test

0 comments on commit f56a5e3

Please sign in to comment.