Merge branch '21025-keep-web-redirect-bypass'
[arvados.git] / build / get-package-version.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 # When run with WORKSPACE pointing at a git checkout of arvados, this script
7 # calculates the package version of an Arvados component.
8
9 # set to --no-cache-dir to disable pip caching
10 CACHE_FLAG=
11 STDOUT_IF_DEBUG=/dev/null
12 STDERR_IF_DEBUG=/dev/null
13 DASHQ_UNLESS_DEBUG=-q
14 ITERATION="${ARVADOS_BUILDING_ITERATION:-1}"
15
16 . `dirname "$(readlink -f "$0")"`/run-library.sh
17
18 TYPE_LANG=$1
19 SRC_PATH=$2
20
21 if [[ "$TYPE_LANG" == "" ]] || [[ "$SRC_PATH" == "" ]]; then
22   echo "Syntax: $0 <lang> <src_path>"
23   echo
24   echo "Example: $0 go cmd/arvados-client"
25   echo "Example: $0 python3 services/fuse"
26   echo
27   exit 1
28 fi
29
30 if [[ "$WORKSPACE" == "" ]]; then
31   echo "The WORKSPACE environment variable must be set, pointing at the root of the arvados git tree"
32   exit 1
33 fi
34
35
36 debug_echo "package_go_binary $SRC_PATH"
37
38 if [[ "$TYPE_LANG" == "go" ]]; then
39   calculate_go_package_version go_package_version $SRC_PATH
40   echo "${go_package_version}-${ITERATION}"
41 elif [[ "$TYPE_LANG" == "python3" ]]; then
42
43   cd $WORKSPACE/$SRC_PATH
44
45   rm -rf dist/*
46
47   # Get the latest setuptools
48   if ! pip3 install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'; then
49     echo "Error, unable to upgrade setuptools with"
50     echo "  pip3 install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U 'setuptools<45'"
51     exit 1
52   fi
53   # filter a useless warning (when building the cwltest package) from the stderr output
54   if ! python3 setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching' |grep -v 'for version number calculation'); then
55     echo "Error, unable to run python3 setup.py sdist for $SRC_PATH"
56     exit 1
57   fi
58
59   PYTHON_VERSION=$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)
60   UNFILTERED_PYTHON_VERSION=$(echo -n $PYTHON_VERSION | sed s/\.dev/~dev/g |sed 's/\([0-9]\)rc/\1~rc/g')
61
62   echo "${UNFILTERED_PYTHON_VERSION}-${ITERATION}"
63 fi
64