Skip to content

Commit

Permalink
BraveNewPipe: refactor the data.json creation script to work with sev…
Browse files Browse the repository at this point in the history
…eral branches

As for now we use separated release data.json.
One for brave and braveConscrypt flavor and one for braveKitkat
  • Loading branch information
evermind-zz committed Mar 10, 2024
1 parent 8372a69 commit c79feb7
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions .github/scripts/brave-new-pipe-releast-actions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# this script updates the json file with new version that BraveNewPipe is fetching regulary

set -e

Expand All @@ -19,7 +20,6 @@ APK_FILE=$2
BNP_R_MGR_REPO="bnp-r-mgr"
GITHUB_LOGIN="bravenewpipe"
RELEASE_BODY="Apk available at bravenewpipe/NewPipe@${TAG}](https://github.com/bravenewpipe/NewPipe/releases/tag/${TAG})."
GIT_BRANCH="master"

PRERELEASE="false"
if [[ "$TAG" == "latest" ]]; then
Expand All @@ -32,16 +32,17 @@ if [[ "$GITHUB_REPOSITORY" != "bravenewpipe/NewPipe" ]]; then
fi

create_tagged_release() {
REPO=$1
COMMIT_MSG=$2
pushd /tmp/${REPO}/
local L_REPO=$1
local L_BRANCH=$2
local L_COMMIT_MSG=$3
pushd /tmp/${L_REPO}/

# Set the local git identity
git config user.email "${GITHUB_LOGIN}@users.noreply.github.com"
git config user.name "$GITHUB_LOGIN"

# Obtain the release ID for the previous release of $TAG (if present)
local previous_release_id=$(curl --user ${GITHUB_LOGIN}:${GITHUB_SUPER_TOKEN} --request GET --silent https://api.github.com/repos/${GITHUB_LOGIN}/${REPO}/releases/tags/${TAG} | jq '.id')
local previous_release_id=$(curl --user ${GITHUB_LOGIN}:${GITHUB_SUPER_TOKEN} --request GET --silent https://api.github.com/repos/${GITHUB_LOGIN}/${L_REPO}/releases/tags/${TAG} | jq '.id')

# Delete the previous release (if present)
if [[ -n "$previous_release_id" ]]; then
Expand All @@ -50,7 +51,7 @@ create_tagged_release() {
--user ${GITHUB_LOGIN}:${GITHUB_SUPER_TOKEN} \
--request DELETE \
--silent \
https://api.github.com/repos/${GITHUB_LOGIN}/${REPO}/releases/${previous_release_id}
https://api.github.com/repos/${GITHUB_LOGIN}/${L_REPO}/releases/${previous_release_id}
fi

# Delete previous identical tags, if present
Expand All @@ -59,8 +60,8 @@ create_tagged_release() {

# Add all the changed files and push the changes upstream
git add -f .
git commit -m "${COMMIT_MSG}" || true
git push -f origin ${GIT_BRANCH}:${GIT_BRANCH}
git commit -m "${L_COMMIT_MSG}" || true
git push -f origin ${L_BRANCH}:${L_BRANCH}
git tag $TAG
git push origin $TAG

Expand All @@ -70,7 +71,7 @@ create_tagged_release() {
# 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 @- \
# evermind -- we don't want any release entries there https://api.github.com/repos/${GITHUB_LOGIN}/${REPO}/releases <<END
# evermind -- we don't want any release entries there https://api.github.com/repos/${GITHUB_LOGIN}/${L_REPO}/releases <<END
# 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",
Expand All @@ -82,27 +83,42 @@ create_tagged_release() {
popd
}

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://bravenewpipe:${GITHUB_SUPER_TOKEN}@github.com/bravenewpipe/${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\""
}

BUILD_TOOLS_VERSION="${BUILD_TOOLS_VERSION:-29.0.3}"
AAPT=$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/aapt

URL="https://github.com/bravenewpipe/NewPipe/releases/download/${TAG}/BraveNewPipe_${TAG}.apk"
URL_CONSCRYPT="https://github.com/bravenewpipe/NewPipe/releases/download/${TAG}/BraveNewPipe_conscrypt_${TAG}.apk"
URL_KITKAT="https://github.com/bravenewpipe/NewPipe/releases/download/${TAG}/BraveNewPipe_kitkat${TAG}.apk"
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

# checkout json release file repo
rm -rf "/tmp/${BNP_R_MGR_REPO}"
git clone --branch "${GIT_BRANCH}" "https://bravenewpipe:${GITHUB_SUPER_TOKEN}@github.com/bravenewpipe/${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 = "'${URL}'"' \
| jq '( .flavors.github.stable.alternative_apks[] | select(.alternative == "conscrypt") ).url |= "'${URL_CONSCRYPT}'"' \
> $TEMPFILE
mv $TEMPFILE $JSON_FILE

create_tagged_release "$BNP_R_MGR_REPO" "\"version\": \"$VERSION_NAME\""
# We have two different json files for now:
# The first is used within the flavors brave and braveConscrypt
# and the second is used in braveKitkat. 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_KITKAT" "$URL_KITKAT"
create_json_file_and_create_tagged_release "master" "$URL" "$URL_CONSCRYPT"

0 comments on commit c79feb7

Please sign in to comment.