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" | |
29 | ||
edb933dd | 30 | possible_depends_on="lttng-ust|lttng-modules" |
3f7ea864 JR |
31 | re="Depends-on: (${possible_depends_on}): ([^'$'\n'']*)" |
32 | property_file="${WORKSPACE}/gerrit_custom_dependencies.properties" | |
33 | ||
34 | # Create the property file even if it ends up being empty | |
35 | touch "$property_file" | |
36 | ||
37 | # Move to lttng-tools source directory | |
38 | pushd "${WORKSPACE}/src/lttng-tools" | |
39 | ||
40 | git rev-list --format=%B --max-count=1 HEAD | while read -r line; do | |
705ab0a8 JR |
41 | # Deactivate debug mode to prevent the gcc warning publisher from picking up |
42 | # compiler error present in the commit message. | |
43 | set +x | |
3f7ea864 | 44 | if ! [[ ${line} =~ ${re} ]]; then |
705ab0a8 | 45 | set -x |
3f7ea864 JR |
46 | continue |
47 | fi | |
705ab0a8 | 48 | set -x |
3f7ea864 JR |
49 | |
50 | project=${BASH_REMATCH[1]} | |
51 | gerrit_id=${BASH_REMATCH[2]} | |
52 | ||
53 | project_sanitize=${BASH_REMATCH[1]//-/_} | |
54 | ||
55 | if [ "$conf" = "no-ust" ] && [ "$project" = "lttng-ust" ]; then | |
56 | # No need to checkout lttng-ust for this configuration axis | |
57 | continue | |
58 | fi | |
59 | ||
edb933dd MJ |
60 | if [ "$project" = "lttng-modules" ]; then |
61 | if [ -d "$WORKSPACE/src/lttng-modules" ]; then | |
62 | # Remove the regular modules sources to replace them with those | |
63 | # from the gerrit change | |
64 | rm -rf "$WORKSPACE/src/lttng-modules" | |
65 | else | |
66 | # This job does not require modules sources | |
67 | continue | |
68 | fi | |
69 | fi | |
70 | ||
3f7ea864 JR |
71 | # Export the GERRIT_DEP_... into the property file for further jenkins usage |
72 | echo "GERRIT_DEP_${project_sanitize^^}=${gerrit_id}" >> "$property_file" | |
73 | ||
74 | # Get the change latest ref | |
75 | ref=$(curl "${gerrit_url}/changes/${gerrit_id}${gerrit_query}" | tail -n+2 | jq -r "$gerrit_json_query") | |
76 | git clone "${gerrit_url}/${project}" "$WORKSPACE/src/$project" | |
77 | pushd "$WORKSPACE/src/$project" | |
78 | git fetch "${gerrit_url}/${project}" "$ref" | |
79 | git checkout FETCH_HEAD | |
80 | popd | |
81 | done | |
82 | ||
83 | popd |