From c9e6978062b0e7d7f0cc87b838cd84286fcc44f4 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Mon, 22 Jun 2020 16:35:35 -0700 Subject: Fix the way PR build clones gVisor. Copybara force-pushes to the PR immediately before merging which triggers a PR build. Since the PR is merged, the refspec +refs/pull/{pr_num}/merge is not available and the build fails causing all master commit CI builds to show a failure. This change remove the clone step from travis and clone manually in a way which always would succeed. We fetch +refs/pull/{pr_num}/head and cherry pick that onto the target branch. I have tested this in https://github.com/ayushr2/gvisor/pull/1 and https://github.com/ayushr2/gvisor/pull/2. PiperOrigin-RevId: 317759891 --- .travis.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4cb202b7d..9d3141f38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,27 @@ language: shell dist: xenial +git: + clone: false # Clone manually in before_install +before_install: + - set -e -o pipefail + - | + if [ "${TRAVIS_PULL_REQUEST}" = false ]; then + # This is not a PR build, fetch and checkout the commit being tested + git clone -q --depth 1 "https://github.com/${TRAVIS_REPO_SLUG}.git" "${TRAVIS_REPO_SLUG}" + cd "${TRAVIS_REPO_SLUG}" + git fetch origin "${TRAVIS_COMMIT}" --depth 1 + git checkout -qf "${TRAVIS_COMMIT}" + else + # This is a PR build, simulate +refs/pull/{num}/merge. + # We can do that by fetching +refs/pull/{num}/head and cherry picking it + # onto the target branch. + git clone -q --branch "${TRAVIS_BRANCH}" --depth 1 "https://github.com/${TRAVIS_REPO_SLUG}.git" "${TRAVIS_REPO_SLUG}" + cd "${TRAVIS_REPO_SLUG}" + git fetch origin "+refs/pull/${TRAVIS_PULL_REQUEST}/head" --depth 1 + git config --global user.email "$(git log -1 FETCH_HEAD --pretty="%cE")" + git config --global user.name "$(git log -1 FETCH_HEAD --pretty="%aN")" + git cherry-pick --strategy=recursive -X theirs --keep-redundant-commits FETCH_HEAD + fi cache: directories: - /home/travis/.cache/bazel/ -- cgit v1.2.3