Fix rtd merge job to handle new tag uploaded
[releng/global-jjb.git] / shell / python-tools-install.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 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 "---> python-tools-install.sh"
12
13 set -eu -o pipefail
14
15 # Generate a list of 'pip' packages pre-build/post-build
16 # During post-build, perform a diff on the two lists and copy files to archive directory
17 echo "Listing pip packages"
18 pip_list_pre=/tmp/pip-list-pre.txt
19 pip_list_post=/tmp/pip-list-post.txt
20 pip_list_diffs=/tmp/pip-list-diffs.txt
21 if [[ -f $pip_list_pre ]]; then
22     python3 -m pip list > $pip_list_post
23     echo "Compare pip packages before/after..."
24     if diff --suppress-common-lines $pip_list_pre $pip_list_post \
25             | tee $pip_list_diffs; then
26         echo "No diffs" | tee $pip_list_diffs
27     fi
28     mkdir -p "$WORKSPACE/archives"
29     cp "$pip_list_pre" "$pip_list_post" "$pip_list_diffs" "$WORKSPACE/archives"
30     rm -rf "$pip_list_pre" "$pip_list_post" "$pip_list_diffs"
31     ls "$WORKSPACE/archives"
32     # Would just like to 'exit 0' here but we can't because the
33     # log-deploy.sh script is 'appended' to this file and it would not
34     # be executed.
35 else
36     python3 -m pip list > "$pip_list_pre"
37     # These 'pip installs' only need to be executed during pre-build
38
39     requirements_file=$(mktemp /tmp/requirements-XXXX.txt)
40
41     # Note: To test lftools master branch change the lftools configuration below in
42     #       the requirements file from "lftools[openstack]~=#.##.#" to
43     #       git+https://github.com/lfit/releng-lftools.git#egg=lftools[openstack]
44
45     echo "Generating Requirements File"
46     cat << 'EOF' > "$requirements_file"
47 lftools[openstack]
48 python-heatclient
49 python-openstackclient
50 niet~=1.4.2
51 tox>=3.7.0 # Tox 3.7 or greater is necessary for parallel mode support
52 yq
53 EOF
54
55     # Use `python -m pip` to ensure we are using the latest version of pip
56     python3 -m venv ~/.local
57     python3 -m pip install --user --quiet --upgrade pip
58     python3 -m pip install --user --quiet --upgrade setuptools
59     python3 -m pip install --user --quiet --upgrade -r "$requirements_file"
60     rm -rf "$requirements_file"
61 fi