Skip to content

Instantly share code, notes, and snippets.

@rokibhasansagar
Last active March 16, 2020 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rokibhasansagar/bf1e94f9e7426650bcbbf16506511f25 to your computer and use it in GitHub Desktop.
Save rokibhasansagar/bf1e94f9e7426650bcbbf16506511f25 to your computer and use it in GitHub Desktop.
[WIP] SkyHawk Builder

Build SkyHawk Recovery Project in CircleCI and Release onto Device Tree itself. Attach the .CircleCI.config.yml file as ".circleci/config.yml" in DT and set some ENV Vars. Trigger the build and voilà, You get the built zip as-well-as recovery.img for safekeeping.

version: 2.1
jobs:
build:
docker:
- image: fr3akyphantom/droid-builder:latest
environment:
# MANIFEST_BR: '9.0' # Optional: State SHRP Manifest Branch. i.e., '9.0' or other
VENDOR: 'meizu' # State Product Vendor or Manufacturer
CODENAME: 'mblu2' # Device Codename
GitHubMail: '' # Enter GitHub User EMail Address
GitHubName: '' # Enter GitHub Username
# Add the following Token in encrypted form inside CircleCI
# GITHUB_TOKEN: '' # GitHub OAuth Token, for release
EXTRA_CMD: "cd bootable/recovery; patch -p1 < ../../device/${VENDOR}/${CODENAME}/patches/bootable/recovery/*.patch || true; cd ../.."
Device_Tree: 'https://github.com/SHRP-Devices/device_meizu_mblu2' # The Full URL of DT
BUILDTYPE: 'userdebug' # Set as eng or userdebug
VER: '2.2'
working_directory: /home/builder/shrp/
steps:
# - checkout
- run:
name: Create a keep-alive shell
command: |
cat \<< EOF > act.sh
#!/bin/bash
while true; do
echo -e "\n" && sleep 300
done
EOF
chmod a+x act.sh
- run:
name: Get Script and Execute Build
command: |
wget -q "https://gist.github.com/rokibhasansagar/bf1e94f9e7426650bcbbf16506511f25/raw/script.sh"
chmod a+x script.sh
# Run script along with keep-alive shell
./act.sh & ./script.sh
#!/bin/bash
# Some checks before proceeding
if [[ -z ${Device_Tree} ]]; then
echo -e "\n Device Tree URL is not given.\n Can not proceed."
exit 1
elif [[ -z ${VENDOR} ]]; then
echo -e "\n Vendor Name not given."
exit 1
elif [[ -z ${CODENAME} ]]; then
echo -e "\n Device Codename not given."
exit 1
else
true
fi
if [[ -z ${BUILDTYPE} ]]; then
echo -e "\n Build Type, e.g., eng or userdebug is not set."
exit 1
fi
if [[ -z ${MANIFEST_BR} ]]; then
echo -e "\n Using Default Pie Manifest Branch."
MANIFEST_BR="9.0"
fi
if [[ -z $GitHubName ]]; then
echo -e "\n GitHub Username is not set."
exit 1
elif [[ -z $GitHubMail ]]; then
echo -e "\n GitHub E-mail Address is not set."
exit 1
else
true
fi
if [[ -z ${GITHUB_TOKEN} ]]; then
echo -e "\n GitHub OAuth Token not set. Can not Upload Built File on GitHub Releases."
fi
# Set Git Credential
git config --global user.email $GitHubMail
git config --global user.name $GitHubName
git config --global color.ui true
git config --global credential.helper store
# Proceed
mkdir droid && cd droid
BuildDir=$(pwd) && export BuildDir=$(echo $(pwd))
echo -e "\n Initialize repo Command"
repo init -q -u https://github.com/SKYHAWK-Recovery-Project/platform_manifest_twrp_omni.git -b ${MANIFEST_BR} --depth 1
echo -e "\n Removing Unimportant Darwin-specific Files from syncing"
cd .repo/manifests
sed -i '/darwin/d' default.xml
( find . -type f -name '*.xml' | xargs sed -i '/darwin/d' ) || true
git commit -a -m "Magic" || true
cd ../
sed -i '/darwin/d' manifest.xml
cd ../
CPU_COUNT=$(grep -c ^processor /proc/cpuinfo)
THREAD_COUNT_SYNC=$(($CPU_COUNT * 8))
echo -e "\n Syncing it up! Wait for a few minutes..."
repo sync -c -q --force-sync --no-clone-bundle --optimized-fetch --prune --no-tags -j$THREAD_COUNT_SYNC
# Device Tree with/without patches goes here
git clone ${Device_Tree} device/${VENDOR}/${CODENAME}
# Patches, if needed, use EXTRA_CMD env variable
# Export commands in one line. Use semicolons if more than one command is needed.
# Don't forget to bind them in one double quote.
if [[ -n ${EXTRA_CMD} ]]; then
eval ${EXTRA_CMD}
cd ${BuildDir}
fi
echo -e "\n Build process starting..."
export ALLOW_MISSING_DEPENDENCIES=true
source build/envsetup.sh
lunch omni_${CODENAME}-${BUILDTYPE}
make -j$(nproc --all) recoveryimage
mkdir -p ${BuildDir}/release
cp out/target/product/${CODENAME}/SHRP*.zip ${BuildDir}/release/
# Release Build as Zip
if [[ ! -z ${GITHUB_TOKEN} ]]; then
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -n "SkyHawk Recovery Project $(echo $VER)" -b "Latest Release for $(echo $CODENAME)" -c ${CIRCLE_SHA1} -delete v$(echo $VER) ${BuildDir}/release/
fi
echo -e "\n All Done.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment