travis-ci: dedicated scripts + skip duplicated builds
cover travis-ci: dedicated scripts + skip duplicated builds
From: Lars Schneider <[email protected]>
Hi,
the patches were previously discussed here:
https://public-inbox.org/git/[email protected]/#t
Over there Junio posted the original patch to skip a build on Travis CI. The patch became 2/2 in this series.
Cheers,
Lars
Base Ref: master
Web-Diff: https://github.com/larsxschneider/git/commit/65ab003ec9
Checkout: git fetch https://github.com/larsxschneider/git travisci/move-into-ci-v1 && git checkout 65ab003ec9
Lars Schneider (2):
travis-ci: move Travis CI code into dedicated scripts
travis-ci: skip a branch build if equal tag is present
.travis.yml | 88 +++++----------------------------------------- ci/install-dependencies.sh | 43 ++++++++++++++++++++++ ci/lib-travisci.sh | 28 +++++++++++++++ ci/print-test-failures.sh | 18 ++++++++++ ci/run-build.sh | 8 +++++ ci/run-linux32-docker.sh | 23 ++++++++++++ ci/run-static-analysis.sh | 8 +++++ ci/run-tests.sh | 10 ++++++ ci/run-windows-build.sh | 2 ++ ci/test-documentation.sh | 4 ++- 10 files changed, 151 insertions(+), 81 deletions(-) create mode 100755 ci/install-dependencies.sh create mode 100755 ci/lib-travisci.sh create mode 100755 ci/print-test-failures.sh create mode 100755 ci/run-build.sh create mode 100755 ci/run-linux32-docker.sh create mode 100755 ci/run-static-analysis.sh create mode 100755 ci/run-tests.sh
base-commit: 3ec7d702a89c647ddf42a59bc3539361367de9d5 --
2.14.1
PATCH 1/2 travis-ci: move Travis CI code into dedicated scripts
From: Lars Schneider <[email protected]>
Most of the Travis CI commands are in the '.travis.yml'. The yml format does not support functions and therefore code duplication is necessary to run commands across all builds.
To fix this, add a library for common CI functions. Move all Travis CI code into dedicated scripts and make them call the library first.
--- .travis.yml | 88 +++++----------------------------------------- ci/install-dependencies.sh | 43 ++++++++++++++++++++++ ci/lib-travisci.sh | 5 +++ ci/print-test-failures.sh | 18 ++++++++++ ci/run-build.sh | 8 +++++ ci/run-linux32-docker.sh | 23 ++++++++++++ ci/run-static-analysis.sh | 8 +++++ ci/run-tests.sh | 10 ++++++ ci/run-windows-build.sh | 2 ++ ci/test-documentation.sh | 4 ++- 10 files changed, 128 insertions(+), 81 deletions(-) create mode 100755 ci/install-dependencies.sh create mode 100755 ci/lib-travisci.sh create mode 100755 ci/print-test-failures.sh create mode 100755 ci/run-build.sh create mode 100755 ci/run-linux32-docker.sh create mode 100755 ci/run-static-analysis.sh create mode 100755 ci/run-tests.sh
.travis.yml +8 -80
@@ -61,23 +61,8 @@ matrix: services: - docker before_install: - - docker pull daald/ubuntu32:xenial before_script: - script: - - > - docker run - --interactive - --env DEVELOPER - --env DEFAULT_TEST_TARGET - --env GIT_PROVE_OPTS - --env GIT_TEST_OPTS - --env GIT_TEST_CLONE_2GB - --volume "${PWD}:/usr/src/git" - daald/ubuntu32:xenial - /usr/src/git/ci/run-linux32-build.sh $(id -u $USER) - # 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 + script: ci/run-linux32-docker.sh - env: Static Analysis os: linux compiler:
@@ -86,9 +71,8 @@ matrix: packages: - coccinelle before_install: - script: - # "before_script" that builds Git is inherited from base job - - make coccicheck + # "before_script" that builds Git is inherited from base job + script: ci/run-static-analysis.sh after_failure: - env: Documentation os: linux
@@ -99,70 +83,14 @@ matrix: - asciidoc - xmlto before_install: - before_script: gem install asciidoctor + before_script: script: ci/test-documentation.sh after_failure: -before_install: - - > - case "${TRAVIS_OS_NAME:-linux}" in - linux) - export GIT_TEST_HTTPD=YesPlease - - mkdir --parents custom/p4 - pushd custom/p4 - wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4d - wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4 - chmod u+x p4d - chmod u+x p4 - export PATH="$(pwd):$PATH" - popd - mkdir --parents custom/git-lfs - pushd custom/git-lfs - wget --quiet https://github.com/github/git-lfs/releases/download/v$LINUX_GIT_LFS_VERSION/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 . - export PATH="$(pwd):$PATH" - popd - ;; - osx) - 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; - -before_script: make --jobs=2 - -script: - - > - mkdir -p $HOME/travis-cache; - ln -s $HOME/travis-cache/.prove t/.prove; - make --quiet test; - -after_failure: - - > - : '<-- Click here to see detailed test output! '; - 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; +before_install: ci/install-dependencies.sh +before_script: ci/run-build.sh +script: ci/run-tests.sh +after_failure: ci/print-test-failures.sh notifications: email: false
ci/install-dependencies.sh new file +43 -0
43 lines not on this page · raw message
ci/lib-travisci.sh new file +5 -0
@@ -0,0 +1,5 @@ +# Library of functions shared by all CI scripts + +# Set 'exit on error' for all CI scripts to let the caller know that +# something went wrong +set -e
ci/print-test-failures.sh new file +18 -0
@@ -0,0 +1,18 @@ +#!/bin/sh +# +# Print output of failing tests +# + +. ${0%/*}/lib-travisci.sh + +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
ci/run-build.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh +# +# Build Git +# + +. ${0%/*}/lib-travisci.sh + +make --jobs=2
ci/run-linux32-docker.sh new file +23 -0
@@ -0,0 +1,23 @@ +#!/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 + +docker run \ + --interactive \ + --env DEVELOPER \ + --env DEFAULT_TEST_TARGET \ + --env GIT_PROVE_OPTS \ + --env GIT_TEST_OPTS \ + --env GIT_TEST_CLONE_2GB \ + --volume "${PWD}:/usr/src/git" \ + daald/ubuntu32:xenial \ + /usr/src/git/ci/run-linux32-build.sh $(id -u $USER)
ci/run-static-analysis.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh +# +# Perform various static code analysis checks +# + +. ${0%/*}/lib-travisci.sh + +make coccicheck
ci/run-tests.sh new file +10 -0
@@ -0,0 +1,10 @@ +#!/bin/sh +# +# Test Git +# + +. ${0%/*}/lib-travisci.sh + +mkdir -p $HOME/travis-cache +ln -s $HOME/travis-cache/.prove t/.prove +make --quiet test
ci/run-windows-build.sh +2 -0
@@ -6,6 +6,8 @@ # 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
ci/test-documentation.sh +3 -1
@@ -3,7 +3,9 @@ # Perform sanity checks on documentation and build it. # -set -e +. ${0%/*}/lib-travisci.sh + +gem install asciidoctor make check-builtins make check-docs
Signature · 1 line
2.14.1
PATCH 2/2 travis-ci: skip a branch build if equal tag is present
In reply to [email protected]From: Lars Schneider <[email protected]>
If we push a branch and a tag pointing to the HEAD of this branch, then Travis CI would run the build twice. This wastes resources and slows the testing.
Add a function to detect this situation and skip the build the branch if appropriate. Invoke this function on every build.
--- ci/lib-travisci.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
ci/lib-travisci.sh +23 -0
@@ -1,5 +1,28 @@ # 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) && + $TAG != $TRAVIS_BRANCH + then + echo "Tip of $TRAVIS_BRANCH is exactly at $TAG" + exit 0 + fi +} + # Set 'exit on error' for all CI scripts to let the caller know that # something went wrong set -e + +skip_branch_tip_with_tag
Signature · 1 line
2.14.1
Re: [PATCH v1 1/2] travis-ci: move Travis CI code into dedicated scripts
In reply to [email protected]Quoted 11 lines · [email protected] writes:
From: Lars Schneider <[email protected]>
Most of the Travis CI commands are in the '.travis.yml'. The yml format does not support functions and therefore code duplication is necessary to run commands across all builds.
To fix this, add a library for common CI functions. Move all Travis CI code into dedicated scripts and make them call the library first.
Signed-off-by Lars Schneider <[email protected]>---
Thanks. I _think_ you ended up not having to use shell function to avoid code duplication ;-) but I find the script part of the result much easier to understand.
Two things I noticed:
- run-windows-build.sh did not use to run with "set -e" but now it does because it includes lib-travisci.sh; if (I didn't check with fine toothed comb) the original were not "set -e" clean, we may see unwanted errors in run-windows-build.sh, but that is sometihng we can fix going forward.
- it seems that the test output section lost ": <- click here..."; I do not know if there is a negative consequence of this change.
Indentation of some scripts were a bit too deep and I found it hard to read them, so the following is what I did (but did not commit) while reading them through.
Thanks.
ci/install-dependencies.sh | 51 ++++++++++++++++++++++++---------------------- ci/print-test-failures.sh | 18 ++++++++-------- 2 files changed, 36 insertions(+), 33 deletions(-)
ci/install-dependencies.sh +27 -24
@@ -5,33 +5,36 @@ . ${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 "${TRAVIS_OS_NAME:-linux}" in - linux) - export GIT_TEST_HTTPD=YesPlease +linux) + export GIT_TEST_HTTPD=YesPlease - mkdir --parents custom/p4 - pushd custom/p4 - wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4d - wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4 - chmod u+x p4d - chmod u+x p4 - export PATH="$(pwd):$PATH" - popd - mkdir --parents custom/git-lfs - pushd custom/git-lfs - wget --quiet https://github.com/github/git-lfs/releases/download/v$LINUX_GIT_LFS_VERSION/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 . - export PATH="$(pwd):$PATH" - popd + mkdir --parents custom/p4 + pushd custom/p4 + wget --quiet "$P4WHENCE/bin.linux26x86_64/p4d" + wget --quiet "$P4WHENCE/bin.linux26x86_64/p4" + chmod u+x p4d + chmod u+x p4 + export PATH="$(pwd):$PATH" + popd + mkdir --parents custom/git-lfs + pushd custom/git-lfs + 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 . + export PATH="$(pwd):$PATH" + popd ;; - osx) - 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 +osx) + 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
ci/print-test-failures.sh +9 -9
@@ -6,13 +6,13 @@ . ${0%/*}/lib-travisci.sh 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 +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
Re: [PATCH v1 2/2] travis-ci: skip a branch build if equal tag is present
In reply to [email protected]Quoted 1 line
If we push a branch and a tag pointing to the HEAD of this branch,
s/the HEAD of//, perhaps?
There is no such thing as "HEAD" (all capital!) of a branch, is it?
Quoted 1 line
then Travis CI would run the build twice. This wastes resources and
Nit: s/run the build/build and test the same tree/, to further stress that the two builds are redundant.
Quoted 3 lines
slows the testing.
Add a function to detect this situation and skip the build the branch
s/skip the build/skip building/ ?
Quoted 20 lines
if appropriate. Invoke this function on every build.
Helped-by Junio C Hamano <[email protected]>Signed-off-by Lars Schneider <[email protected]>--- ci/lib-travisci.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)ci/lib-travisci.sh +5
-0@@ -1,5 +1,28 @@ # 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. + #
ci/lib-travisci.sh line 17
Quoted 10 lines
ci/lib-travisci.sh +10
-0+ # 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) && + $TAG != $TRAVIS_BRANCH
This must be
[ $TAG != $TRAVIS_BRANCH ]
otherwise the shell will rightfully complain:
$ TRAVIS_BRANCH=v2.14.0 ./ci/lib-travisci.sh ./ci/lib-travisci.sh: line 17: v2.14.0: command not found
Furthermore, I would prefer quotes around $TAG and $TRAVIS_BRANCH. If either one of those two variables were empty (or contain multiple words) at that point, the shell would complain. Now, I don't think that either can end up being empty, so quotes are not necessary, but having quotes around them would save future readers from spending brain cycles on this unnecessarily.
Quoted 15 lines
ci/lib-travisci.sh +8
-0+ then + echo "Tip of $TRAVIS_BRANCH is exactly at $TAG" + exit 0 + fi +} + # Set 'exit on error' for all CI scripts to let the caller know that # something went wrong set -e + +skip_branch_tip_with_tagSignature · 1 line
2.14.1
Re: [PATCH v1 2/2] travis-ci: skip a branch build if equal tag is present
Quoted 7 lines · SZEDER Gábor
Quoted 2 lines
If we push a branch and a tag pointing to the HEAD of this branch,
s/the HEAD of//, perhaps?
There is no such thing as "HEAD" (all capital!) of a branch, is it?
Agreed, maybe:
"If we push a branch and a tag pointing to the tip of this branch..."
Would that be OK for you?
Quoted 4 lines
Quoted 1 line
then Travis CI would run the build twice. This wastes resources and
Nit: s/run the build/build and test the same tree/, to further stress that the two builds are redundant.
OK, will fix.
Quoted 5 lines
Quoted 3 lines
slows the testing.
Add a function to detect this situation and skip the build the branch
s/skip the build/skip building/ ?
OK, will fix.
Quoted 40 lines
Quoted 20 lines
if appropriate. Invoke this function on every build.
Helped-by Junio C Hamano <[email protected]>Signed-off-by Lars Schneider <[email protected]>---
ci/lib-travisci.sh| 23 +++++++++++++++++++++++1 file changed, 23 insertions(+)ci/lib-travisci.sh +5
-0@@ -1,5 +1,28 @@ # 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. + #ci/lib-travisci.sh line 17
Quoted 10 lines
ci/lib-travisci.sh +10
-0+ # 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) && + $TAG != $TRAVIS_BRANCHThis must be
[ $TAG != $TRAVIS_BRANCH ]otherwise the shell will rightfully complain:
$ TRAVIS_BRANCH=v2.14.0 ./ci/lib-travisci.sh ./ci/lib-travisci.sh: line 17: v2.14.0: command not found
Quoted 6 lines
Furthermore, I would prefer quotes around $TAG and $TRAVIS_BRANCH. If either one of those two variables were empty (or contain multiple words) at that point, the shell would complain. Now, I don't think that either can end up being empty, so quotes are not necessary, but having quotes around them would save future readers from spending brain cycles on this unnecessarily.
Agreed. I will fix both things!
Thanks for the review,
Lars