2022-02-28 00:09:47 +01:00
|
|
|
#!/usr/bin/env bash
|
2024-03-10 09:13:04 +01:00
|
|
|
# this script updates the json file with new version that BraveNewPipe is fetching regulary
|
2022-02-28 00:09:47 +01:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ $# -ne 2 ]]; then
|
|
|
|
echo "This needs a release tag and a apk file:"
|
|
|
|
echo "e.g. $0 v0.22.0-1.0.5 /path/to/BraveNewPipe_v0.22.0-1.0.5.apk"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$GITHUB_SUPER_TOKEN" ]]; then
|
|
|
|
echo "This script needs a GitHub personal access token."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
TAG=$1
|
|
|
|
APK_FILE=$2
|
|
|
|
|
|
|
|
BNP_R_MGR_REPO="bnp-r-mgr"
|
2024-03-10 09:13:04 +01:00
|
|
|
|
|
|
|
GITHUB_USER="bravenewpipe"
|
|
|
|
RELEASE_REPO="NewPipe"
|
|
|
|
RELEASE_BODY="Apk available at ${GITHUB_USER}/${RELEASE_REPO}@${TAG}](https://github.com/${GITHUB_USER}/${RELEASE_REPO}/releases/tag/${TAG})."
|
2022-02-28 00:09:47 +01:00
|
|
|
|
|
|
|
PRERELEASE="false"
|
|
|
|
if [[ "$TAG" == "latest" ]]; then
|
|
|
|
PRERELEASE="true"
|
|
|
|
fi
|
|
|
|
|
2024-03-10 09:13:04 +01:00
|
|
|
if [[ "$GITHUB_REPOSITORY" != "${GITHUB_USER}/${RELEASE_REPO}" ]]; then
|
|
|
|
echo "This mirror script is only meant to be run from ${GITHUB_USER}/${RELEASE_REPO}, not ${GITHUB_REPOSITORY}. Nothing to do here."
|
2022-02-28 00:09:47 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
create_tagged_release() {
|
2024-03-10 09:13:04 +01:00
|
|
|
local L_REPO=$1
|
|
|
|
local L_BRANCH=$2
|
|
|
|
local L_COMMIT_MSG=$3
|
|
|
|
pushd /tmp/${L_REPO}/
|
2022-02-28 00:09:47 +01:00
|
|
|
|
|
|
|
# Set the local git identity
|
2024-03-10 09:13:04 +01:00
|
|
|
git config user.email "${GITHUB_USER}@users.noreply.github.com"
|
|
|
|
git config user.name "$GITHUB_USER"
|
2022-02-28 00:09:47 +01:00
|
|
|
|
|
|
|
# Obtain the release ID for the previous release of $TAG (if present)
|
2024-03-10 09:13:04 +01:00
|
|
|
local previous_release_id=$(curl --user ${GITHUB_USER}:${GITHUB_SUPER_TOKEN} --request GET --silent https://api.github.com/repos/${GITHUB_USER}/${L_REPO}/releases/tags/${TAG} | jq '.id')
|
2022-02-28 00:09:47 +01:00
|
|
|
|
|
|
|
# Delete the previous release (if present)
|
|
|
|
if [[ -n "$previous_release_id" ]]; then
|
|
|
|
echo "Deleting previous release: ${previous_release_id}"
|
|
|
|
curl \
|
2024-03-10 09:13:04 +01:00
|
|
|
--user ${GITHUB_USER}:${GITHUB_SUPER_TOKEN} \
|
2022-02-28 00:09:47 +01:00
|
|
|
--request DELETE \
|
|
|
|
--silent \
|
2024-03-10 09:13:04 +01:00
|
|
|
https://api.github.com/repos/${GITHUB_USER}/${L_REPO}/releases/${previous_release_id}
|
2022-02-28 00:09:47 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete previous identical tags, if present
|
|
|
|
git tag -d $TAG || true
|
|
|
|
git push origin :$TAG || true
|
|
|
|
|
|
|
|
# Add all the changed files and push the changes upstream
|
|
|
|
git add -f .
|
2024-03-10 09:13:04 +01:00
|
|
|
git commit -m "${L_COMMIT_MSG}" || true
|
|
|
|
git push -f origin ${L_BRANCH}:${L_BRANCH}
|
2022-02-28 00:09:47 +01:00
|
|
|
git tag $TAG
|
|
|
|
git push origin $TAG
|
|
|
|
|
|
|
|
# evermind -- we don't want any release entries there # Generate a skeleton release on GitHub
|
|
|
|
# evermind -- we don't want any release entries there curl \
|
2024-03-10 09:13:04 +01:00
|
|
|
# evermind -- we don't want any release entries there --user ${GITHUB_USER}:${GITHUB_SUPER_TOKEN} \
|
2022-02-28 00:09:47 +01:00
|
|
|
# evermind -- we don't want any release entries there --request POST \
|
|
|
|
# evermind -- we don't want any release entries there --silent \
|
|
|
|
# evermind -- we don't want any release entries there --data @- \
|
2024-03-10 09:13:04 +01:00
|
|
|
# evermind -- we don't want any release entries there https://api.github.com/repos/${GITHUB_USER}/${L_REPO}/releases <<END
|
2022-02-28 00:09:47 +01:00
|
|
|
# evermind -- we don't want any release entries there {
|
|
|
|
# evermind -- we don't want any release entries there "tag_name": "$TAG",
|
|
|
|
# evermind -- we don't want any release entries there "name": "Auto-generated release for tag $TAG",
|
|
|
|
# evermind -- we don't want any release entries there "body": "$RELEASE_BODY",
|
|
|
|
# evermind -- we don't want any release entries there "draft": false,
|
|
|
|
# evermind -- we don't want any release entries there "prerelease": $PRERELEASE
|
|
|
|
# evermind -- we don't want any release entries there }
|
|
|
|
# evermind -- we don't want any release entries thereEND
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
2024-03-10 09:13:04 +01:00
|
|
|
create_json_file_and_create_tagged_release() {
|
|
|
|
local L_BRANCH="$1"
|
|
|
|
local L_URL_STABLE="$2"
|
|
|
|
local L_URL_ALTERNATIVE="$3"
|
|
|
|
# checkout json release file repo
|
|
|
|
rm -rf "/tmp/${BNP_R_MGR_REPO}"
|
|
|
|
git clone --branch "${L_BRANCH}" "https://${GITHUB_USER}:${GITHUB_SUPER_TOKEN}@github.com/${GITHUB_USER}/${BNP_R_MGR_REPO}.git" /tmp/${BNP_R_MGR_REPO}
|
|
|
|
# update version{code,name} and download url
|
|
|
|
cat $JSON_FILE \
|
|
|
|
| jq '.flavors.github.stable.version_code = '${VERSION_CODE}'' \
|
|
|
|
| jq '.flavors.github.stable.version = "'${VERSION_NAME}'"' \
|
|
|
|
| jq '.flavors.github.stable.apk = "'${L_URL_STABLE}'"' \
|
|
|
|
| jq '( .flavors.github.stable.alternative_apks[] | select(.alternative == "conscrypt") ).url |= "'${L_URL_ALTERNATIVE}'"' \
|
|
|
|
> $TEMPFILE
|
|
|
|
mv $TEMPFILE $JSON_FILE
|
|
|
|
|
|
|
|
create_tagged_release "$BNP_R_MGR_REPO" "$L_BRANCH" "\"version\": \"$VERSION_NAME\""
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_build_tools_version() {
|
|
|
|
ls /usr/local/lib/android/sdk/build-tools/ | tail -n 1
|
|
|
|
}
|
|
|
|
|
|
|
|
BUILD_TOOLS_VERSION="${BUILD_TOOLS_VERSION:-$(detect_build_tools_version)}"
|
|
|
|
|
2022-02-28 00:09:47 +01:00
|
|
|
AAPT=$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/aapt
|
|
|
|
|
2024-03-10 09:13:04 +01:00
|
|
|
URL_PREFIX="https://github.com/${GITHUB_USER}/${RELEASE_REPO}/releases/download/${TAG}"
|
|
|
|
URL="$URL_PREFIX/BraveNewPipe_${TAG}.apk"
|
|
|
|
URL_CONSCRYPT="$URL_PREFIX/BraveNewPipe_conscrypt_${TAG}.apk"
|
|
|
|
URL_LEGACY="$URL_PREFIX/BraveNewPipe_legacy_${TAG}.apk"
|
2022-02-28 00:09:47 +01:00
|
|
|
VERSION_NAME=${TAG/v/}
|
|
|
|
VERSION_CODE="$($AAPT d badging $APK_FILE | grep -Po "(?<=\sversionCode=')([0-9.-]+)")"
|
|
|
|
|
|
|
|
TEMPFILE="$(mktemp -p /tmp -t sdflhXXXXXXXXX)"
|
|
|
|
JSON_FILE=/tmp/${BNP_R_MGR_REPO}/api/data.json
|
|
|
|
|
2024-03-10 09:13:04 +01:00
|
|
|
# We have two different json files for now:
|
|
|
|
# The first is used within the flavors brave and braveConscrypt
|
|
|
|
# and the second is used in braveLegacy. The json files
|
|
|
|
# are stored in the same repo but in different branches.
|
|
|
|
# We call kitkat stuff first as each call tags and delete same exising
|
|
|
|
# tags before and we want the master branch to have the actual tag.
|
|
|
|
create_json_file_and_create_tagged_release "kitkat" "$URL_LEGACY" "$URL_LEGACY"
|
|
|
|
create_json_file_and_create_tagged_release "master" "$URL" "$URL_CONSCRYPT"
|