blob: 1cf042d48ad6dfdc56c051d01ce3f19df5823a1d [file] [log] [blame]
Fabio Utzig14301ab2020-04-16 17:20:38 -03001#!/bin/bash -x
2
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15if [[ $TRAVIS_PULL_REQUEST != "false" || $TRAVIS_BRANCH != "master" ]]; then
16 echo "Either a PR or not \"master\" branch, exiting"
17 exit 0
18fi
19
20IMGTOOL_VER_PREFIX="\+imgtool_version = "
21IMGTOOL_VER_FILE="imgtool/__init__.py"
22DIST_DIR="dist"
23
24if [[ -z "$TWINE_TOKEN" ]]; then
25 echo "\$TWINE_TOKEN must be set in travis settings"
26 exit 0
27fi
28
29cd scripts/
30
31last_release=$(pip show imgtool | grep "Version: " | cut -d" " -f2)
32repo_version=$(grep "imgtool_version = " imgtool/__init__.py | sed 's/^.* = "\(.*\)"/\1/g')
33
34python3 ../ci/compare_versions.py --old $last_release --new $repo_version
35rc=$?
36
37if [[ $rc -eq 0 ]]; then
38 echo "Imgtool version not changed; will not publish"
39 exit 0
40elif [[ $rc -eq 1 ]]; then
41 echo "Error parsing versions"
42 exit 1
43elif [[ $rc -eq 3 ]]; then
44 echo "Imgtool downgrade detected!"
45 exit 1
46fi
47
48rm -rf $DIST_DIR
49python setup.py sdist bdist_wheel
50
51twine upload --username __token__ --password "${TWINE_TOKEN}" "${DIST_DIR}/*"