Fix API breakage caused by OS Plugin version scan
[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 # Script to install lftools via a version passed in via lf-infra-parameters
14 #
15 # Required parameters:
16 #
17 #     LFTOOLS_VERSION: Passed in via lf-infra-parameters configuration. Can be
18 #                      set to a strict version number like '1.2.3' or using
19 #                      PEP-440 definitions.
20 #
21 #                      Examples:
22 #                          <1.0.0
23 #                          >=1.0.0,<2.0.0
24 #
25 # By default a released version of lftools should always be used.
26 # The purpose of the 2 variables below is so that lftools devs can test
27 # unreleased versions of lftools. There are 2 methods to install a dev version
28 # of lftools:
29 #
30 #     1) gerrit patch: Used to test a patch that has not yet been merged.
31 #                      To do this set something like this:
32 #                          LFTOOLS_MODE=gerrit
33 #                          LFTOOLS_REFSPEC=refs/changes/96/5296/7
34 #
35 #     2) git branch: Used to install an lftools version from a specific branch.
36 #                    To use this set the variables as follows:
37 #                          LFTOOLS_MODE=git
38 #                          LFTOOLS_REFSPEC=master
39 #
40 #     3) release : The intended use case and default setting.
41 #                  Set LFTOOLS_MODE=release, in this case LFTOOLS_REFSPEC is unused.
42
43 LFTOOLS_MODE=release  # release | git | gerrit
44 LFTOOLS_REFSPEC=master
45
46 # Ensure we fail the job if any steps fail.
47 # DO NOT set -u as virtualenv's activate script has unbound variables
48 set -e -o pipefail
49
50 virtualenv --quiet "/tmp/v/lftools"
51 # shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091
52 source "/tmp/v/lftools/bin/activate"
53 pip install --quiet --upgrade "pip==9.0.3" setuptools
54
55 case $LFTOOLS_MODE in
56     gerrit)
57         git clone https://gerrit.linuxfoundation.org/infra/releng/lftools.git /tmp/lftools
58         pushd /tmp/lftools
59         git fetch origin "$LFTOOLS_REFSPEC"
60         git checkout FETCH_HEAD
61         pip install --quiet --upgrade -r requirements.txt
62         pip install --quiet --upgrade -e .
63         popd
64         ;;
65
66     git)
67         pip install --quiet --upgrade git+https://gerrit.linuxfoundation.org/infra/releng/lftools.git@"$BRANCH"
68         ;;
69
70     release)
71         if [[ $LFTOOLS_VERSION =~ ^[0-9] ]]; then
72             LFTOOLS_VERSION="==$LFTOOLS_VERSION"
73         fi
74
75         pip install --quiet --upgrade "lftools${LFTOOLS_VERSION}"
76         ;;
77 esac
78
79 lftools --version
80
81 # pipdeptree prints out a lot of information because lftools pulls in many
82 # dependencies. Let's only print it if we want to debug.
83 # echo "----> Pip Dependency Tree"
84 # pip install --quiet --upgrade pipdeptree
85 # pipdeptree