diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dea6af3..63ed335 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,6 +6,21 @@ on: description: 'Deploy Type (TEST/BETA/OFFICIAL)' required: true default: 'TEST' + Vendor: + description: 'Enter Device OEM Name' + required: true + CodeName: + description: 'Enter Device Code Name' + required: true + Branch: + description: 'Enter bootable/recovery Branch' + required: true + Link: + description: 'Enter Direct Download Link' + required: true + DtLink: + description: 'Enter Device Tree Link (From PBRP Org)' + required: true ChangeLogs: description: 'Build ChangeLogs' required: true @@ -13,6 +28,11 @@ on: env: BUILD_RELEASE_TYPE: ${{ github.event.inputs.DEPLOY_TYPE }} + VENDOR: ${{ github.event.inputs.Vendor }} + CODENAME: ${{ github.event.inputs.CodeName }} + BRANCH: ${{ github.event.inputs.Branch }} + LINK: ${{ github.event.inputs.Link }} + DTLINK: ${{ github.event.inputs.DtLink }} CHANGELOG: ${{ github.event.inputs.ChangeLogs }} BOT_API: ${{ secrets.BOT_API }} GCF_AUTH_KEY: ${{ secrets.GCF_AUTH_KEY }} @@ -21,8 +41,6 @@ env: GitHubName: ${{ secrets.GitHubName }} SFPassword: ${{ secrets.SFPassword }} SFUserName: ${{ secrets.SFUserName }} - TARGET: "pbrp" - #EXTRA_CMD: "Extra Commands Here" jobs: PBRP_CI: @@ -30,38 +48,34 @@ jobs: runs-on: ubuntu-20.04 steps: - - name: Auto Adapt Manifest - # /* if your branch name is other than the one which you dispatched workflow from then set it manually in the place of ${GITHUB_REF##*/}" */ - run: echo "MANIFEST=https://github.com/PitchBlackRecoveryProject/manifest_pb -b ${GITHUB_REF##*/}" >> $GITHUB_ENV - - name: Export Vars run: | if [[ ${BUILD_RELEASE_TYPE} == "TEST" ]]; then echo "TEST_BUILD=true" >> $GITHUB_ENV;fi if [[ ${BUILD_RELEASE_TYPE} == "BETA" ]]; then echo "BETA_BUILD=true" >> $GITHUB_ENV;fi if [[ ${BUILD_RELEASE_TYPE} == "OFFICIAL" ]]; then echo "PB_OFFICIAL=true" >> $GITHUB_ENV;fi + echo "WorkPath=/home/runner/workspace" >> ${GITHUB_ENV} + echo "DLPATH=/home/runner/workspace/out/target/product/$CODENAME" >> ${GITHUB_ENV} + + - name: Download Build + run: | + mkdir -p $WorkPath && cd $WorkPath + git clone https://github.com/PitchBlackRecoveryProject/android_bootable_recovery -b $BRANCH --single-branch bootable/recovery + git clone https://github.com/PitchBlackRecoveryProject/DeployBuild DeployBuild + git clone https://github.com/PitchBlackRecoveryProject/vendor_utils vendor/utils + git clone $DTLINK device/$VENDOR/$CODENAME + mkdir -p $DLPATH && cd $DLPATH + wget $LINK + unzip -j *.zip *.img - - name: Checkout Cleaning Up Runner Repo - uses: actions/checkout@v2 - with: - repository: PitchBlackRecoveryProject/Cleaner - ref: main - token: ${{ secrets.GH_BOT_TOKEN }} - path: .github/actions/Cleaner - - name: Cleaning - uses: ./.github/actions/Cleaner + - name: Installing GHR + run: | + cd /home/runner + curl -s https://api.github.com/repos/tcnksm/ghr/releases/latest | jq -r '.assets[] | select(.browser_download_url | contains("linux_amd64")) | .browser_download_url' | wget -qi - + tar -xzf ghr_*_amd64.tar.gz --wildcards 'ghr*/ghr' --strip-components 1 && rm -rf ghr_*_amd64.tar.gz + chmod a+x ./ghr && sudo mv ./ghr /usr/local/bin/ - - name: Checkout Recovery Compiler Repo - uses: actions/checkout@v2 - with: - repository: PitchBlackRecoveryProject/Compiler - ref: production - token: ${{ secrets.GH_BOT_TOKEN }} - path: .github/actions/Compiler - - name: Recovery Compilation - uses: ./.github/actions/Compiler - - - name: Release Builds + - name: Release Build run: | sudo apt-get update && sudo apt-get install sshpass -y - cd $BuildPath - bash vendor/utils/pb_deploy.sh ${BUILD_RELEASE_TYPE} ${VENDOR} ${CODENAME} + cd $WorkPath + bash DeployBuild/pb_deploy.sh ${BUILD_RELEASE_TYPE} ${VENDOR} ${CODENAME} diff --git a/pb_deploy.sh b/pb_deploy.sh new file mode 100644 index 0000000..d65a3d6 --- /dev/null +++ b/pb_deploy.sh @@ -0,0 +1,339 @@ +#!/bin/bash +# +# Custom Deploy Script for PBRP +# +# Copyright (C) 2019 - 2020, Manjot Sidhu +# Rokib Hasan Sagar +# Mohd Faraz +# PitchBlack Recovery Project +# +# This software is licensed under the terms of the GNU General Public +# License version 2, as published by the Free Software Foundation, and +# may be copied, distributed, and modified under those terms. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Please maintain this if you use this script or any part of it +# +# Required Arguments: BUILD_TYPE(OFFICIAL/BETA/TEST) VENDOE/OEM(such as xiaomi) CODENAME(such as rolex) + +test $# -lt 3 && echo -e "Give Proper arguments\nRequired Arguments: BUILD_TYPE(OFFICIAL/BETA/TEST) VENDOE/OEM(such as xiaomi) CODENAME(such as rolex)" && exit 1; +DEPLOY_TYPE=$1 +VENDOR=$2 +CODENAME=$3 +blue='\033[0;34m' +cyan='\033[0;36m' +green='\e[0;32m' +yellow='\033[0;33m' +red='\033[0;31m' +nocol='\033[0m' +purple='\e[0;35m' +white='\e[0;37m' +if [ ! -d "$(pwd)/out/target/product/${CODENAME}/" ]; then + echo -e "${red}Plz Run in the Root of the compilation enviromnent\n${nocol}" + exit 1; +fi +curl https://raw.githubusercontent.com/PitchBlackRecoveryProject/vendor_utils/pb/pb_devices.json > /tmp/pb_devices.json +maintainer=$(python3 vendor/utils/pb_devices.py verify $VENDOR $CODENAME true) + +# GitHub Username & Repository Name +GH_USER=PitchBlackRecoveryProject +GH_REPO=android_device_${VENDOR}_${CODENAME}-pbrp +GH_SHA=$(cd $(pwd)/device/${VENDOR}/${CODENAME} && git rev-list --branches | head -1) + +if [ -z ${GH_BOT_TOKEN} ] || [ -z ${BOT_API} ]; then + echo "Make sure all ENV variables (GH_BOT_TOKEN/BOT_API) are available" + exit -1; +fi + +UPLOAD_PATH=$(pwd)/out/target/product/${CODENAME}/upload/ + +# Version +TWRP_V=$(cat $(pwd)/bootable/recovery/variables.h | egrep "define\s+TW_MAIN_VERSION_STR" | awk '{print $3}' | tr -d '"') +VERSION=$(cat $(pwd)/bootable/recovery/variables.h | egrep "define\s+PB_MAIN_VERSION" | awk '{print $3}' | tr -d '"') + +pb_sticker="https://thumbs.gfycat.com/NauticalMellowAlpineroadguidetigerbeetle-mobile.mp4" + +# Validate and Prepare for deploy +if [[ "$DEPLOY_TYPE" == "OFFICIAL" ]]; then + # Official Deploy = SF + GHR + WP + TG (Main Channel) + + DEPLOY_TYPE_NAME="Official" + RELEASE_TAG=${VERSION} + BUILDFILE=$(find $(pwd)/out/target/product/${CODENAME}/PBRP*-OFFICIAL.zip 2>/dev/null) + +elif [[ "$DEPLOY_TYPE" == "BETA" ]]; then + # Beta Deploy = SF + GHR + WP + TG (Beta Group) + + DEPLOY_TYPE_NAME="Beta" + RELEASE_TAG=${VERSION}-beta + BUILDFILE=$(find $(pwd)/out/target/product/${CODENAME}/PBRP*-BETA.zip 2>/dev/null) + +elif [[ "$DEPLOY_TYPE" == "TEST" ]]; then + # Test Deploy = GHR + TG (Device Maintainers Chat) + + DEPLOY_TYPE_NAME="Test" + RELEASE_TAG=${VERSION}-test + BUILDFILE=$(find $(pwd)/out/target/product/${CODENAME}/PBRP*-UNOFFICIAL.zip 2>/dev/null) + +else + echo -e "Wrong Build Type Given, Required Build Type: OFFICIAL/BETA/TEST" && exit 1 +fi + +function get_device_name () { + local DEVICE=$(cat /tmp/pb_devices.json | grep $1 -A 3 | grep name | awk -F[\"] '{print $4}') + echo "$DEVICE" +} + +function get_vendor () { + echo "$(echo ${1} | cut -d' ' -f1)" +} +# Common Props +BUILD_IMG=$(find $(pwd)/out/target/product/${CODENAME}/recovery.img 2>/dev/null) +MD5=$(md5sum $BUILDFILE | awk '{print $1}') +FILE_SIZE=$( du -h $BUILDFILE | awk '{print $1}' ) +BUILD_DATE=$(echo "$BUILDFILE" | awk -F'[-]' '{print $4}') +BUILD_DATETIME="$(echo "$BUILDFILE" | awk -F'[-]' '{print $4}')-$(echo "$BUILDFILE" | awk -F'[-]' '{print $5}')" +TARGET_DEVICE=$(cat /tmp/pb_devices.json | grep ${CODENAME} -A 3 | grep name | awk -F[\"] '{print $4}') +BUILD_NAME=$(echo ${BUILDFILE} | awk -F['/'] '{print $NF}') +DEVICES=$(cat /tmp/pb_devices.json | grep ${CODENAME} -A 3 | grep unified | awk -F[\"] '{ for (i=4; iChangelog:\n"${CHANGELOG}"\n" +fi +FORMAT=${FORMAT}"\nMD5: $MD5\n" +BUTTONS= +#Special format for unifieds +if [ ! -z "$DEVICES" ]; then + UNIFORMAT="PitchBlack Recovery for $(get_vendor $(get_device_name $(echo $DEVICES | cut -d' ' -f1)))" + TAGS= + for i in $DEVICES; do + TARGET_DEVICE=$(cat /tmp/pb_devices.json | grep -i ${i} -A 1 | grep name | awk -F[\"] '{print $4}' | cut -d' ' -f2-) + UNIFORMAT="${UNIFORMAT} $TARGET_DEVICE /" + TAGS="${TAGS}#${i} " + wp_link="https://pitchblackrecovery.com/$(echo $i | sed "s:_:-:g")" + BUTTONS="${BUTTONS}$i|$wp_link!" + done + UNIFORMAT="${UNIFORMAT:0:-1} (${CODENAME})\n\nInfo\n\nPitchBlack V${VERSION} ${DEPLOY_TYPE_NAME}\nBased on TWRP ${TWRP_V}\nBuild Date: ${BUILD_DATE:0:4}/${BUILD_DATE:4:2}/${BUILD_DATE:6}\n\nMaintainer: ${maintainer}\n" + if [[ ! -z $CHANGELOG ]]; then + UNIFORMAT=${UNIFORMAT}"\nChangelog:\n"${CHANGELOG}"\n" + fi + UNIFORMAT=${UNIFORMAT}"\nMD5: $MD5\n\n${TAGS}\n" + FORMAT=$UNIFORMAT +fi + +# Deploy on SourceForge +function sf_deploy() { + echo -e "${green}Deploying on SourceForge!\n${nocol}" + + # Install sshpass if not installed + chksspb=$(which sshpass 2>/dev/null) + if [[ "$chksspb" != "/usr/bin/sshpass" ]]; then + echo + printf "Sshpass is required but not installed!\n\nInstalling sspass...\n" + echo + ID_LIKE="$(cut -d'=' -f2 <<<$(grep ID_LIKE= /etc/os-release))" + echo + if [ "$ID_LIKE" == "arch" ]; then + sudo pacman -S sshpass --noconfirm + elif [ "$ID_LIKE" = "debian" ]; then + sudo apt-get install sshpass -y + fi + else true; + fi + + echo + + # SF Details + echo + echo "Build detected for :" $CODENAME + echo "PitchBlack version :" $pbv + echo "Build Date :" $BUILD_DATE + echo "Build Location :" $BUILDFILE + echo "MD5 :" $MD5 + echo + + if [ -z $SFUserName ]; then + echo -e "${green}Enter SF Username${nocol}" + read SFUserName + fi + if [ -z $SFPassword ]; then + echo -e "${green}Enter SF Password${nocol}" + read -s SFPassword + fi + cd $(pwd)/vendor/utils; + + # Check for Official + python3 pb_devices.py verify "$VENDOR" "$CODENAME" + if [[ "$?" == "0" ]]; then + sshpass -p "${SFPassword}" rsync -avP --progress -e 'ssh -o StrictHostKeyChecking=no' ${BUILDFILE} "${SFUserName}"@web.sourceforge.net:/home/frs/project/pbrp/${CODENAME}/${BUILD_NAME} + if [ "$?" != "0" ]; then + sshpass -p "${SFPassword}" sftp ${SFUserName}@web.sourceforge.net <<-EOF + cd /home/frs/project/pbrp/ + mkdir ${CODENAME} + exit + EOF + sshpass -p "${SFPassword}" rsync -avP --progress -e 'ssh -o StrictHostKeyChecking=no' ${BUILDFILE} "${SFUserName}"@web.sourceforge.net:/home/frs/project/pbrp/${CODENAME}/${BUILD_NAME} + fi + if [ "$?" == "0" ] + then + echo -e "${green} Deployed On SOURCEFORGE SUCCESSFULLY\n${nocol}" + cd ../../ + return 0 + else + echo -e "${red} FAILED TO UPLOAD TO SOURCEFORGE\n${nocol}" + cd ../../ + return 1 + fi + else + echo -e "${red} Device is not Official\n${nocol}" + cd ../../ + return 2 + fi +} + +# Deploy on GitHub Releases +function gh_deploy() { + + # Prepare Upload directory for Github Releases + mkdir ${UPLOAD_PATH} + + # Copy Required Files + if [[ ! -z ${BUILDFILE} ]]; then + cp $BUILDFILE $UPLOAD_PATH + fi + cp $BUILD_IMG $UPLOAD_PATH + + # If Samsung's Odin TAR available, copy it to our upload dir + BUILD_FILE_TAR=$(find $(pwd)/out/target/product/${CODENAME}/*.tar 2>/dev/null) + if [[ ! -z ${BUILD_FILE_TAR} ]]; then + echo "Samsung's Odin Tar available: $BUILD_FILE_TAR" + cp ${BUILD_FILE_TAR} ${UPLOAD_PATH} + fi + + # Final Release + ghr -t ${GH_BOT_TOKEN} -u ${GH_USER} -r ${GH_REPO} -n "$(echo $DEPLOY_TYPE_NAME) Release for $(echo $CODENAME)" -b "PBRP $(echo $RELEASE_TAG)" -c ${GH_SHA} -delete ${RELEASE_TAG} ${UPLOAD_PATH} + + return "$?" +} + + +# Deploy Official Build on Official Telegram Channel +function tg_official_deploy() { + echo -e "${green}Deploying to Telegram!\n${nocol}" + + if [ -z "$DEVICES" ]; then + python3 vendor/utils/scripts/telegram.py -c @pitchblackrecovery -AN "$pb_sticker" -C "$FORMAT" -D "Download|${wp_link}!Chat|https://t.me/pbrpcom!Channel|https://t.me/pitchblackrecovery" -m "HTML" + else + python3 vendor/utils/scripts/telegram.py -c @pitchblackrecovery -AN "$pb_sticker" -C "$FORMAT" -D "${BUTTONS}Chat|https://t.me/pbrpcom!Channel|https://t.me/pitchblackrecovery" -m "HTML" + fi + + echo -e "${green}Deployed to Telegram SUCCESSFULLY!\n${nocol}" + return 0 +} + + +# Deploy Beta Build on Official PBRP Testing Group +function tg_beta_deploy() { + echo -e "${green}Deploying to Telegram!\n${nocol}" + + if [ -z "$DEVICES" ]; then + python3 vendor/utils/scripts/telegram.py -c "-1001270222037" -AN "$pb_sticker" -C "$FORMAT" -D "Download|$wp_link!Beta Chat|https://t.me/pbrp_testers!Channel|https://t.me/joinchat/AAAAAEu2DNXX-P7RgFWBcw" -m "HTML" + else + python3 vendor/utils/scripts/telegram.py -c "-1001270222037" -AN "$pb_sticker" -C "$FORMAT" -D "${BUTTONS}Beta Chat|https://t.me/pbrp_testers!Channel|https://t.me/joinchat/AAAAAEu2DNXX-P7RgFWBcw" -m "HTML" + fi + + + echo -e "${green}Deployed to Telegram SUCCESSFULLY!\n${nocol}" + return 0 +} + +# Deploy Test Build on Official PBRP Device Maintainers Group +function tg_test_deploy() { + echo -e "${green}Deploying to Telegram Device Maintainers Chat!\n${nocol}" + + if [ -z ${BUILDFILE} ]; then + TEST_LINK="https://github.com/${GH_USER}/${GH_REPO}/releases/download/${RELEASE_TAG}/recovery.img" + else + TEST_LINK="https://github.com/${GH_USER}/${GH_REPO}/releases/download/${RELEASE_TAG}/$(echo $BUILDFILE | awk -F'[/]' '{print $NF}')" + fi + + MAINTAINER_MSG="PitchBlack Recovery for \`${VENDOR}\` \`${CODENAME}\` is available Only For Testing Purpose\n\n" + if [[ ! -z $MAINTAINER ]]; then MAINTAINER_MSG=${MAINTAINER_MSG}"Maintainer: ${MAINTAINER}\n\n"; fi + if [[ ! -z $CHANGELOG ]]; then MAINTAINER_MSG=${MAINTAINER_MSG}"Changelog:\n"${CHANGELOG}"\n\n"; fi + + MAINTAINER_MSG=${MAINTAINER_MSG}"Go to ${TEST_LINK} to download it." + if [[ $USE_SECRET_BOOTABLE == 'true' ]]; then + python3 vendor/utils/scripts/telegram.py -c "-1001465331122" -M "$MAINTAINER_MSG" -m "HTML" + else + python3 vendor/utils/scripts/telegram.py -c "-1001228903553" -M "$MAINTAINER_MSG" -m "HTML" + fi + + echo -e "${green}Deployed to Telegram SUCCESSFULLY!\n${nocol}" + return 0 +} + +# Deploy on PBRP Database for WP +# NOTE: Must be called after sf_deploy +function wp_deploy() { + echo -e "${green}Deploying to PBRP Database!\n${nocol}" + + curl -i -X POST 'https://us-central1-pbrp-prod.cloudfunctions.net/release' -H "Authorization: Bearer ${GCF_AUTH_KEY}" -H "Content-Type: application/json" --data "{\"codename\": \"$CODENAME\", \"vendor\":\"$VENDOR\", \"md5\": \"$MD5\", \"size\": \"$FILE_SIZE\", \"sf_link\": \"$sf_link\", \"gh_link\": \"$gh_link\",\"version\": \"$VERSION\", \"build_type\": \"$DEPLOY_TYPE\"}" + + echo -e "${green}Deployed to PBRP Database SUCCESSFULLY!\n${nocol}" + return 0 +} + +if [[ "$DEPLOY_TYPE" == "OFFICIAL" ]]; then + zipcounter=$(find $(pwd)/out/target/product/$CODENAME/PBRP*-OFFICIAL.zip 2>/dev/null | wc -l) +elif [[ "$DEPLOY_TYPE" == "BETA" ]]; then + zipcounter=$(find $(pwd)/out/target/product/$CODENAME/PBRP*-BETA.zip 2>/dev/null | wc -l) +else + zipcounter=$(find $(pwd)/out/target/product/$CODENAME/PBRP*-UNOFFICIAL.zip 2>/dev/null | wc -l) +fi + + recoveryimgcheck=$(find $(pwd)/out/target/product/$CODENAME/recovery.img 2>/dev/null | wc -l) + +if [[ "$recoveryimgcheck" > "0" ]]; then + if [[ "$zipcounter" > "1" ]]; then + printf "${red}More than one zips dected! Remove old build...\n${nocol}" + else + # Time for Deployment! + if [[ "$DEPLOY_TYPE" == "OFFICIAL" ]]; then + # Official Deploy = SF + GHR + WP + TG (Main Channel) + + if ! sf_deploy; then echo -e "Error in SourceForge Deployment." && exit 1; fi + if ! gh_deploy; then echo -e "Error in GitHub Releases Deployment." && exit 1; fi + if ! wp_deploy; then echo -e "Error in PBRP Website Deployment." && exit 1; fi + if ! tg_official_deploy; then echo -e "Error in Telegram Official Deployment." && exit 1; fi + elif [[ "$DEPLOY_TYPE" == "BETA" ]]; then + # Beta Deploy = SF + GHR + WP + TG (Beta Group) + + if ! sf_deploy; then echo -e "Error in SourceForge Deployment." && exit 1; fi + if ! gh_deploy; then echo -e "Error in GitHub Releases Deployment." && exit 1; fi + if ! wp_deploy; then echo -e "Error in PBRP Website Deployment." && exit 1; fi + if ! tg_beta_deploy; then echo -e "Error in Telegram Beta Deployment." && exit 1; fi + elif [[ "$DEPLOY_TYPE" == "TEST" ]]; then + # Test Deploy = GHR + TG (Device Maintainers Chat) + + if ! gh_deploy; then echo -e "Error in GitHub Releases Deployment." && exit 1; fi + if ! tg_test_deploy; then echo -e "Error in Telegram Test Deployment." && exit 1; fi + else + echo -e "Wrong Arguments Given, Required Arguments: BUILD_TYPE(OFFICIAL/BETA/TEST)" && exit 1 + fi + fi +else + echo + printf "${red}No build found\n${nocol}" + echo +fi