2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> gerrit-fetch-dependencies.sh"
12 # Fetches patches all projects provided by comment trigger
14 # Takes a list of Gerrit patches and fetches all projects and cherry-pick
15 # patches for projects. The trigger is
16 # 'recheck: SPACE_SEPERATED_LIST_OF_PATCHES'
18 # 'reverify: SPACE_SEPERATED_LIST_OF_PATCHES'
20 # NOTE: This script assumes the user will provide the correct dependency order
21 # via the PATCHES list.
23 # Ensure we fail the job if any steps fail.
26 REPOS_DIR="$WORKSPACE/.repos"
28 IFS=" " read -r -a PATCHES <<< "$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep -E '(recheck:|reverify:)' | awk -F: '{print $2}')"
30 # Workaround for git-review bug in v1.24
31 # https://storyboard.openstack.org/#!/story/2001081
32 set +u # Allow unbound variables for virtualenv
33 virtualenv --quiet "/tmp/v/git-review"
34 # shellcheck source=/tmp/v/git-review/bin/activate disable=SC1091
35 source "/tmp/v/git-review/bin/activate"
36 pip install --quiet --upgrade "pip==9.0.3" setuptools
37 pip install --quiet --upgrade git-review
39 # End git-review workaround
42 for patch in $(echo "${PATCHES[@]}"); do
43 json=$(curl -s "$GERRIT_URL/changes/$patch" | sed -e "s/)]}'//")
44 project=$(echo "$json" | jq -r '.project')
45 branch=$(echo "$json" | jq -r '.branch')
47 if [ "$GERRIT_CHANGE_NUMBER" == "$patch" ]; then
48 echo "WARN: GERRIT_CHANGE and $patch are one and the same. Ignoring patch..."
52 if [ ! -d "$REPOS_DIR/$project" ]; then
53 git clone -q --depth 1 -b "$branch" "$GIT_URL/$project" "$REPOS_DIR/$project"
55 # This array will be used later to determine project build order.
56 projects+=("$project")
59 pushd "$REPOS_DIR/$project"
60 # If remote gerrit already exists just make sure path is expected
61 if ! git remote add gerrit "$GERRIT_URL/$project" > /dev/null 2>&1; then
62 git remote set-url gerrit "$GERRIT_URL/$project"
64 git review --cherrypick="$patch"
68 # This script should be a macro which re-inject's the projects variable back
69 # into the build so a script later on can use it.
70 echo "DEPENDENCY_BUILD_ORDER=${projects[*]}" > "$WORKSPACE/.dependency.properties"