diff --git a/scripts/travis/build.sh b/scripts/travis/build.sh index 8dde0a604a..2c4fff11d6 100644 --- a/scripts/travis/build.sh +++ b/scripts/travis/build.sh @@ -1,9 +1,23 @@ #!/usr/bin/env bash -set -ev +echo "=========================== Starting Build Script ===========================" +PS4="\[\e[35m\]+ \[\e[m\]" +set -vex pushd "$(dirname "${BASH_SOURCE[0]}")/../../" -PROFILES="$([ "${TRAVIS_BUILD_STAGE_NAME,,}" = "release" ] && echo "-Pinternal" || echo "-PcommunityDocker" )" +source "$(dirname "${BASH_SOURCE[0]}")/build_functions.sh" + +if isBranchBuild && [ "${TRAVIS_BRANCH}" = "master" ] && [ "${TRAVIS_BUILD_STAGE_NAME,,}" = "release" ] ; then + # update ":latest" image tags on remote repositories by using the maven *internal* profile + PROFILES="-Pinternal" +else + # build the ":latest" image tags locally with the maven *communityDocker* profile + PROFILES="-PcommunityDocker" +fi mvn -B -V install -DskipTests -Dmaven.javadoc.skip=true "${PROFILES}" +popd +set +vex +echo "=========================== Finishing Build Script ==========================" + diff --git a/scripts/travis/build_functions.sh b/scripts/travis/build_functions.sh index d2b05dbb41..3efdc21e2f 100644 --- a/scripts/travis/build_functions.sh +++ b/scripts/travis/build_functions.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set +vx function isPullRequestBuild() { test "${TRAVIS_PULL_REQUEST}" != "false" @@ -12,6 +13,8 @@ function cloneRepo() { local REPO="${1}" local TAG_OR_BRANCH="${2}" + printf "Clonning \"%s\" on %s\n" "${TAG_OR_BRANCH}" "${REPO}" + # clone the repository branch/tag pushd "$(dirname "${BASH_SOURCE[0]}")/../../../" >/dev/null @@ -62,7 +65,26 @@ function remoteBranchExists() { local REMOTE_REPO="${1}" local BRANCH="${2}" - git ls-remote --exit-code --heads "https://${GIT_USERNAME}:${GIT_PASSWORD}@${REMOTE_REPO}" "${BRANCH}" + git ls-remote --exit-code --heads "https://${GIT_USERNAME}:${GIT_PASSWORD}@${REMOTE_REPO}" "${BRANCH}" &>/dev/null +} + +function identifyUpstreamSourceBranch() { + local UPSTREAM_REPO="${1}" + + # if it's a pull request, use the source branch name (if it exists) + if isPullRequestBuild && remoteBranchExists "${UPSTREAM_REPO}" "${TRAVIS_PULL_REQUEST_BRANCH}" ; then + echo "${TRAVIS_PULL_REQUEST_BRANCH}" + exit 0 + fi + + # otherwise use the current branch name (or in case of PRs, the target branch name) + if remoteBranchExists "${UPSTREAM_REPO}" "${TRAVIS_BRANCH}" ; then + echo "${TRAVIS_BRANCH}" + exit 0 + fi + + # if none of the previous exists, use the "master" branch + echo "master" } function pullUpstreamTag() { @@ -91,20 +113,8 @@ function pullUpstreamTagAndBuildDockerImage() { function pullAndBuildSameBranchOnUpstream() { local UPSTREAM_REPO="${1}" local EXTRA_BUILD_ARGUMENTS="${2}" - local SOURCE_BRANCH="$(isBranchBuild && echo "${TRAVIS_BRANCH}" || echo "${TRAVIS_PULL_REQUEST_BRANCH}")" - if ! remoteBranchExists "${UPSTREAM_REPO}" "${SOURCE_BRANCH}" ; then - printf "Branch \"%s\" not found on the %s repository\n" "${SOURCE_BRANCH}" "${UPSTREAM_REPO}" - #exit 1 - fi - - local SOURCE_BRANCH="${TRAVIS_BRANCH}" - if ! remoteBranchExists "${UPSTREAM_REPO}" "${SOURCE_BRANCH}" ; then - printf "Branch \"%s\" not found on the %s repository\n" "${SOURCE_BRANCH}" "${UPSTREAM_REPO}" - #exit 1 - fi - # TODO remove this line and enable the previous "exit" commands: - local SOURCE_BRANCH="master" + local SOURCE_BRANCH="$(identifyUpstreamSourceBranch "${UPSTREAM_REPO}")" cloneRepo "${UPSTREAM_REPO}" "${SOURCE_BRANCH}" @@ -118,3 +128,19 @@ function pullAndBuildSameBranchOnUpstream() { popd } +function retieveLatestTag() { + local REPO="${1}" + local BRANCH="${2}" + + local LOCAL_PATH="/tmp/$(basename "${REPO%.git}")" + + git clone -q -b "${BRANCH}" "https://${GIT_USERNAME}:${GIT_PASSWORD}@${REPO}" "${LOCAL_PATH}" + + pushd "${LOCAL_PATH}" >/dev/null + git describe --abbrev=0 --tags + popd >/dev/null + + rm -rf "${LOCAL_PATH}" +} + +set -vx diff --git a/scripts/travis/init.sh b/scripts/travis/init.sh index d6dd516c28..efec4313b3 100644 --- a/scripts/travis/init.sh +++ b/scripts/travis/init.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash -set -ev +echo "=========================== Starting Init Script ===========================" +PS4="\[\e[35m\]+ \[\e[m\]" +set -vex pushd "$(dirname "${BASH_SOURCE[0]}")/../../" # Maven Setup @@ -7,6 +9,7 @@ mkdir -p "${HOME}/.m2" && cp -f .travis.settings.xml "${HOME}/.m2/settings.xml" find "${HOME}/.m2/repository/" -type d -name "*-SNAPSHOT*" | xargs -r -l rm -rf # Docker Logins +echo "${DOCKERHUB_PASSWORD}" | docker login -u="${DOCKERHUB_USERNAME}" --password-stdin echo "${QUAY_PASSWORD}" | docker login -u="${QUAY_USERNAME}" --password-stdin quay.io # Enable experimental docker features (for the image squash option) @@ -16,3 +19,7 @@ sudo service docker restart # not helpful in this script # export HOST_IP=$(hostname -I | cut -f1 -d' ') +popd +set +vex +echo "=========================== Finishing Init Script ==========================" + diff --git a/scripts/travis/maven_release.sh b/scripts/travis/maven_release.sh index 990b45b7f9..beb01fb830 100755 --- a/scripts/travis/maven_release.sh +++ b/scripts/travis/maven_release.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash -set -ev +echo "=========================== Starting Release Script ===========================" +PS4="\[\e[35m\]+ \[\e[m\]" +set -vex +pushd "$(dirname "${BASH_SOURCE[0]}")/../../" + # Use full history for release git checkout -B "${TRAVIS_BRANCH}" @@ -15,3 +19,8 @@ mvn -B \ -Dusername="${GIT_USERNAME}" \ -Dpassword="${GIT_PASSWORD}" + +popd +set +vex +echo "=========================== Finishing Release Script ==========================" + diff --git a/scripts/travis/update_downstream.sh b/scripts/travis/update_downstream.sh index 8868656124..c81e0ac547 100644 --- a/scripts/travis/update_downstream.sh +++ b/scripts/travis/update_downstream.sh @@ -6,20 +6,22 @@ pushd "$(dirname "${BASH_SOURCE[0]}")/../../" source "$(dirname "${BASH_SOURCE[0]}")/build_functions.sh" +#Fetch the latest changes, as Travis will only checkout the PR commit +git fetch origin "${TRAVIS_BRANCH}" +git checkout "${TRAVIS_BRANCH}" +git pull + +# Retrieve the current Community version - latest tag on the current branch +VERSION="$(git describe --abbrev=0 --tags)" + DOWNSTREAM_REPO="github.com/Alfresco/alfresco-enterprise-repo.git" cloneRepo "${DOWNSTREAM_REPO}" "${TRAVIS_BRANCH}" cd "$(dirname "${BASH_SOURCE[0]}")/../../../$(basename "${DOWNSTREAM_REPO%.git}")" -# Update parent -mvn -B versions:update-parent versions:commit - -VERSION="$(sed -n '//,/<\/parent>/p' pom.xml \ - | sed -n '//,/<\/version>/p' \ - | tr -d '\n' \ - | grep -oP '(?<=).*(?=)' \ - | xargs)" +# Update parent version +mvn -B versions:update-parent versions:commit "-DparentVersion=[${VERSION}]" # Update dependency version mvn -B versions:set-property versions:commit \