Files
Magisk/scripts/release.sh

107 lines
2.2 KiB
Bash
Raw Normal View History

2024-07-24 23:10:57 -07:00
#!/usr/bin/env bash
set -e
# On macOS, gsed is required (brew install gnu-sed)
2025-06-20 00:59:38 -07:00
# Required tools: gh
2024-07-24 23:10:57 -07:00
# The GitHub cli (gh) has to be properly authenticated
# These variables can be modified as needed
CONFIG=config.prop
NOTES=notes.md
# These are constants, do not modify
GCONFIG=app/gradle.properties
2024-07-24 23:10:57 -07:00
BUILDCMD="./build.py -c $CONFIG"
CWD=$(pwd)
grep_prop() {
local REGEX="s/^$1=//p"
shift
local FILES=$@
sed -n "$REGEX" $FILES | head -n 1
}
2025-06-05 11:00:27 -07:00
ensure_config() {
2024-07-24 23:10:57 -07:00
# Make sure version is not commented out and exists
sed -i "s:^# version=:version=:g" $CONFIG
if ! grep -qE '^version=' $CONFIG; then
echo 'version=' >> $CONFIG
fi
2024-08-03 01:55:03 -07:00
# Make sure abiList is not set when building for release
sed -i "s:^abiList=:# abiList=:g" $CONFIG
2024-07-24 23:10:57 -07:00
}
disable_version_config() {
# Comment out version config
sed -i "s:^version=:# version=:g" $CONFIG
}
2025-06-20 00:59:38 -07:00
# $1 = ver
2025-06-05 11:00:27 -07:00
set_version() {
2024-07-24 23:10:57 -07:00
local ver=$1
local code=$(echo - | awk "{ print $ver * 1000 }")
local tag="v$ver"
2025-06-05 11:00:27 -07:00
2024-07-24 23:10:57 -07:00
sed -i "s:versionCode=.*:versionCode=${code}:g" $GCONFIG
sed -i "s:version=.*:version=${ver}:g" $CONFIG
2025-06-05 11:00:27 -07:00
sed -i "1s:.*:## $(date +'%Y.%-m.%-d') Magisk v$ver:" $NOTES
2024-07-24 23:10:57 -07:00
# Commit version code changes
git add -u .
git status
2025-03-07 14:14:06 -08:00
git commit -m "Release Magisk v$ver" -m "[skip ci]"
2025-06-05 11:00:27 -07:00
}
# $1 = ver
build() {
2024-07-24 23:10:57 -07:00
[ -z $1 ] && exit 1
local ver=$1
git pull
2025-06-20 00:59:38 -07:00
set_version $ver
$BUILDCMD clean
$BUILDCMD all
$BUILDCMD -r all
2024-07-24 23:10:57 -07:00
}
2025-06-05 11:00:27 -07:00
upload() {
2024-07-24 23:10:57 -07:00
gh auth status
local code=$(grep_prop magisk.versionCode $GCONFIG)
local ver=$(echo - | awk "{ print $code / 1000 }")
local tag="v$ver"
local title="Magisk v$ver"
2024-07-24 23:10:57 -07:00
local out=$(grep_prop outdir $CONFIG)
2024-07-24 23:10:57 -07:00
if [ -z $out ]; then
out=out
fi
git tag $tag
2024-07-24 23:10:57 -07:00
git push origin master
git push --tags
2025-06-05 11:00:27 -07:00
# Prepare release notes
tail -n +3 $NOTES > release.md
# Publish release
local release_apk="Magisk-v${ver}.apk"
cp $out/app-release.apk $release_apk
gh release create --verify-tag $tag -p -t "$title" -F release.md $release_apk $out/app-debug.apk $NOTES
2024-07-24 23:10:57 -07:00
rm -f $release_apk release.md
2024-07-24 23:10:57 -07:00
}
# Use GNU sed on macOS
if command -v gsed >/dev/null; then
function sed() { gsed "$@"; }
export -f sed
fi
2024-07-25 03:04:24 -07:00
trap disable_version_config EXIT
2025-06-05 11:00:27 -07:00
ensure_config
2024-07-24 23:10:57 -07:00
case $1 in
build ) build $2 ;;
upload ) upload ;;
2024-07-24 23:10:57 -07:00
* ) exit 1 ;;
esac