From 948253618cb1b269459a9cb81be989850f9fc5cf Mon Sep 17 00:00:00 2001 From: fredboy Date: Wed, 17 Apr 2024 02:56:39 +0700 Subject: [PATCH] Add release scripts --- .gitignore | 2 ++ gen-changelog.sh | 16 +++++++++++++++ make-release.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ up-version.sh | 22 +++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100755 gen-changelog.sh create mode 100755 make-release.sh create mode 100755 up-version.sh diff --git a/.gitignore b/.gitignore index ac624d2..c83f78b 100644 --- a/.gitignore +++ b/.gitignore @@ -116,3 +116,5 @@ Thumbs.db !/ios-moe/xcode/*.xcodeproj/xcshareddata !/ios-moe/xcode/*.xcodeproj/project.pbxproj /ios-moe/xcode/native/ + +release-*/ \ No newline at end of file diff --git a/gen-changelog.sh b/gen-changelog.sh new file mode 100755 index 0000000..f2959c1 --- /dev/null +++ b/gen-changelog.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +previous_tag=0 +i=0 +for current_tag in $(git tag --sort=-creatordate) +do + +if [ "$previous_tag" != 0 ] && [ $i -lt 1 ]; then + i=$(echo "$i + 1" | bc -q ) + tag_date=$(git log -1 --pretty=format:'%ad' --date=short ${previous_tag}) + printf "## ${previous_tag} (${tag_date})\n\n" + git log ${current_tag}...${previous_tag} --pretty=format:'* %s ' --reverse | grep -v Merge + printf "\n\n" +fi +previous_tag=${current_tag} +done diff --git a/make-release.sh b/make-release.sh new file mode 100755 index 0000000..e593734 --- /dev/null +++ b/make-release.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +require_clean_work_tree() { + # Update the index + git update-index -q --ignore-submodules --refresh + err=0 + + # Disallow unstaged changes in the working tree + if ! git diff-files --quiet --ignore-submodules -- + then + echo >&2 "cannot $1: you have unstaged changes." + git diff-files --name-status -r --ignore-submodules -- >&2 + err=1 + fi + + # Disallow uncommitted changes in the index + if ! git diff-index --cached --quiet HEAD --ignore-submodules -- + then + echo >&2 "cannot $1: your index contains uncommitted changes." + git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2 + err=1 + fi + + if [ $err = 1 ] + then + echo >&2 "Please commit or stash them." + exit 1 + fi +} + + +if [[ ! $1 ]]; then + echo "usage: $0 versionName" + exit +fi + +require_clean_work_tree "$0" + +release_dir="release-$1" + +mkdir "$release_dir" + +./up-version.sh "$1" +./gen-changelog.sh > "$release_dir/CHANGELOG" + +./gradlew clean android:assembleRelease desktop:dist + +cp android/build/outputs/apk/release/*.apk "$release_dir/" +cp desktop/build/libs/*.jar "$release_dir/" + +echo "$release_dir/" diff --git a/up-version.sh b/up-version.sh new file mode 100755 index 0000000..ed84b4d --- /dev/null +++ b/up-version.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +git stash > /dev/null +stashed=$? + +new_version=$1 + +new_version_string=$(echo $new_version | sed 's/\(alpha\|beta\)\(.*\)/\1 \2/') + +sed -i 's/\(version\s=\s\)'"'"'.*'"'"'/\1'"'"''"$new_version"''"'"'/g' build.gradle +sed -i 's/\(versionName\s\)\".*\"/\1\"'"$new_version"'\"/g' android/build.gradle +sed -i 's/\(^\s*versionCode\s\)\([0-9]*\)/echo "\1$((\2+1))"/ge' android/build.gradle +sed -i 's/\(public static final String VERSION = \)\".*\"/\1\"'"$new_version_string"'\"/' core/src/ru/deadsoftware/cavedroid/CaveGame.java + +git add build.gradle android/build.gradle core/src/ru/deadsoftware/cavedroid/CaveGame.java + +git commit -m "Update version" +git tag "$new_version" + +if [ $stashed ]; then + git stash pop +fi -- 2.29.2