|
| 1 | +#!/bin/bash |
| 2 | +set -ev |
| 3 | + |
| 4 | +#saveGitCredentials() { |
| 5 | +# cat >$HOME/.netrc <<EOL |
| 6 | +#machine github.com |
| 7 | +#login ${GITHUB_USERNAME} |
| 8 | +#password ${GITHUB_TOKEN} |
| 9 | +# |
| 10 | +#machine api.github.com |
| 11 | +#login ${GITHUB_USERNAME} |
| 12 | +#password ${GITHUB_TOKEN} |
| 13 | +#EOL |
| 14 | +# chmod 600 $HOME/.netrc |
| 15 | +#} |
| 16 | + |
| 17 | +getVersion() { |
| 18 | + ./gradlew properties -q | grep "version:" | grep -v "kotlin_version:" | awk '{print $2}' | tr -d '[:space:]' |
| 19 | +} |
| 20 | + |
| 21 | +removeSnapshots() { |
| 22 | + sed -i 's/-SNAPSHOT//' gradle.properties |
| 23 | +} |
| 24 | + |
| 25 | +commitRelease() { |
| 26 | + local APP_VERSION=$(getVersion) |
| 27 | + git commit -a -m "Update version for release" |
| 28 | + git tag -a "v${APP_VERSION}" -m "Tag release version" |
| 29 | +} |
| 30 | + |
| 31 | +bumpVersion() { |
| 32 | + echo "Bump version number" |
| 33 | + local APP_VERSION=$(getVersion | xargs) |
| 34 | + local SEMANTIC_REGEX='^([0-9]+)\.([0-9]+)(\.([0-9]+))?$' |
| 35 | + if [[ ${APP_VERSION} =~ ${SEMANTIC_REGEX} ]]; then |
| 36 | + if [[ ${BASH_REMATCH[4]} ]]; then |
| 37 | + nextVersion=$((BASH_REMATCH[4] + 1)) |
| 38 | + nextVersion="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${nextVersion}-SNAPSHOT" |
| 39 | + else |
| 40 | + nextVersion=$((BASH_REMATCH[2] + 1)) |
| 41 | + nextVersion="${BASH_REMATCH[1]}.${nextVersion}-SNAPSHOT" |
| 42 | + fi |
| 43 | + |
| 44 | + echo "Next version: ${nextVersion}" |
| 45 | + sed -i -E "s/^version(\s)?=.*/version=${nextVersion}/" gradle.properties |
| 46 | + else |
| 47 | + echo "No semantic version and therefore cannot publish to maven repository: '${APP_VERSION}'" |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +commitNextVersion() { |
| 52 | + git commit -a -m "Update version for release" |
| 53 | +} |
| 54 | + |
| 55 | +git config --global user.email "[email protected]" |
| 56 | +git config --global user.name "GitHub Actions" |
| 57 | + |
| 58 | +echo "Deploying release to Bintray" |
| 59 | +removeSnapshots |
| 60 | + |
| 61 | +./gradlew clean assemble && ./gradlew bintrayUpload -x check --info |
| 62 | + |
| 63 | +commitRelease |
| 64 | +bumpVersion |
| 65 | +commitNextVersion |
| 66 | +git push --follow-tags |
0 commit comments