From ead7c278bde29d113bf8e1811fd5bca12ca20a9a Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 28 Jan 2015 13:48:42 -0800 Subject: [PATCH] Simplify travis file. Signed-off-by: Andrea Luzzardi --- .travis.yml | 64 ++++--------------------------------------- script/.validate | 33 ++++++++++++++++++++++ script/validate-dco | 56 +++++++++++++++++++++++++++++++++++++ script/validate-gofmt | 30 ++++++++++++++++++++ 4 files changed, 124 insertions(+), 59 deletions(-) create mode 100644 script/.validate create mode 100755 script/validate-dco create mode 100755 script/validate-gofmt diff --git a/.travis.yml b/.travis.yml index ce9295b11e..cefb500bb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,68 +5,14 @@ go: # - 1.4 # see https://github.com/moovweb/gvm/pull/116 for why Go 1.4 is currently disabled -# https://github.com/docker/libcontainer/blob/e9f44b52de03138d9273eadd5a87a0cea11b4f5d/.travis.yml - -# this section defines the majority of our "build matrix" -# see http://docs.travis-ci.com/user/build-configuration/#The-Build-Matrix -env: - - TRAVIS_GLOBAL_WTF=1 # since we don't want to re-run dco/gofmt checks for every single GOOS/GOARCH combination, we artificially create a separate build matrix cell here where those checks will be run (see the TRAVIS_GLOBAL_WTF checks in the script commands below) - - _GOOS=linux _GOARCH=amd64 - - _GOOS=linux _GOARCH=386 - - _GOOS=linux _GOARCH=arm - - _GOOS=darwin _GOARCH=amd64 - - _GOOS=darwin _GOARCH=386 - - _GOOS=windows _GOARCH=amd64 - - _GOOS=windows _GOARCH=386 - # let us have speedy Docker-based Travis workers sudo: false -before_install: - - go get github.com/tools/godep - install: - # setup our current repo as "github.com/docker/swarm" in the GOPATH - - mkdir -pv "${GOPATH%%:*}/src/github.com/docker" - && [ -d "${GOPATH%%:*}/src/github.com/docker/swarm" ] - || ln -sv "$(pwd -P)" "${GOPATH%%:*}/src/github.com/docker/swarm" - # grab the files from docker/docker that do DCO/gofmt checking (and make the minor adjustments necessary to make them do docker/swarm) - - if [ "$TRAVIS_GLOBAL_WTF" ]; then - export DOCKER_PATH="${GOPATH%%:*}/src/github.com/docker/docker"; - mkdir -pv "$DOCKER_PATH/project/make"; - ( cd "$DOCKER_PATH/project/make" && wget -c 'https://raw.githubusercontent.com/docker/docker/master/project/make/'{.validate,validate-dco,validate-gofmt} ); - sed -i 's!docker/docker!docker/swarm!' "$DOCKER_PATH/project/make/.validate"; - sed -i 's!\^vendor/!\^Godeps/!' "$DOCKER_PATH/project/make/validate-gofmt"; - fi - # cross-compile the Go toolchain for the GOOS/GOARCH combo we're testing - - if [ -z "$TRAVIS_GLOBAL_WTF" ]; then - gvm cross "$_GOOS" "$_GOARCH"; - export GOOS="$_GOOS" GOARCH="$_GOARCH"; - fi - # restore vendored dependencies - - if [ -z "$TRAVIS_GLOBAL_WTF" ]; then - godep restore; - fi - # add some debugging output that's super helpful when adapting the Travis scripts (so that which environment variables are available in the exact situation being debugged can be seen easily, with real-life examples) - - env | sort - - go env + - export GOPATH=${TRAVIS_BUILD_DIR}/Godeps/_workspace:$GOPATH + - export PATH=${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$PATH script: - - if [ "$TRAVIS_GLOBAL_WTF" ]; then - bash "$DOCKER_PATH/project/make/validate-dco"; - fi - # check gofmt, but only on Go 1.3 - - if [[ "$TRAVIS_GLOBAL_WTF" && "$TRAVIS_GO_VERSION" == go1.3* ]]; then - bash "$DOCKER_PATH/project/make/validate-gofmt"; - fi - # when we're on the native GOHOSTOS/GOHOSTARCH, the test suite will run as-is, but for all other platforms, we only want to test compilation - - if [ -z "$TRAVIS_GLOBAL_WTF" ]; then - case "$(go env GOOS)/$(go env GOARCH)" in - $(go env GOHOSTOS)/$(go env GOHOSTARCH)) - go test -v ./...; - ;; - *) - go build -v; - ;; - esac - fi + - script/validate-dco + - script/validate-gofmt + - go test -v -race ./... diff --git a/script/.validate b/script/.validate new file mode 100644 index 0000000000..318f9ebfff --- /dev/null +++ b/script/.validate @@ -0,0 +1,33 @@ +#!/bin/bash + +if [ -z "$VALIDATE_UPSTREAM" ]; then + # this is kind of an expensive check, so let's not do this twice if we + # are running more than one validate bundlescript + + VALIDATE_REPO='https://github.com/docker/swarm.git' + VALIDATE_BRANCH='master' + + if [ "$TRAVIS" = 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then + VALIDATE_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git" + VALIDATE_BRANCH="${TRAVIS_BRANCH}" + fi + + VALIDATE_HEAD="$(git rev-parse --verify HEAD)" + + git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" + VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" + + VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD" + VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD" + + validate_diff() { + if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then + git diff "$VALIDATE_COMMIT_DIFF" "$@" + fi + } + validate_log() { + if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then + git log "$VALIDATE_COMMIT_LOG" "$@" + fi + } +fi diff --git a/script/validate-dco b/script/validate-dco new file mode 100755 index 0000000000..1c75d91bfa --- /dev/null +++ b/script/validate-dco @@ -0,0 +1,56 @@ +#!/bin/bash + +source "$(dirname "$BASH_SOURCE")/.validate" + +adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }') +dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }') +notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')" + +: ${adds:=0} +: ${dels:=0} + +# "Username may only contain alphanumeric characters or dashes and cannot begin with a dash" +githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+' + +# https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work +dcoPrefix='Signed-off-by:' +dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$" + +check_dco() { + grep -qE "$dcoRegex" +} + +if [ $adds -eq 0 -a $dels -eq 0 ]; then + echo '0 adds, 0 deletions; nothing to validate! :)' +elif [ -z "$notDocs" -a $adds -le 1 -a $dels -le 1 ]; then + echo 'Congratulations! DCO small-patch-exception material!' +else + commits=( $(validate_log --format='format:%H%n') ) + badCommits=() + for commit in "${commits[@]}"; do + if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then + # no content (ie, Merge commit, etc) + continue + fi + if ! git log -1 --format='format:%B' "$commit" | check_dco; then + badCommits+=( "$commit" ) + fi + done + if [ ${#badCommits[@]} -eq 0 ]; then + echo "Congratulations! All commits are properly signed with the DCO!" + else + { + echo "These commits do not have a proper '$dcoPrefix' marker:" + for commit in "${badCommits[@]}"; do + echo " - $commit" + done + echo + echo 'Please amend each commit to include a properly formatted DCO marker.' + echo + echo 'Visit the following URL for information about the Docker DCO:' + echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work' + echo + } >&2 + false + fi +fi diff --git a/script/validate-gofmt b/script/validate-gofmt new file mode 100755 index 0000000000..c565976b41 --- /dev/null +++ b/script/validate-gofmt @@ -0,0 +1,30 @@ +#!/bin/bash + +source "$(dirname "$BASH_SOURCE")/.validate" + +IFS=$'\n' +files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^Godeps/' || true) ) +unset IFS + +badFiles=() +for f in "${files[@]}"; do + # we use "git show" here to validate that what's committed is formatted + if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then + badFiles+=( "$f" ) + fi +done + +if [ ${#badFiles[@]} -eq 0 ]; then + echo 'Congratulations! All Go source files are properly formatted.' +else + { + echo "These files are not properly gofmt'd:" + for f in "${badFiles[@]}"; do + echo " - $f" + done + echo + echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' + echo + } >&2 + false +fi