2
0
mirror of https://github.com/topjohnwu/Magisk synced 2025-08-23 09:49:24 +00:00
magisk/scripts/release.sh

284 lines
6.0 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)
# Required tools: jq, gh
# The GitHub cli (gh) has to be properly authenticated
# These variables can be modified as needed
MAGISK_FILES=../magisk-files
CONFIG=config.prop
NOTES=notes.md
# These are constants, do not modify
GCONFIG=app/gradle.properties
2024-07-24 23:10:57 -07:00
README=README.MD
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
}
# $1 = tag
2025-06-05 11:00:27 -07:00
update_readme_canary() {
sed -i "s:badge/Magisk-Canary.*:badge/Magisk-Canary-red)](https\://github.com/topjohnwu/Magisk/releases/tag/$1):g" $README
2024-07-24 23:10:57 -07:00
}
# $1 = tag
update_readme_beta() {
2025-06-05 11:00:27 -07:00
update_readme_canary $1
2024-07-24 23:10:57 -07:00
sed -i "s:badge/Magisk%20Beta.*:badge/Magisk%20Beta-${1}-blue)](https\://github.com/topjohnwu/Magisk/releases/tag/$1):g" $README
}
# $1 = tag
2025-06-05 11:00:27 -07:00
update_readme_stable() {
update_readme_beta $1
sed -i "s:badge/Magisk-v.*:badge/Magisk-${1}-blue)](https\://github.com/topjohnwu/Magisk/releases/tag/$1):g" $README
2024-07-24 23:10:57 -07:00
}
2025-06-05 11:00:27 -07:00
# $1 = tag
# $2 = file name
2024-07-24 23:10:57 -07:00
gen_link() {
echo "https://github.com/topjohnwu/Magisk/releases/download/$1/$2"
}
2025-06-05 11:00:27 -07:00
# $1 = version code
is_canary() {
[ $(($1 % 100)) -ne 0 ]
}
# $1 = json path
# $2 = apk name
update_json() {
local json=$1
local apk=$2
2024-07-24 23:10:57 -07:00
local ver=$(grep_prop version $CONFIG)
local code=$(grep_prop magisk.versionCode $GCONFIG)
2025-06-05 11:00:27 -07:00
local tag
if is_canary $code; then
tag="canary-$code"
else
tag="v$ver"
fi
2024-07-24 23:10:57 -07:00
jq ".magisk.version=\"$ver\"|.magisk.versionCode=\"$code\"|
2025-06-05 11:00:27 -07:00
.magisk.link=\"$(gen_link $tag $apk)\"|
2024-07-24 23:10:57 -07:00
.magisk.note=\"$(gen_link $tag notes.md)\"" $json > ${json}.tmp
mv ${json}.tmp $json
}
2025-06-05 11:00:27 -07:00
update_canary_json() {
update_json $MAGISK_FILES/canary.json app-release.apk
update_json $MAGISK_FILES/debug.json app-debug.apk
}
2024-07-24 23:10:57 -07:00
2025-06-05 11:00:27 -07:00
update_beta_json() {
update_json $MAGISK_FILES/canary.json Magisk-v${ver}.apk
update_json $MAGISK_FILES/debug.json app-debug.apk
cp -vf $MAGISK_FILES/canary.json $MAGISK_FILES/beta.json
2024-07-24 23:10:57 -07:00
}
2025-06-05 11:00:27 -07:00
update_stable_json() {
update_beta_json
cp -vf $MAGISK_FILES/beta.json $MAGISK_FILES/stable.json
}
bump_canary_version() {
2024-07-24 23:10:57 -07:00
# Update version code
local code=$(grep_prop magisk.versionCode $GCONFIG)
code=$((code + 1))
local tag="canary-$code"
sed -i "s:versionCode=.*:versionCode=${code}:g" $GCONFIG
update_readme_canary $tag
# Commit version code changes
git add -u .
git status
2025-03-07 14:14:06 -08:00
git commit -m "Release new canary build" -m "[skip ci]"
2024-07-24 23:10:57 -07:00
git tag $tag
# Update version name
local ver=$(git rev-parse --short=8 HEAD)
sed -i "s:version=.*:version=${ver}:g" $CONFIG
2025-06-05 11:00:27 -07:00
sed -i "1s:.*:## Magisk (${ver}) (${code}):" $NOTES
2024-07-24 23:10:57 -07:00
update_canary_json
2025-06-05 11:00:27 -07:00
# Commit json files
2024-07-24 23:10:57 -07:00
cd $MAGISK_FILES
git add -u .
git status
git commit -m "Update Canary Channel: Upstream to $ver"
cd $CWD
}
# $1 = ver, $2 = stable?
2025-06-05 11:00:27 -07:00
set_version() {
2024-07-24 23:10:57 -07:00
local ver=$1
local stable=$2
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
if $stable; then
update_readme_stable $tag
2025-06-05 11:00:27 -07:00
update_stable_json
2024-07-24 23:10:57 -07:00
else
update_readme_beta $tag
2025-06-05 11:00:27 -07:00
update_beta_json
2024-07-24 23:10:57 -07:00
fi
# 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]"
2024-07-24 23:10:57 -07:00
git tag $tag
2025-06-05 11:00:27 -07:00
# Commit json files
cd $MAGISK_FILES
git add -u .
git status
git commit -m "Release Magisk v$ver"
cd $CWD
}
build_apk() {
2024-07-24 23:10:57 -07:00
$BUILDCMD clean
2025-06-05 11:00:27 -07:00
$BUILDCMD all
2024-07-24 23:10:57 -07:00
$BUILDCMD -r all
}
2025-06-05 11:00:27 -07:00
build_canary() {
bump_canary_version
build_apk
}
# $1 = ver
build_beta() {
2024-07-24 23:10:57 -07:00
[ -z $1 ] && exit 1
local ver=$1
2025-06-05 11:00:27 -07:00
set_version $ver false
build_apk
2024-07-24 23:10:57 -07:00
}
2025-06-05 11:00:27 -07:00
# $1 = ver
build_stable() {
2024-07-24 23:10:57 -07:00
[ -z $1 ] && exit 1
local ver=$1
2025-06-05 11:00:27 -07:00
set_version $ver true
build_apk
2024-07-24 23:10:57 -07:00
}
2025-06-05 11:00:27 -07:00
upload() {
# Verify pattern
[[ "$1" =~ canary|beta|stable ]]
local type=$1
2024-07-24 23:10:57 -07:00
gh auth status
local latest_tag=$(git describe --abbrev=0 --tags)
local ver=$(grep_prop version $CONFIG)
local code=$(grep_prop magisk.versionCode $GCONFIG)
local out=$(grep_prop outdir $CONFIG)
local tag title
if [ -z $out ]; then
out=out
fi
git push origin master
git push --tags
2025-06-05 11:00:27 -07:00
# Prepare release notes
tail -n +3 $NOTES > release.md
case $type in
"canary" )
tag="canary-$code"
title="Magisk ($ver) ($code)"
# Assert tag format
[ $latest_tag = $tag ]
# Publish release
gh release create --verify-tag $tag -p -t "$title" -F release.md $out/app-release.apk $out/app-debug.apk $NOTES
;;
"beta|stable" )
tag="v$ver"
title="Magisk v$ver"
# Assert tag format
[ $latest_tag = $tag ]
# 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
rm -f $release_apk
;;
esac
# If publishing stable, make it not prerelease and explicitly latest
if [ $type = "stable" ]; then
gh release edit $tag --prerelease=false --latest
2024-07-24 23:10:57 -07:00
fi
rm -f release.md
2025-06-05 11:00:27 -07:00
# Finally upload jsons
2024-07-24 23:10:57 -07:00
cd $MAGISK_FILES
git push origin master
cd $CWD
}
revert() {
local latest_tag=$(git describe --abbrev=0 --tags)
git tag -d $latest_tag
git reset --hard HEAD~
cd $MAGISK_FILES
git reset --hard HEAD~
cd $CWD
}
# Use GNU sed on macOS
if command -v gsed >/dev/null; then
function sed() { gsed "$@"; }
export -f sed
fi
git pull
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
"canary" ) build_canary ;;
2025-06-05 11:00:27 -07:00
"beta" ) build_beta $2 ;;
"stable" ) build_stable $2 ;;
"upload" ) upload $2 ;;
2024-07-24 23:10:57 -07:00
"revert" ) revert ;;
* ) exit 1 ;;
esac