Commit | Line | Data |
---|---|---|
51c9c62d | 1 | #!/bin/bash |
3f7ea864 JR |
2 | # shellcheck disable=SC2103 |
3 | # | |
4 | # Copyright (C) 2020 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> | |
5 | # | |
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. | |
10 | # | |
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. | |
15 | # | |
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/>. | |
18 | ||
51c9c62d MJ |
19 | set -exu |
20 | ||
3f7ea864 JR |
21 | #Required variables |
22 | GERRIT_NAME=${GERRIT_NAME:-} | |
23 | WORKSPACE=${WORKSPACE:-} | |
24 | conf=${conf:-} | |
25 | ||
26 | gerrit_url="https://${GERRIT_NAME}" | |
27 | gerrit_query="?o=CURRENT_REVISION&o=DOWNLOAD_COMMANDS" | |
28 | gerrit_json_query=".revisions[.current_revision].ref" | |
32dae18e | 29 | gerrit_json_query_status=".status" |
3f7ea864 | 30 | |
60428fd0 | 31 | possible_depends_on="lttng-ust|lttng-modules|userspace-rcu" |
3f7ea864 JR |
32 | re="Depends-on: (${possible_depends_on}): ([^'$'\n'']*)" |
33 | property_file="${WORKSPACE}/gerrit_custom_dependencies.properties" | |
34 | ||
35 | # Create the property file even if it ends up being empty | |
36 | touch "$property_file" | |
37 | ||
38 | # Move to lttng-tools source directory | |
39 | pushd "${WORKSPACE}/src/lttng-tools" | |
40 | ||
41 | git rev-list --format=%B --max-count=1 HEAD | while read -r line; do | |
705ab0a8 JR |
42 | # Deactivate debug mode to prevent the gcc warning publisher from picking up |
43 | # compiler error present in the commit message. | |
44 | set +x | |
3f7ea864 | 45 | if ! [[ ${line} =~ ${re} ]]; then |
705ab0a8 | 46 | set -x |
3f7ea864 JR |
47 | continue |
48 | fi | |
705ab0a8 | 49 | set -x |
3f7ea864 JR |
50 | |
51 | project=${BASH_REMATCH[1]} | |
52 | gerrit_id=${BASH_REMATCH[2]} | |
53 | ||
54 | project_sanitize=${BASH_REMATCH[1]//-/_} | |
55 | ||
56 | if [ "$conf" = "no-ust" ] && [ "$project" = "lttng-ust" ]; then | |
57 | # No need to checkout lttng-ust for this configuration axis | |
58 | continue | |
59 | fi | |
60 | ||
edb933dd MJ |
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" | |
66 | else | |
67 | # This job does not require modules sources | |
68 | continue | |
69 | fi | |
70 | fi | |
71 | ||
3f7ea864 JR |
72 | # Export the GERRIT_DEP_... into the property file for further jenkins usage |
73 | echo "GERRIT_DEP_${project_sanitize^^}=${gerrit_id}" >> "$property_file" | |
aff4e3d1 JR |
74 | # Deactivate tests for the project |
75 | echo "${project_sanitize^^}_RUN_TESTS=no" >> "$property_file" | |
3f7ea864 JR |
76 | |
77 | # Get the change latest ref | |
78 | ref=$(curl "${gerrit_url}/changes/${gerrit_id}${gerrit_query}" | tail -n+2 | jq -r "$gerrit_json_query") | |
32dae18e JR |
79 | change_status=$(curl "${gerrit_url}/changes/${gerrit_id}${gerrit_query}" | tail -n+2 | jq -r "$gerrit_json_query_status") |
80 | if [ "$change_status" == "MERGED" ]; then | |
81 | # When the change we depends on is merged use master as the ref. | |
82 | # This is not ideal CI time wise since we do not reuse artifacts. | |
83 | # This solve a tricky situation where we actually want to use master | |
84 | # instead of the change available on gerrit. Intermediary changes | |
85 | # present in master could have an impact on the change under test. | |
86 | ref="refs/heads/master" | |
87 | elif [ "$change_status" == "ABANDONED" ]; then | |
88 | # We have a situation where the "HEAD" commit for feature branch are | |
60428fd0 | 89 | # not merged and abandoned. Default to the master branch and hope |
32dae18e JR |
90 | # for the best. This is far from ideal but we need might also need |
91 | # to find a better way to handle feature branch here. In the | |
92 | # meantime use master for such cases. | |
93 | echo "Depends-on change is ABANDONED. Defaulting to master" | |
94 | ref="refs/heads/master" | |
95 | fi | |
96 | ||
60428fd0 JR |
97 | # The build.sh script from userspace-rcu expects the source to be located in |
98 | # `liburcu` instead of userspace-rcu. Accommodate for this here. | |
99 | if [ "$project" = "userspace-rcu" ]; then | |
100 | clone_directory="liburcu" | |
101 | else | |
102 | clone_directory="$project" | |
103 | fi | |
104 | ||
105 | clone_directory="$WORKSPACE/src/$clone_directory" | |
106 | ||
107 | git clone "${gerrit_url}/${project}" "$clone_directory" | |
108 | pushd "$clone_directory" | |
3f7ea864 JR |
109 | git fetch "${gerrit_url}/${project}" "$ref" |
110 | git checkout FETCH_HEAD | |
111 | popd | |
112 | done | |
113 | ||
114 | popd |