ci / lib.shon commit tests: optionally skip bin-wrappers/ (dd167a3)
   1# Library of functions shared by all CI scripts
   2
   3skip_branch_tip_with_tag () {
   4        # Sometimes, a branch is pushed at the same time the tag that points
   5        # at the same commit as the tip of the branch is pushed, and building
   6        # both at the same time is a waste.
   7        #
   8        # When the build is triggered by a push to a tag, $CI_BRANCH will
   9        # have that tagname, e.g. v2.14.0.  Let's see if $CI_BRANCH is
  10        # exactly at a tag, and if so, if it is different from $CI_BRANCH.
  11        # That way, we can tell if we are building the tip of a branch that
  12        # is tagged and we can skip the build because we won't be skipping a
  13        # build of a tag.
  14
  15        if TAG=$(git describe --exact-match "$CI_BRANCH" 2>/dev/null) &&
  16                test "$TAG" != "$CI_BRANCH"
  17        then
  18                echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
  19                exit 0
  20        fi
  21}
  22
  23# Save some info about the current commit's tree, so we can skip the build
  24# job if we encounter the same tree again and can provide a useful info
  25# message.
  26save_good_tree () {
  27        echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
  28        # limit the file size
  29        tail -1000 "$good_trees_file" >"$good_trees_file".tmp
  30        mv "$good_trees_file".tmp "$good_trees_file"
  31}
  32
  33# Skip the build job if the same tree has already been built and tested
  34# successfully before (e.g. because the branch got rebased, changing only
  35# the commit messages).
  36skip_good_tree () {
  37        if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")"
  38        then
  39                # Haven't seen this tree yet, or no cached good trees file yet.
  40                # Continue the build job.
  41                return
  42        fi
  43
  44        echo "$good_tree_info" | {
  45                read tree prev_good_commit prev_good_job_number prev_good_job_id
  46
  47                if test "$CI_JOB_ID" = "$prev_good_job_id"
  48                then
  49                        cat <<-EOF
  50                        $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
  51                        This commit has already been built and tested successfully by this build job.
  52                        To force a re-build delete the branch's cache and then hit 'Restart job'.
  53                        EOF
  54                else
  55                        cat <<-EOF
  56                        $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
  57                        This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit.
  58                        The log of that build job is available at $(url_for_job_id $prev_good_job_id)
  59                        To force a re-build delete the branch's cache and then hit 'Restart job'.
  60                        EOF
  61                fi
  62        }
  63
  64        exit 0
  65}
  66
  67check_unignored_build_artifacts ()
  68{
  69        ! git ls-files --other --exclude-standard --error-unmatch \
  70                -- ':/*' 2>/dev/null ||
  71        {
  72                echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)"
  73                false
  74        }
  75}
  76
  77# Set 'exit on error' for all CI scripts to let the caller know that
  78# something went wrong.
  79# Set tracing executed commands, primarily setting environment variables
  80# and installing dependencies.
  81set -ex
  82
  83if test true = "$TRAVIS"
  84then
  85        CI_TYPE=travis
  86        # When building a PR, TRAVIS_BRANCH refers to the *target* branch. Not
  87        # what we want here. We want the source branch instead.
  88        CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
  89        CI_COMMIT="$TRAVIS_COMMIT"
  90        CI_JOB_ID="$TRAVIS_JOB_ID"
  91        CI_JOB_NUMBER="$TRAVIS_JOB_NUMBER"
  92        CI_OS_NAME="$TRAVIS_OS_NAME"
  93        CI_REPO_SLUG="$TRAVIS_REPO_SLUG"
  94
  95        cache_dir="$HOME/travis-cache"
  96
  97        url_for_job_id () {
  98                echo "https://travis-ci.org/$CI_REPO_SLUG/jobs/$1"
  99        }
 100
 101        BREW_INSTALL_PACKAGES="git-lfs gettext"
 102        export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
 103        export GIT_TEST_OPTS="--verbose-log -x --immediate"
 104        export MAKEFLAGS="--jobs=2"
 105elif test -n "$SYSTEM_COLLECTIONURI" || test -n "$SYSTEM_TASKDEFINITIONSURI"
 106then
 107        CI_TYPE=azure-pipelines
 108        # We are running in Azure Pipelines
 109        CI_BRANCH="$BUILD_SOURCEBRANCH"
 110        CI_COMMIT="$BUILD_SOURCEVERSION"
 111        CI_JOB_ID="$BUILD_BUILDID"
 112        CI_JOB_NUMBER="$BUILD_BUILDNUMBER"
 113        CI_OS_NAME="$(echo "$AGENT_OS" | tr A-Z a-z)"
 114        test darwin != "$CI_OS_NAME" || CI_OS_NAME=osx
 115        CI_REPO_SLUG="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
 116        CC="${CC:-gcc}"
 117
 118        # use a subdirectory of the cache dir (because the file share is shared
 119        # among *all* phases)
 120        cache_dir="$HOME/test-cache/$SYSTEM_PHASENAME"
 121
 122        url_for_job_id () {
 123                echo "$SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$1"
 124        }
 125
 126        BREW_INSTALL_PACKAGES=
 127        export GIT_PROVE_OPTS="--timer --jobs 10 --state=failed,slow,save"
 128        export GIT_TEST_OPTS="--verbose-log -x --write-junit-xml"
 129        export MAKEFLAGS="--jobs=10"
 130else
 131        echo "Could not identify CI type" >&2
 132        exit 1
 133fi
 134
 135good_trees_file="$cache_dir/good-trees"
 136
 137mkdir -p "$cache_dir"
 138
 139skip_branch_tip_with_tag
 140skip_good_tree
 141
 142if test -z "$jobname"
 143then
 144        jobname="$CI_OS_NAME-$CC"
 145fi
 146
 147export DEVELOPER=1
 148export DEFAULT_TEST_TARGET=prove
 149export GIT_TEST_CLONE_2GB=YesPlease
 150if [ "$jobname" = linux-gcc ]; then
 151        export CC=gcc-8
 152fi
 153
 154case "$jobname" in
 155linux-clang|linux-gcc)
 156        export GIT_TEST_HTTPD=YesPlease
 157
 158        # The Linux build installs the defined dependency versions below.
 159        # The OS X build installs the latest available versions. Keep that
 160        # in mind when you encounter a broken OS X build!
 161        export LINUX_P4_VERSION="16.2"
 162        export LINUX_GIT_LFS_VERSION="1.5.2"
 163
 164        P4_PATH="$HOME/custom/p4"
 165        GIT_LFS_PATH="$HOME/custom/git-lfs"
 166        export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH"
 167        ;;
 168osx-clang|osx-gcc)
 169        # t9810 occasionally fails on Travis CI OS X
 170        # t9816 occasionally fails with "TAP out of sequence errors" on
 171        # Travis CI OS X
 172        export GIT_SKIP_TESTS="t9810 t9816"
 173        ;;
 174GIT_TEST_GETTEXT_POISON)
 175        export GIT_TEST_GETTEXT_POISON=YesPlease
 176        ;;
 177esac