From 693d7b953e952be935d7f81981d1dd5b287c4f0d Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 12 Aug 2020 12:08:40 +0200 Subject: [PATCH] ci: skip containerized-tests for doc-only PRs Signed-off-by: Niels de Vos --- containerized-tests.groovy | 33 +++++++++++++++++++++++++++++---- scripts/skip-doc-change.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100755 scripts/skip-doc-change.sh diff --git a/containerized-tests.groovy b/containerized-tests.groovy index f799e7422..acf0ee4c4 100644 --- a/containerized-tests.groovy +++ b/containerized-tests.groovy @@ -2,7 +2,11 @@ def cico_retries = 16 def cico_retry_interval = 60 def ci_git_repo = 'https://github.com/ceph/ceph-csi' def ci_git_branch = 'ci/centos' +def git_repo = 'https://github.com/ceph/ceph-csi' def ref = "master" +def git_since = 'master' +def workdir = '/opt/build/go/src/github.com/ceph/ceph-csi' +def doc_change = 0 node('cico-workspace') { @@ -12,6 +16,29 @@ node('cico-workspace') { changelog: false } + stage('checkout PR') { + if (params.ghprbPullId != null) { + ref = "pull/${ghprbPullId}/head" + } + if (params.ghprbTargetBranch != null) { + git_since = "${ghprbTargetBranch}" + } + + sh "git clone --depth=1 --branch='${git_since}' '${git_repo}' ~/build/ceph-csi" + sh "cd ~/build/ceph-csi && git fetch origin ${ref} && git checkout -b ${ref} FETCH_HEAD" + } + + stage('check doc-only change') { + doc_change = sh( + script: "cd ~/build/ceph-csi && \${OLDPWD}/scripts/skip-doc-change.sh origin/${git_since}", + returnStatus: true) + } + // if doc_change (return value of skip-doc-change.sh is 1, do not run the other stages + if (doc_change == 1) { + currentBuild.result = 'SUCCESS' + return + } + stage('reserve bare-metal machine') { def firstAttempt = true retry(30) { @@ -30,11 +57,9 @@ node('cico-workspace') { try { stage('prepare bare-metal machine') { - if (params.ghprbPullId != null) { - ref = "pull/${ghprbPullId}/head" - } sh 'scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ./prepare.sh root@${CICO_NODE}:' - sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} ./prepare.sh --workdir=/opt/build/go/src/github.com/ceph/ceph-csi --gitrepo=${ci_git_repo} --ref=${ref}" + // TODO: already checked out the PR on the node, scp the contents? + sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} ./prepare.sh --workdir=${workdir} --gitrepo=${git_repo} --ref=${ref}" } stage('test & build') { parallel test: { diff --git a/scripts/skip-doc-change.sh b/scripts/skip-doc-change.sh new file mode 100755 index 000000000..ef6477f1f --- /dev/null +++ b/scripts/skip-doc-change.sh @@ -0,0 +1,38 @@ +#!/bin/bash -e +# + +GIT_SINCE="${1}" +if [ -z "${GIT_SINCE}" ]; then + GIT_SINCE='origin/master' +fi + +CHANGED_FILES=$(git diff --name-only "${GIT_SINCE}") + +[[ -z $CHANGED_FILES ]] && exit 1 + +skip=0 +#files to be skipped +declare -a FILES=(^docs/ .md$ ^scripts/ LICENSE .mergify.yml .github .gitignore) + +function check_file_present() { + local file=$1 + for FILE in "${FILES[@]}"; do + if [[ $file =~ $FILE ]]; then + if [[ $file =~ (minikube.sh|travis-functest.sh) ]]; then + continue + fi + return 0 + fi + done + return 1 +} + +for CHANGED_FILE in $CHANGED_FILES; do + if ! check_file_present "$CHANGED_FILE"; then + skip=1 + fi +done +if [ $skip -eq 0 ]; then + echo "doc change only" + exit 1 +fi