|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +cd "$(dirname "$0")" |
| 6 | + |
| 7 | +STATUS=$(git status --porcelain) |
| 8 | + |
| 9 | +if [ -n "$STATUS" ]; then |
| 10 | + echo "====================================================================" |
| 11 | + echo "=============== ERROR: repository unclean, stopping! ===============" |
| 12 | + echo "====================================================================" |
| 13 | + echo |
| 14 | + git status |
| 15 | + echo |
| 16 | + echo "====================================================================" |
| 17 | + echo "=============== ERROR: repository unclean, stopping! ===============" |
| 18 | + echo "====================================================================" |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +### clean up old poetry artifacts: |
| 23 | +rm -rf dist/ |
| 24 | +### clean up potential leftovers from previous runs of this script: |
| 25 | +rm -rf sjlogging/ |
| 26 | + |
| 27 | +# move the source tree to the project root, so poetry will pick it up |
| 28 | +# automatically from there (without explicit configuration): |
| 29 | +mv src/main/resources/sjlogging . |
| 30 | + |
| 31 | +### parse the version from 'pom.xml': |
| 32 | +PACKAGE_VERSION=$(xmlstarlet sel --template -m _:project -v _:version pom.xml) |
| 33 | + |
| 34 | +### make sure to have a valid Python package version: |
| 35 | +case $PACKAGE_VERSION in |
| 36 | +*-SNAPSHOT*) |
| 37 | + echo "POM version [$PACKAGE_VERSION] is a snapshot!" |
| 38 | + PACKAGE_VERSION=${PACKAGE_VERSION/-SNAPSHOT/} |
| 39 | + ### calculate the distance to the last release tag: |
| 40 | + LAST_TAG=$(git tag --list 'jython-scijava-logging-*' | sort | tail -n1) |
| 41 | + # echo "Last git tag: '$LAST_TAG'" |
| 42 | + COMMITS_SINCE=$(git rev-list "${LAST_TAG}..HEAD" | wc -l) |
| 43 | + # echo "Nr of commits since last tag: $COMMITS_SINCE" |
| 44 | + HEAD_ID=$(git rev-parse --short HEAD) |
| 45 | + # echo "HEAD commit hash: $HEAD_ID" |
| 46 | + PACKAGE_VERSION="${PACKAGE_VERSION}.dev${COMMITS_SINCE}+${HEAD_ID}" |
| 47 | + ;; |
| 48 | +esac |
| 49 | + |
| 50 | +echo "Using package version: [$PACKAGE_VERSION]" |
| 51 | + |
| 52 | +### put the version into the project file and the package source: |
| 53 | +sed -i "s/\${project.version}/${PACKAGE_VERSION}/" pyproject.toml |
| 54 | +sed -i "s/\${project.version}/${PACKAGE_VERSION}/" sjlogging/__init__.py |
| 55 | + |
| 56 | +### let poetry build wheel and tar.gz: |
| 57 | +poetry build -vv |
| 58 | + |
| 59 | +### clean up the moved source tree and restore the previous state: |
| 60 | +rm -rf sjlogging/ |
| 61 | +git restore pyproject.toml |
| 62 | +git restore src/main/resources/sjlogging/ |
0 commit comments