Fabio Utzig | 14301ab | 2020-04-16 17:20:38 -0300 | [diff] [blame] | 1 | #!/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 | |
| 15 | if [[ $TRAVIS_PULL_REQUEST != "false" || $TRAVIS_BRANCH != "master" ]]; then |
| 16 | echo "Either a PR or not \"master\" branch, exiting" |
| 17 | exit 0 |
| 18 | fi |
| 19 | |
| 20 | IMGTOOL_VER_PREFIX="\+imgtool_version = " |
| 21 | IMGTOOL_VER_FILE="imgtool/__init__.py" |
| 22 | DIST_DIR="dist" |
| 23 | |
| 24 | if [[ -z "$TWINE_TOKEN" ]]; then |
| 25 | echo "\$TWINE_TOKEN must be set in travis settings" |
| 26 | exit 0 |
| 27 | fi |
| 28 | |
| 29 | cd scripts/ |
| 30 | |
| 31 | last_release=$(pip show imgtool | grep "Version: " | cut -d" " -f2) |
| 32 | repo_version=$(grep "imgtool_version = " imgtool/__init__.py | sed 's/^.* = "\(.*\)"/\1/g') |
| 33 | |
| 34 | python3 ../ci/compare_versions.py --old $last_release --new $repo_version |
| 35 | rc=$? |
| 36 | |
| 37 | if [[ $rc -eq 0 ]]; then |
| 38 | echo "Imgtool version not changed; will not publish" |
| 39 | exit 0 |
| 40 | elif [[ $rc -eq 1 ]]; then |
| 41 | echo "Error parsing versions" |
| 42 | exit 1 |
| 43 | elif [[ $rc -eq 3 ]]; then |
| 44 | echo "Imgtool downgrade detected!" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | rm -rf $DIST_DIR |
| 49 | python setup.py sdist bdist_wheel |
| 50 | |
| 51 | twine upload --username __token__ --password "${TWINE_TOKEN}" "${DIST_DIR}/*" |