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