X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=scripts%2Flttng-tools%2Fgerrit-depends-on.sh;h=7f62f82d6fe52699035bbdae059f8eb268f0016c;hb=32dae18e9f1860e274a91cf31c0f21825b2ee71a;hp=062323bfb50c3f84279b76761605d7863d2cf93c;hpb=3f7ea864199cffe7601489aa0b3a2aeccf9c0695;p=lttng-ci.git diff --git a/scripts/lttng-tools/gerrit-depends-on.sh b/scripts/lttng-tools/gerrit-depends-on.sh index 062323b..7f62f82 100755 --- a/scripts/lttng-tools/gerrit-depends-on.sh +++ b/scripts/lttng-tools/gerrit-depends-on.sh @@ -1,4 +1,4 @@ -#!/bin/bash -exu +#!/bin/bash # shellcheck disable=SC2103 # # Copyright (C) 2020 Jonathan Rajotte-Julien @@ -16,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +set -exu + #Required variables GERRIT_NAME=${GERRIT_NAME:-} WORKSPACE=${WORKSPACE:-} @@ -24,8 +26,9 @@ conf=${conf:-} gerrit_url="https://${GERRIT_NAME}" gerrit_query="?o=CURRENT_REVISION&o=DOWNLOAD_COMMANDS" gerrit_json_query=".revisions[.current_revision].ref" +gerrit_json_query_status=".status" -possible_depends_on="lttng-ust" +possible_depends_on="lttng-ust|lttng-modules" re="Depends-on: (${possible_depends_on}): ([^'$'\n'']*)" property_file="${WORKSPACE}/gerrit_custom_dependencies.properties" @@ -36,9 +39,14 @@ touch "$property_file" pushd "${WORKSPACE}/src/lttng-tools" git rev-list --format=%B --max-count=1 HEAD | while read -r line; do + # Deactivate debug mode to prevent the gcc warning publisher from picking up + # compiler error present in the commit message. + set +x if ! [[ ${line} =~ ${re} ]]; then + set -x continue fi + set -x project=${BASH_REMATCH[1]} gerrit_id=${BASH_REMATCH[2]} @@ -50,11 +58,40 @@ git rev-list --format=%B --max-count=1 HEAD | while read -r line; do continue fi + if [ "$project" = "lttng-modules" ]; then + if [ -d "$WORKSPACE/src/lttng-modules" ]; then + # Remove the regular modules sources to replace them with those + # from the gerrit change + rm -rf "$WORKSPACE/src/lttng-modules" + else + # This job does not require modules sources + continue + fi + fi + # Export the GERRIT_DEP_... into the property file for further jenkins usage echo "GERRIT_DEP_${project_sanitize^^}=${gerrit_id}" >> "$property_file" # Get the change latest ref ref=$(curl "${gerrit_url}/changes/${gerrit_id}${gerrit_query}" | tail -n+2 | jq -r "$gerrit_json_query") + change_status=$(curl "${gerrit_url}/changes/${gerrit_id}${gerrit_query}" | tail -n+2 | jq -r "$gerrit_json_query_status") + if [ "$change_status" == "MERGED" ]; then + # When the change we depends on is merged use master as the ref. + # This is not ideal CI time wise since we do not reuse artifacts. + # This solve a tricky situation where we actually want to use master + # instead of the change available on gerrit. Intermediary changes + # present in master could have an impact on the change under test. + ref="refs/heads/master" + elif [ "$change_status" == "ABANDONED" ]; then + # We have a situation where the "HEAD" commit for feature branch are + # not merged and abandonned. Default to the master branch and hope + # for the best. This is far from ideal but we need might also need + # to find a better way to handle feature branch here. In the + # meantime use master for such cases. + echo "Depends-on change is ABANDONED. Defaulting to master" + ref="refs/heads/master" + fi + git clone "${gerrit_url}/${project}" "$WORKSPACE/src/$project" pushd "$WORKSPACE/src/$project" git fetch "${gerrit_url}/${project}" "$ref"