2 # shellcheck disable=SC2103
4 # Copyright (C) 2020 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 GERRIT_NAME
=${GERRIT_NAME:-}
23 WORKSPACE
=${WORKSPACE:-}
26 gerrit_url
="https://${GERRIT_NAME}"
27 gerrit_query
="&o=CURRENT_REVISION&o=DOWNLOAD_COMMANDS"
28 gerrit_json_query
=".[0].revisions[.[0].current_revision].ref"
29 gerrit_json_query_status
=".[0].status"
31 possible_depends_on
="lttng-ust|lttng-modules|userspace-rcu|babeltrace"
32 re
="Depends-on: (${possible_depends_on}): ([^'$'\n'']*)"
33 property_file
="${WORKSPACE}/gerrit_custom_dependencies.properties"
35 # Create the property file even if it ends up being empty
36 touch "$property_file"
38 # Move to lttng-tools source directory
39 pushd "${WORKSPACE}/src/lttng-tools"
41 git rev-list
--format=%B
--max-count=1 HEAD |
while read -r line
; do
42 # Deactivate debug mode to prevent the gcc warning publisher from picking up
43 # compiler error present in the commit message.
45 if ! [[ ${line} =~
${re} ]]; then
51 project
=${BASH_REMATCH[1]}
52 gerrit_id
=${BASH_REMATCH[2]}
54 project_sanitize
=${BASH_REMATCH[1]//-/_}
56 if [ "$conf" = "no-ust" ] && [ "$project" = "lttng-ust" ]; then
57 # No need to checkout lttng-ust for this configuration axis
61 if [ "$project" = "lttng-modules" ]; then
62 if [ -d "$WORKSPACE/src/lttng-modules" ]; then
63 # Remove the regular modules sources to replace them with those
64 # from the gerrit change
65 rm -rf "$WORKSPACE/src/lttng-modules"
69 # Export the GERRIT_DEP_... into the property file for further jenkins usage
70 echo "GERRIT_DEP_${project_sanitize^^}=${gerrit_id}" >> "$property_file"
71 # Deactivate tests for the project
72 echo "${project_sanitize^^}_RUN_TESTS=no" >> "$property_file"
74 # Get the change latest ref
77 # This is necessary since a cherry pick can have the same change id
78 # across branches. Still this is only valid for projects where the
79 # branch name fits the same branch name style of the lttng-tools
81 # We will need to be much more clever if the situation arise where
82 # we need to depends-on a cherry picked change id for the
83 # userspace-rcu or babeltrace project. Until then let's use this
84 # hack. The quick solution to this is to tell the committer to change
85 # the change id. We could also be clever and require that the
86 # "branch name" be included in the `Depends-on` clause.
87 local_query
="${gerrit_url}/changes/?q=change:${gerrit_id}+branch:${GERRIT_BRANCH}${gerrit_query}"
88 default_branch
="${GERRIT_BRANCH}"
91 local_query
="${gerrit_url}/changes/?q=change:${gerrit_id}${gerrit_query}"
92 default_branch
="master"
96 json_doc
=$
(curl
"$local_query" |
tail -n+2)
97 count
=$
(jq
-r '. | length' <<< "$json_doc")
98 if [ "$count" != "1" ]; then
99 echo "Expected an array of size 1 got $count"
103 ref
=$
(jq
-r "$gerrit_json_query" <<< "$json_doc")
104 change_status
=$
(jq
-r "$gerrit_json_query_status" <<< "$json_doc")
105 if [ "$change_status" == "MERGED" ]; then
106 # When the change we depends on is merged use master as the ref.
107 # This is not ideal CI time wise since we do not reuse artifacts.
108 # This solve a tricky situation where we actually want to use master
109 # instead of the change available on gerrit. Intermediary changes
110 # present in master could have an impact on the change under test.
111 echo "Depends-on change is MERGED. Defaulting to ${default_branch}"
112 ref
="refs/heads/$default_branch"
113 elif [ "$change_status" == "ABANDONED" ]; then
114 # We have a situation where the "HEAD" commit for feature branch are
115 # not merged and abandoned. Default to the master branch and hope
116 # for the best. This is far from ideal but we need might also need
117 # to find a better way to handle feature branch here. In the
118 # meantime use master for such cases.
119 echo "Depends-on change is ABANDONED. Defaulting to ${default_branch}"
120 ref
="refs/heads/${default_branch}"
123 # The build.sh script from userspace-rcu expects the source to be located in
124 # `liburcu` instead of userspace-rcu. Accommodate for this here.
125 if [ "$project" = "userspace-rcu" ]; then
126 clone_directory
="liburcu"
128 clone_directory
="$project"
131 clone_directory
="$WORKSPACE/src/$clone_directory"
133 git clone
"${gerrit_url}/${project}" "$clone_directory"
134 pushd "$clone_directory"
135 git fetch
"${gerrit_url}/${project}" "$ref"
136 git checkout FETCH_HEAD
This page took 0.033131 seconds and 4 git commands to generate.