diff options
Diffstat (limited to 'ci')
-rwxr-xr-x | ci/install-dependencies.sh | 42 | ||||
-rwxr-xr-x | ci/lib-travisci.sh | 126 | ||||
-rwxr-xr-x | ci/print-test-failures.sh | 27 | ||||
-rwxr-xr-x | ci/run-build.sh | 8 | ||||
-rwxr-xr-x | ci/run-linux32-build.sh | 60 | ||||
-rwxr-xr-x | ci/run-linux32-docker.sh | 31 | ||||
-rwxr-xr-x | ci/run-static-analysis.sh | 10 | ||||
-rwxr-xr-x | ci/run-tests.sh | 18 | ||||
-rwxr-xr-x | ci/run-windows-build.sh | 103 | ||||
-rwxr-xr-x | ci/test-documentation.sh | 27 |
10 files changed, 449 insertions, 3 deletions
diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh new file mode 100755 index 0000000000..75a9fd2475 --- /dev/null +++ b/ci/install-dependencies.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Install dependencies required to build and test Git on Linux and macOS +# + +. ${0%/*}/lib-travisci.sh + +P4WHENCE=http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION +LFSWHENCE=https://github.com/github/git-lfs/releases/download/v$LINUX_GIT_LFS_VERSION + +case "$jobname" in +linux-clang|linux-gcc) + mkdir --parents "$P4_PATH" + pushd "$P4_PATH" + wget --quiet "$P4WHENCE/bin.linux26x86_64/p4d" + wget --quiet "$P4WHENCE/bin.linux26x86_64/p4" + chmod u+x p4d + chmod u+x p4 + popd + mkdir --parents "$GIT_LFS_PATH" + pushd "$GIT_LFS_PATH" + wget --quiet "$LFSWHENCE/git-lfs-linux-amd64-$LINUX_GIT_LFS_VERSION.tar.gz" + tar --extract --gunzip --file "git-lfs-linux-amd64-$LINUX_GIT_LFS_VERSION.tar.gz" + cp git-lfs-$LINUX_GIT_LFS_VERSION/git-lfs . + popd + ;; +osx-clang|osx-gcc) + brew update --quiet + # Uncomment this if you want to run perf tests: + # brew install gnu-time + brew install git-lfs gettext + brew link --force gettext + brew install caskroom/cask/perforce + ;; +esac + +echo "$(tput setaf 6)Perforce Server Version$(tput sgr0)" +p4d -V | grep Rev. +echo "$(tput setaf 6)Perforce Client Version$(tput sgr0)" +p4 -V | grep Rev. +echo "$(tput setaf 6)Git-LFS Version$(tput sgr0)" +git-lfs version diff --git a/ci/lib-travisci.sh b/ci/lib-travisci.sh new file mode 100755 index 0000000000..1efee55ef7 --- /dev/null +++ b/ci/lib-travisci.sh @@ -0,0 +1,126 @@ +# Library of functions shared by all CI scripts + +skip_branch_tip_with_tag () { + # Sometimes, a branch is pushed at the same time the tag that points + # at the same commit as the tip of the branch is pushed, and building + # both at the same time is a waste. + # + # Travis gives a tagname e.g. v2.14.0 in $TRAVIS_BRANCH when + # the build is triggered by a push to a tag. Let's see if + # $TRAVIS_BRANCH is exactly at a tag, and if so, if it is + # different from $TRAVIS_BRANCH. That way, we can tell if + # we are building the tip of a branch that is tagged and + # we can skip the build because we won't be skipping a build + # of a tag. + + if TAG=$(git describe --exact-match "$TRAVIS_BRANCH" 2>/dev/null) && + test "$TAG" != "$TRAVIS_BRANCH" + then + echo "$(tput setaf 2)Tip of $TRAVIS_BRANCH is exactly at $TAG$(tput sgr0)" + exit 0 + fi +} + +# Save some info about the current commit's tree, so we can skip the build +# job if we encounter the same tree again and can provide a useful info +# message. +save_good_tree () { + echo "$(git rev-parse $TRAVIS_COMMIT^{tree}) $TRAVIS_COMMIT $TRAVIS_JOB_NUMBER $TRAVIS_JOB_ID" >>"$good_trees_file" + # limit the file size + tail -1000 "$good_trees_file" >"$good_trees_file".tmp + mv "$good_trees_file".tmp "$good_trees_file" +} + +# Skip the build job if the same tree has already been built and tested +# successfully before (e.g. because the branch got rebased, changing only +# the commit messages). +skip_good_tree () { + if ! good_tree_info="$(grep "^$(git rev-parse $TRAVIS_COMMIT^{tree}) " "$good_trees_file")" + then + # Haven't seen this tree yet, or no cached good trees file yet. + # Continue the build job. + return + fi + + echo "$good_tree_info" | { + read tree prev_good_commit prev_good_job_number prev_good_job_id + + if test "$TRAVIS_JOB_ID" = "$prev_good_job_id" + then + cat <<-EOF + $(tput setaf 2)Skipping build job for commit $TRAVIS_COMMIT.$(tput sgr0) + This commit has already been built and tested successfully by this build job. + To force a re-build delete the branch's cache and then hit 'Restart job'. + EOF + else + cat <<-EOF + $(tput setaf 2)Skipping build job for commit $TRAVIS_COMMIT.$(tput sgr0) + This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit. + The log of that build job is available at https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$prev_good_job_id + To force a re-build delete the branch's cache and then hit 'Restart job'. + EOF + fi + } + + exit 0 +} + +check_unignored_build_artifacts () +{ + ! git ls-files --other --exclude-standard --error-unmatch \ + -- ':/*' 2>/dev/null || + { + echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)" + false + } +} + +# Set 'exit on error' for all CI scripts to let the caller know that +# something went wrong. +# Set tracing executed commands, primarily setting environment variables +# and installing dependencies. +set -ex + +cache_dir="$HOME/travis-cache" +good_trees_file="$cache_dir/good-trees" + +mkdir -p "$cache_dir" + +skip_branch_tip_with_tag +skip_good_tree + +if test -z "$jobname" +then + jobname="$TRAVIS_OS_NAME-$CC" +fi + +export DEVELOPER=1 +export DEFAULT_TEST_TARGET=prove +export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save" +export GIT_TEST_OPTS="--verbose-log" +export GIT_TEST_CLONE_2GB=YesPlease + +case "$jobname" in +linux-clang|linux-gcc) + export GIT_TEST_HTTPD=YesPlease + + # The Linux build installs the defined dependency versions below. + # The OS X build installs the latest available versions. Keep that + # in mind when you encounter a broken OS X build! + export LINUX_P4_VERSION="16.2" + export LINUX_GIT_LFS_VERSION="1.5.2" + + P4_PATH="$HOME/custom/p4" + GIT_LFS_PATH="$HOME/custom/git-lfs" + export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH" + ;; +osx-clang|osx-gcc) + # t9810 occasionally fails on Travis CI OS X + # t9816 occasionally fails with "TAP out of sequence errors" on + # Travis CI OS X + export GIT_SKIP_TESTS="t9810 t9816" + ;; +GETTEXT_POISON) + export GETTEXT_POISON=YesPlease + ;; +esac diff --git a/ci/print-test-failures.sh b/ci/print-test-failures.sh new file mode 100755 index 0000000000..4f261ddc01 --- /dev/null +++ b/ci/print-test-failures.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Print output of failing tests +# + +. ${0%/*}/lib-travisci.sh + +# Tracing executed commands would produce too much noise in the loop below. +set +x + +if ! ls t/test-results/*.exit >/dev/null 2>/dev/null +then + echo "Build job failed before the tests could have been run" + exit +fi + +for TEST_EXIT in t/test-results/*.exit +do + if [ "$(cat "$TEST_EXIT")" != "0" ] + then + TEST_OUT="${TEST_EXIT%exit}out" + echo "------------------------------------------------------------------------" + echo "$(tput setaf 1)${TEST_OUT}...$(tput sgr0)" + echo "------------------------------------------------------------------------" + cat "${TEST_OUT}" + fi +done diff --git a/ci/run-build.sh b/ci/run-build.sh new file mode 100755 index 0000000000..4f940d1032 --- /dev/null +++ b/ci/run-build.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# Build Git +# + +. ${0%/*}/lib-travisci.sh + +make --jobs=2 diff --git a/ci/run-linux32-build.sh b/ci/run-linux32-build.sh new file mode 100755 index 0000000000..2c60d2e70a --- /dev/null +++ b/ci/run-linux32-build.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# +# Build and test Git in a 32-bit environment +# +# Usage: +# run-linux32-build.sh <host-user-id> +# + +set -ex + +if test $# -ne 1 || test -z "$1" +then + echo >&2 "usage: run-linux32-build.sh <host-user-id>" + exit 1 +fi + +# Update packages to the latest available versions +linux32 --32bit i386 sh -c ' + apt update >/dev/null && + apt install -y build-essential libcurl4-openssl-dev libssl-dev \ + libexpat-dev gettext python >/dev/null +' + +# If this script runs inside a docker container, then all commands are +# usually executed as root. Consequently, the host user might not be +# able to access the test output files. +# If a non 0 host user id is given, then create a user "ci" with that +# user id to make everything accessible to the host user. +HOST_UID=$1 +if test $HOST_UID -eq 0 +then + # Just in case someone does want to run the test suite as root. + CI_USER=root +else + CI_USER=ci + if test "$(id -u $CI_USER 2>/dev/null)" = $HOST_UID + then + echo "user '$CI_USER' already exists with the requested ID $HOST_UID" + else + useradd -u $HOST_UID $CI_USER + fi + + # Due to a bug the test suite was run as root in the past, so + # a prove state file created back then is only accessible by + # root. Now that bug is fixed, the test suite is run as a + # regular user, but the prove state file coming from Travis + # CI's cache might still be owned by root. + # Make sure that this user has rights to any cached files, + # including an existing prove state file. + test -n "$cache_dir" && chown -R $HOST_UID:$HOST_UID "$cache_dir" +fi + +# Build and test +linux32 --32bit i386 su -m -l $CI_USER -c ' + set -ex + cd /usr/src/git + test -n "$cache_dir" && ln -s "$cache_dir/.prove" t/.prove + make --jobs=2 + make --quiet test +' diff --git a/ci/run-linux32-docker.sh b/ci/run-linux32-docker.sh new file mode 100755 index 0000000000..21637903ce --- /dev/null +++ b/ci/run-linux32-docker.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Download and run Docker image to build and test 32-bit Git +# + +. ${0%/*}/lib-travisci.sh + +docker pull daald/ubuntu32:xenial + +# Use the following command to debug the docker build locally: +# $ docker run -itv "${PWD}:/usr/src/git" --entrypoint /bin/bash daald/ubuntu32:xenial +# root@container:/# /usr/src/git/ci/run-linux32-build.sh <host-user-id> + +container_cache_dir=/tmp/travis-cache + +docker run \ + --interactive \ + --env DEVELOPER \ + --env DEFAULT_TEST_TARGET \ + --env GIT_PROVE_OPTS \ + --env GIT_TEST_OPTS \ + --env GIT_TEST_CLONE_2GB \ + --env cache_dir="$container_cache_dir" \ + --volume "${PWD}:/usr/src/git" \ + --volume "$cache_dir:$container_cache_dir" \ + daald/ubuntu32:xenial \ + /usr/src/git/ci/run-linux32-build.sh $(id -u $USER) + +check_unignored_build_artifacts + +save_good_tree diff --git a/ci/run-static-analysis.sh b/ci/run-static-analysis.sh new file mode 100755 index 0000000000..fe4ee4e06b --- /dev/null +++ b/ci/run-static-analysis.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# +# Perform various static code analysis checks +# + +. ${0%/*}/lib-travisci.sh + +make coccicheck + +save_good_tree diff --git a/ci/run-tests.sh b/ci/run-tests.sh new file mode 100755 index 0000000000..73e273fac7 --- /dev/null +++ b/ci/run-tests.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Test Git +# + +. ${0%/*}/lib-travisci.sh + +ln -s "$cache_dir/.prove" t/.prove + +make --quiet test +if test "$jobname" = "linux-gcc" +then + GIT_TEST_SPLIT_INDEX=YesPlease make --quiet test +fi + +check_unignored_build_artifacts + +save_good_tree diff --git a/ci/run-windows-build.sh b/ci/run-windows-build.sh new file mode 100755 index 0000000000..d99a180e52 --- /dev/null +++ b/ci/run-windows-build.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# +# Script to trigger the Git for Windows build and test run. +# Set the $GFW_CI_TOKEN as environment variable. +# Pass the branch (only branches on https://github.com/git/git are +# supported) and a commit hash. +# + +. ${0%/*}/lib-travisci.sh + +test $# -ne 2 && echo "Unexpected number of parameters" && exit 1 +test -z "$GFW_CI_TOKEN" && echo "GFW_CI_TOKEN not defined" && exit + +BRANCH=$1 +COMMIT=$2 + +gfwci () { + local CURL_ERROR_CODE HTTP_CODE + CONTENT_FILE=$(mktemp -t "git-windows-ci-XXXXXX") + while test -z $HTTP_CODE + do + HTTP_CODE=$(curl \ + -H "Authentication: Bearer $GFW_CI_TOKEN" \ + --silent --retry 5 --write-out '%{HTTP_CODE}' \ + --output >(sed "$(printf '1s/^\xef\xbb\xbf//')" >$CONTENT_FILE) \ + "https://git-for-windows-ci.azurewebsites.net/api/TestNow?$1" \ + ) + CURL_ERROR_CODE=$? + # The GfW CI web app sometimes returns HTTP errors of + # "502 bad gateway" or "503 service unavailable". + # We also need to check the HTTP content because the GfW web + # app seems to pass through (error) results from other Azure + # calls with HTTP code 200. + # Wait a little and retry if we detect this error. More info: + # https://docs.microsoft.com/en-in/azure/app-service-web/app-service-web-troubleshoot-http-502-http-503 + if test $HTTP_CODE -eq 502 || + test $HTTP_CODE -eq 503 || + grep "502 - Web server received an invalid response" $CONTENT_FILE >/dev/null + then + sleep 10 + HTTP_CODE= + fi + done + cat $CONTENT_FILE + rm $CONTENT_FILE + if test $CURL_ERROR_CODE -ne 0 + then + return $CURL_ERROR_CODE + fi + if test "$HTTP_CODE" -ge 400 && test "$HTTP_CODE" -lt 600 + then + return 127 + fi +} + +# Trigger build job +BUILD_ID=$(gfwci "action=trigger&branch=$BRANCH&commit=$COMMIT&skipTests=false") +if test $? -ne 0 +then + echo "Unable to trigger Visual Studio Team Services Build" + echo "$BUILD_ID" + exit 1 +fi + +# Check if the $BUILD_ID contains a number +case $BUILD_ID in +''|*[!0-9]*) echo "Unexpected build number: $BUILD_ID" && exit 1 +esac + +echo "Visual Studio Team Services Build #${BUILD_ID}" + +# Tracing execued commands would produce too much noise in the waiting +# loop below. +set +x + +# Wait until build job finished +STATUS= +RESULT= +while true +do + LAST_STATUS=$STATUS + STATUS=$(gfwci "action=status&buildId=$BUILD_ID") + test "$STATUS" = "$LAST_STATUS" || printf "\nStatus: %s " "$STATUS" + printf "." + + case "$STATUS" in + inProgress|postponed|notStarted) sleep 10 ;; # continue + "completed: succeeded") RESULT="success"; break;; # success + "completed: failed") break;; # failure + *) echo "Unhandled status: $STATUS"; break;; # unknown + esac +done + +# Print log +echo "" +echo "" +set -x +gfwci "action=log&buildId=$BUILD_ID" | cut -c 30- + +# Set exit code for TravisCI +test "$RESULT" = "success" + +save_good_tree diff --git a/ci/test-documentation.sh b/ci/test-documentation.sh index 579d540d32..a20de9ca12 100755 --- a/ci/test-documentation.sh +++ b/ci/test-documentation.sh @@ -1,14 +1,35 @@ -#!/bin/sh +#!/usr/bin/env bash # # Perform sanity checks on documentation and build it. # -set -e +. ${0%/*}/lib-travisci.sh + +gem install asciidoctor make check-builtins make check-docs -make doc +# Build docs with AsciiDoc +make --jobs=2 doc > >(tee stdout.log) 2> >(tee stderr.log >&2) +! test -s stderr.log test -s Documentation/git.html test -s Documentation/git.xml test -s Documentation/git.1 +grep '<meta name="generator" content="AsciiDoc ' Documentation/git.html + +rm -f stdout.log stderr.log +check_unignored_build_artifacts + +# Build docs with AsciiDoctor +make clean +make --jobs=2 USE_ASCIIDOCTOR=1 doc > >(tee stdout.log) 2> >(tee stderr.log >&2) +sed '/^GIT_VERSION = / d' stderr.log +! test -s stderr.log +test -s Documentation/git.html +grep '<meta name="generator" content="Asciidoctor ' Documentation/git.html + +rm -f stdout.log stderr.log +check_unignored_build_artifacts + +save_good_tree |