Add method to test dev versions of lftools
[releng/global-jjb.git] / shell / lftools-install.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
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 "---> lftools-install.sh"
12
13 # By default a released version of lftools should always be used.
14 # The purpose of the 2 variables below is so that lftools devs can test
15 # unreleased versions of lftools. There are 2 methods to install a dev version
16 # of lftools:
17 #
18 #     1) gerrit patch: Used to test a patch that has not yet been merged.
19 #                      To do this set something like this:
20 #                          LFTOOLS_MODE=gerrit
21 #                          LFTOOLS_REFSPEC=refs/changes/96/5296/7
22 #
23 #     2) git branch: Used to install an lftools version from a specific branch.
24 #                    To use this set the variables as follows:
25 #                          LFTOOLS_MODE=git
26 #                          LFTOOLS_REFSPEC=master
27 #
28 #     3) release : The intended use case and default setting.
29 #                  Set LFTOOLS_MODE=release, in this case LFTOOLS_REFSPEC is unused.
30
31 LFTOOLS_MODE=release  # release | git | gerrit
32 LFTOOLS_REFSPEC=master
33
34 # Ensure we fail the job if any steps fail.
35 # DO NOT set -u as virtualenv's activate script has unbound variables
36 set -e -o pipefail
37
38 virtualenv --quiet "/tmp/v/lftools"
39 # shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091
40 source "/tmp/v/lftools/bin/activate"
41 pip install --quiet --upgrade pip
42
43 case $LFTOOLS_MODE in
44     gerrit)
45         git clone https://gerrit.linuxfoundation.org/infra/releng/lftools.git /tmp/lftools
46         pushd /tmp/lftools
47         git fetch origin "$LFTOOLS_REFSPEC"
48         git checkout FETCH_HEAD
49         pip install --quiet --upgrade -r requirements.txt
50         pip install --quiet --upgrade -e .
51         popd
52         ;;
53
54     git)
55         pip install --quiet --upgrade git+https://gerrit.linuxfoundation.org/infra/releng/lftools.git@"$BRANCH"
56         ;;
57
58     release)
59         pip install --quiet --upgrade "lftools<1.0.0"
60         ;;
61 esac
62
63 # pipdeptree prints out a lot of information because lftools pulls in many
64 # dependencies. Let's only print it if we want to debug.
65 # echo "----> Pip Dependency Tree"
66 # pip install --quiet --upgrade pipdeptree
67 # pipdeptree