From 029c5387d56a2104b9bfc275d6f7935c78afe32b Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Tue, 6 Jun 2023 13:32:52 +0200 Subject: [PATCH] Skip tests if all changes in docs (#6870) * Skip tests if all changes in website (and .ibm for testing this PR) * Use Merge base * Add rule for podman-test on GH Actions --- .github/workflows/podman-test.yaml | 7 ++++++- .ibm/pipelines/functions.sh | 26 ++++++++++++++++++++++++ .ibm/pipelines/kubernetes-tests.sh | 2 ++ .ibm/pipelines/nocluster-tests.sh | 2 ++ .ibm/pipelines/openshift-tests.sh | 2 ++ .ibm/pipelines/openshift-unauth-tests.sh | 2 ++ .ibm/pipelines/unit-tests.sh | 2 ++ .ibm/pipelines/validate.sh | 2 ++ .ibm/pipelines/windows-test.sh | 5 ++++- 9 files changed, 48 insertions(+), 2 deletions(-) diff --git a/.github/workflows/podman-test.yaml b/.github/workflows/podman-test.yaml index 64e50ab8975..9e651cc5805 100644 --- a/.github/workflows/podman-test.yaml +++ b/.github/workflows/podman-test.yaml @@ -3,7 +3,12 @@ on: pull_request: branches: - main - + paths-ignore: + - 'docs/**' + - CONTRIBUTING.md + - OWNERS + - README.md + - USAGE_DATA.md jobs: ODO-PODMAN-TEST: diff --git a/.ibm/pipelines/functions.sh b/.ibm/pipelines/functions.sh index 304da985b82..35b9c01bdf9 100644 --- a/.ibm/pipelines/functions.sh +++ b/.ibm/pipelines/functions.sh @@ -44,3 +44,29 @@ cleanup_namespaces() { fi done } + +skip_if_only() { + echo "Checking if tests need to be executed..." + NAMES=$(git diff --merge-base --name-only main) + for change in ${NAMES}; do + skip $change + if [[ $? == 0 ]]; then + return + fi + done + echo " => Skipping the tests." + exit 0 +} + +skip() { + SKIP_IF_ONLY="docs/ CONTRIBUTING.md OWNERS README.md USAGE_DATA.md" + change=$1 + for skip in ${SKIP_IF_ONLY}; do + if [[ "${change}" == "${skip}"* ]]; then + echo " - ${change} is ${skip}*" + return 1 + fi + done + echo " - $change not in $SKIP_IF_ONLY" + return 0 +} diff --git a/.ibm/pipelines/kubernetes-tests.sh b/.ibm/pipelines/kubernetes-tests.sh index 5bc9ed4bd52..4d174710353 100755 --- a/.ibm/pipelines/kubernetes-tests.sh +++ b/.ibm/pipelines/kubernetes-tests.sh @@ -4,6 +4,8 @@ LOGFILE="pr-${GIT_PR_NUMBER}-kubernetes-tests-${BUILD_NUMBER}" source .ibm/pipelines/functions.sh +skip_if_only + ibmcloud login --apikey "${API_KEY_QE}" ibmcloud target -r "${IBM_REGION}" ibmcloud ks cluster config --cluster "${IBM_KUBERNETES_ID}" --admin diff --git a/.ibm/pipelines/nocluster-tests.sh b/.ibm/pipelines/nocluster-tests.sh index ab524c9b726..51e8ffcbc66 100755 --- a/.ibm/pipelines/nocluster-tests.sh +++ b/.ibm/pipelines/nocluster-tests.sh @@ -4,6 +4,8 @@ LOGFILE="pr-${GIT_PR_NUMBER}-nocluster-tests-${BUILD_NUMBER}" source .ibm/pipelines/functions.sh +skip_if_only + ibmcloud login --apikey "${API_KEY_QE}" ibmcloud target -r "${IBM_REGION}" diff --git a/.ibm/pipelines/openshift-tests.sh b/.ibm/pipelines/openshift-tests.sh index d3512666b27..9994984785e 100755 --- a/.ibm/pipelines/openshift-tests.sh +++ b/.ibm/pipelines/openshift-tests.sh @@ -4,6 +4,8 @@ LOGFILE="pr-${GIT_PR_NUMBER}-openshift-tests-${BUILD_NUMBER}" source .ibm/pipelines/functions.sh +skip_if_only + ibmcloud login --apikey "${API_KEY_QE}" ibmcloud target -r eu-de ibmcloud oc cluster config -c "${CLUSTER_ID}" diff --git a/.ibm/pipelines/openshift-unauth-tests.sh b/.ibm/pipelines/openshift-unauth-tests.sh index c098940eb6e..eeaae200f1a 100755 --- a/.ibm/pipelines/openshift-unauth-tests.sh +++ b/.ibm/pipelines/openshift-unauth-tests.sh @@ -4,6 +4,8 @@ LOGFILE="pr-${GIT_PR_NUMBER}-openshift-unauth-tests-${BUILD_NUMBER}" source .ibm/pipelines/functions.sh +skip_if_only + ibmcloud login --apikey "${API_KEY_QE}" ibmcloud target -r eu-de ibmcloud oc cluster config -c "${CLUSTER_ID}" diff --git a/.ibm/pipelines/unit-tests.sh b/.ibm/pipelines/unit-tests.sh index fa404d67205..4bec4d17448 100755 --- a/.ibm/pipelines/unit-tests.sh +++ b/.ibm/pipelines/unit-tests.sh @@ -7,6 +7,8 @@ LOGFILE="pr-${GIT_PR_NUMBER}-unit-tests-${BUILD_NUMBER}" source .ibm/pipelines/functions.sh +skip_if_only + ( set -e make test diff --git a/.ibm/pipelines/validate.sh b/.ibm/pipelines/validate.sh index 53f2d51b681..d3b1afadd20 100755 --- a/.ibm/pipelines/validate.sh +++ b/.ibm/pipelines/validate.sh @@ -7,6 +7,8 @@ LOGFILE="pr-${GIT_PR_NUMBER}-Validate-tests-${BUILD_NUMBER}" source .ibm/pipelines/functions.sh +skip_if_only + ( set -e make goget-tools diff --git a/.ibm/pipelines/windows-test.sh b/.ibm/pipelines/windows-test.sh index 7fd84b701ee..86df02e7617 100755 --- a/.ibm/pipelines/windows-test.sh +++ b/.ibm/pipelines/windows-test.sh @@ -7,6 +7,10 @@ set -x +source .ibm/pipelines/functions.sh + +skip_if_only + LOGFILE="pr-${GIT_PR_NUMBER}-windows-tests-${BUILD_NUMBER}" export REPO=${REPO:-"https://github.com/redhat-developer/odo"} #copy test script inside /tmp/ @@ -19,7 +23,6 @@ RESULT=$? echo "RESULT: $RESULT" # save log -source .ibm/pipelines/functions.sh ibmcloud login --apikey "${API_KEY}" -r "${IBM_REGION}" sshpass -p $WINDOWS_PASSWORD scp -o StrictHostKeyChecking=no Administrator@$WINDOWS_IP:~/AppData/Local/Temp/${LOGFILE} /tmp/${LOGFILE} save_logs "${LOGFILE}" "Windows Tests (OCP)" $RESULT