Skip to content

Commit

Permalink
Run all tests if changes are made to test/ dir
Browse files Browse the repository at this point in the history
In previous commit, CI was modified to run only on those hub components
where the changes were made but wasn't capable enough to run whole test
suite if the changes were made in `test/` dir ie if the CI script was
modified then CI should run on all the hub components.

Also CI wasn't running API tests if the changes were made in go.mod or
go.sum thus skipping one scenario.

This commit fixes all the above issues.

Signed-off-by: vinamra28 <[email protected]>
  • Loading branch information
vinamra28 authored and tekton-robot committed Aug 1, 2022
1 parent 470144a commit 5f1ca75
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions test/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ declare -r SCRIPT_DIR=$(cd $(dirname "$SCRIPT_PATH") && pwd)
declare -r API_DIR="$SCRIPT_DIR/../api"
declare -r UI_DIR="$SCRIPT_DIR/../ui"

# Define this variable if you want to run all tests and not just the modified one.
TEST_RUN_ALL_TESTS=${TEST_RUN_ALL_TESTS:-""}

source $(dirname $0)/../vendor/github.com/tektoncd/plumbing/scripts/presubmit-tests.sh

detect_changes() {
local dir=${1}
git --no-pager diff --name-only "${PULL_BASE_SHA}".."${PULL_PULL_SHA}"|grep "${dir}"
}

[[ -z ${TEST_RUN_ALL_TESTS} ]] && [[ ! -z $(detect_changes "test") ]] && TEST_RUN_ALL_TESTS=1

info() {
echo "INFO: $@"
}
Expand All @@ -58,7 +63,7 @@ install-node() {
node --version
}

ui-unittest(){
ui-unittest() {
install-node

make ui-test || {
Expand All @@ -80,7 +85,7 @@ set-pg-passwd() {
"psql -c \"ALTER USER postgres PASSWORD '$pass';\""
}

api-unittest(){
api-unittest() {
install-postgres
source $API_DIR/test/config/env.test
set-pg-passwd "$POSTGRES_PASSWORD"
Expand Down Expand Up @@ -136,14 +141,14 @@ goa-gen() {
fi
}

api-build(){
api-build() {
make api-build || {
err 'Api build failed'
return 1
}
}

ui-build(){
ui-build() {
install-node

make ui-build || {
Expand All @@ -152,7 +157,7 @@ ui-build(){
}
}

api-e2e(){
api-e2e() {
info Runnning Hub CLI E2E tests

go mod vendor
Expand All @@ -167,20 +172,24 @@ api-e2e(){

}

detect_api_related_changes() {
[[ ! -z $(detect_changes "api") ]] || [[ ! -z $(detect_changes "go.*") ]] && echo "changes detected related to API"
}

### presubmit hooks ###

build_tests() {
# run in a subshell so that path and shell options -eu -o pipefail will
# will remain the same when it exits
[[ ! -z $(detect_changes "api") ]] && {
[[ ! -z ${TEST_RUN_ALL_TESTS} ]] || [[ ! -z $(detect_api_related_changes) ]] && {
(
set -eu -o pipefail

api-build
) || exit 1
} || echo "No changes detected related to API"

[[ ! -z $(detect_changes "ui") ]] && {
[[ ! -z ${TEST_RUN_ALL_TESTS} ]] || [[ ! -z $(detect_changes "ui") ]] && {
(
set -eu -o pipefail

Expand All @@ -192,7 +201,7 @@ build_tests() {
unit_tests() {
# run in a subshell so that path and shell options -eu -o pipefail will
# will remain the same when it exits
[[ ! -z $(detect_changes "api") ]] && {
[[ ! -z ${TEST_RUN_ALL_TESTS} ]] || [[ ! -z $(detect_api_related_changes) ]] && {
(
set -eu -o pipefail

Expand All @@ -207,7 +216,7 @@ unit_tests() {
) || exit 1
} || echo "No changes detected related to API"

[[ ! -z $(detect_changes "ui") ]] && {
[[ ! -z ${TEST_RUN_ALL_TESTS} ]] || [[ ! -z $(detect_changes "ui") ]] && {
(
set -eu -o pipefail

Expand Down

0 comments on commit 5f1ca75

Please sign in to comment.