From 27c4f03a00c917d0053905ec60763450516e2ec0 Mon Sep 17 00:00:00 2001 From: midozalouk Date: Fri, 19 Jan 2024 18:50:49 +0300 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .github/workflows/Recovery Build (Legacy).yml | 168 ++++++++++++++++++ .github/workflows/Recovery Build.yml | 168 ++++++++++++++++++ README.md | 121 +++++++++++++ scripts/convert.sh | 58 ++++++ 5 files changed, 517 insertions(+) create mode 100644 .gitattributes create mode 100644 .github/workflows/Recovery Build (Legacy).yml create mode 100644 .github/workflows/Recovery Build.yml create mode 100644 README.md create mode 100644 scripts/convert.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.github/workflows/Recovery Build (Legacy).yml b/.github/workflows/Recovery Build (Legacy).yml new file mode 100644 index 0000000..d3d9414 --- /dev/null +++ b/.github/workflows/Recovery Build (Legacy).yml @@ -0,0 +1,168 @@ +name: Recovery Build (Legacy) + +on: + workflow_dispatch: + inputs: + MANIFEST_URL: + description: 'MANIFEST_URL (if want to use SSH keys, use git@github.com:XXXXX)' + required: true + default: 'https://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni' + MANIFEST_BRANCH: + description: 'MANIFEST_BRANCH' + required: true + default: 'twrp-7.1' + DEVICE_TREE_URL: + description: 'DEVICE_TREE_URL' + required: true + default: 'https://github.com/ycly2333/android_device_EEBBK_H3000S-twrp' + DEVICE_TREE_BRANCH: + description: 'DEVICE_TREE_BRANCH' + required: true + default: 'twrp-7.1' + DEVICE_PATH: + description: 'DEVICE_PATH' + required: true + default: 'device/EEBBK/H3000S' + COMMON_TREE_URL: + description: 'COMMON_TREE_URL (if no common tree, leave blank)' + required: false + COMMON_PATH: + description: 'COMMON_PATH (if no common tree, leave blank)' + required: false + DEVICE_NAME: + description: 'DEVICE_NAME' + required: true + default: 'H3000S' + MAKEFILE_NAME: + description: 'MAKEFILE_NAME' + required: true + default: 'omni_H3000S' + BUILD_TARGET: + description: 'BUILD_TARGET' + required: true + default: 'recovery' + +jobs: + build: + if: github.event.repository.owner.id == github.event.sender.id + runs-on: ubuntu-20.04 + permissions: + contents: write + steps: + - name: Display Run Parameters + run: | + echo "::group::User Environment Variables" + echo "Manifest URL: ${{ github.event.inputs.MANIFEST_URL }}" + echo "Manifest Branch: ${{ github.event.inputs.MANIFEST_BRANCH }}" + echo "Device Tree URL: ${{ github.event.inputs.DEVICE_TREE_URL }}" + echo "Device Tree Branch: ${{ github.event.inputs.DEVICE_TREE_BRANCH }}" + echo "Device Path: ${{ github.event.inputs.DEVICE_PATH }}" + echo "Device Name: ${{ github.event.inputs.DEVICE_NAME }}" + echo "Makefile Name: ${{ github.event.inputs.MAKEFILE_NAME }}" + echo "Build Target: ${{ github.event.inputs.BUILD_TARGET }}.img" + echo "::endgroup::" + + # You might want to Checkout your repo first, but not mandatory + - name: Check Out + uses: actions/checkout@v3 + # Cleanup The Actions Workspace Using Custom Composite Run Actions + - name: Cleanup + uses: rokibhasansagar/slimhub_actions@main + # That's it! Now use your normal steps + + - name: Prepare the environment + run: | + sudo apt update + sudo apt -y upgrade + sudo apt -y install gperf gcc-multilib gcc-10-multilib g++-multilib g++-10-multilib libc6-dev lib32ncurses5-dev x11proto-core-dev libx11-dev tree lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc bc ccache lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk3.0-gtk3-dev libxml2 lzop pngcrush schedtool squashfs-tools imagemagick libbz2-dev lzma ncftp qemu-user-static libstdc++-10-dev libncurses5 python3 + + - name: Install OpenJDK + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: '8' + + - name: Setup SSH Keys + if: ${{ startsWith(github.event.inputs.MANIFEST_URL, 'git@github.com') }} + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: | + ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Install repo + run: | + mkdir ~/bin + curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo + chmod a+x ~/bin/repo + sudo ln -sf ~/bin/repo /usr/bin/repo + + - name: Initialize repo + run: | + mkdir workspace + cd workspace + echo "workspace-folder=$(pwd)" >> $GITHUB_OUTPUT + git config --global user.name "azwhikaru" + git config --global user.email "azwhikaru+37921907@github.com" + repo init --depth=1 -u ${{ github.event.inputs.MANIFEST_URL }} -b ${{ github.event.inputs.MANIFEST_BRANCH }} + id: pwd + + - name: Repo Sync + run: | + repo sync -j$(nproc --all) --force-sync + working-directory: workspace + + - name: Clone device tree + run: | + git clone ${{ github.event.inputs.DEVICE_TREE_URL }} -b ${{ github.event.inputs.DEVICE_TREE_BRANCH }} ./${{ github.event.inputs.DEVICE_PATH }} + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + + - name: Clone common tree + if: | + github.event.inputs.COMMON_TREE_URL != null + && github.event.inputs.COMMON_PATH != null + run: | + git clone ${{ github.event.inputs.COMMON_TREE_URL }} -b ${{ github.event.inputs.DEVICE_TREE_BRANCH }} ./${{ github.event.inputs.COMMON_PATH }} + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + + - name: Sync Device Dependencies + run: | + bash ${GITHUB_WORKSPACE}/scripts/convert.sh ${{ github.event.inputs.DEVICE_PATH }}/${{ steps.buildtree.outputs.value }}.dependencies + repo sync -j$(nproc --all) + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + continue-on-error: true + + - name: Set Swap Space + uses: pierotofy/set-swap-space@master + with: + swap-size-gb: 12 + + - name: Switch to Python2 + run: | + sudo apt -y install python + sudo rm -rf /usr/bin/python + sudo ln -s /usr/bin/python2 /usr/bin/python + # sudo ln -s /usr/bin/python3 /usr/bin/python3 + continue-on-error: true + + - name: Building recovery + run: | + source build/envsetup.sh + export ALLOW_MISSING_DEPENDENCIES=true + lunch ${{ github.event.inputs.MAKEFILE_NAME }}-eng && make clean && make ${{ github.event.inputs.BUILD_TARGET }}image -j$(nproc --all) + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + + - name: Upload to Release + uses: softprops/action-gh-release@v1 + with: + files: | + workspace/out/target/product/${{ github.event.inputs.DEVICE_NAME }}/${{ github.event.inputs.BUILD_TARGET }}.img + workspace/out/target/product/${{ github.event.inputs.DEVICE_NAME }}/*.zip + workspace/out/target/product/${{ github.event.inputs.DEVICE_NAME }}/*vendor*.img + name: ${{ github.event.inputs.DEVICE_NAME }}-${{ github.run_id }} + tag_name: ${{ github.run_id }} + body: | + Manifest: ${{ github.event.inputs.MANIFEST_BRANCH }} + Device: ${{ github.event.inputs.DEVICE_NAME }} + Target: ${{ github.event.inputs.BUILD_TARGET }}.img + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/Recovery Build.yml b/.github/workflows/Recovery Build.yml new file mode 100644 index 0000000..7630cf6 --- /dev/null +++ b/.github/workflows/Recovery Build.yml @@ -0,0 +1,168 @@ +name: Recovery Build + +on: + workflow_dispatch: + inputs: + MANIFEST_URL: + description: 'MANIFEST_URL (if want to use SSH keys, use git@github.com:XXXXX)' + required: true + default: 'https://github.com/minimal-manifest-twrp/platform_manifest_twrp_aosp' + MANIFEST_BRANCH: + description: 'MANIFEST_BRANCH' + required: true + default: 'twrp-12.1' + DEVICE_TREE_URL: + description: 'DEVICE_TREE_URL' + required: true + default: 'https://github.com/TeamWin/android_device_asus_I003D' + DEVICE_TREE_BRANCH: + description: 'DEVICE_TREE_BRANCH' + required: true + default: 'android-12.1' + DEVICE_PATH: + description: 'DEVICE_PATH' + required: true + default: 'device/asus/I003D' + COMMON_TREE_URL: + description: 'COMMON_TREE_URL (if no common tree, leave blank)' + required: false + COMMON_PATH: + description: 'COMMON_PATH (if no common tree, leave blank)' + required: false + DEVICE_NAME: + description: 'DEVICE_NAME' + required: true + default: 'I003D' + MAKEFILE_NAME: + description: 'MAKEFILE_NAME' + required: true + default: 'twrp_I003D' + BUILD_TARGET: + description: 'BUILD_TARGET' + required: true + default: 'recovery' + +jobs: + build: + if: github.event.repository.owner.id == github.event.sender.id + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Display Run Parameters + run: | + echo "::group::User Environment Variables" + echo "Manifest URL: ${{ github.event.inputs.MANIFEST_URL }}" + echo "Manifest Branch: ${{ github.event.inputs.MANIFEST_BRANCH }}" + echo "Device Tree URL: ${{ github.event.inputs.DEVICE_TREE_URL }}" + echo "Device Tree Branch: ${{ github.event.inputs.DEVICE_TREE_BRANCH }}" + echo "Device Path: ${{ github.event.inputs.DEVICE_PATH }}" + echo "Device Name: ${{ github.event.inputs.DEVICE_NAME }}" + echo "Makefile Name: ${{ github.event.inputs.MAKEFILE_NAME }}" + echo "Build Target: ${{ github.event.inputs.BUILD_TARGET }}.img" + echo "::endgroup::" + + # You might want to Checkout your repo first, but not mandatory + - name: Check Out + uses: actions/checkout@v3 + # Cleanup The Actions Workspace Using Custom Composite Run Actions + - name: Cleanup + uses: rokibhasansagar/slimhub_actions@main + # That's it! Now use your normal steps + + - name: Prepare the environment + run: | + sudo apt update + sudo apt -y upgrade + sudo apt -y install gperf gcc-multilib gcc-10-multilib g++-multilib g++-10-multilib libc6-dev lib32ncurses5-dev x11proto-core-dev libx11-dev tree lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc bc ccache lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk3.0-gtk3-dev libxml2 lzop pngcrush schedtool squashfs-tools imagemagick libbz2-dev lzma ncftp qemu-user-static libstdc++-10-dev libncurses5 python3 + + - name: Install OpenJDK + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: '8' + + - name: Setup SSH Keys + if: ${{ startsWith(github.event.inputs.MANIFEST_URL, 'git@github.com') }} + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: | + ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Install repo + run: | + mkdir ~/bin + curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo + chmod a+x ~/bin/repo + sudo ln -sf ~/bin/repo /usr/bin/repo + + - name: Initialize repo + run: | + mkdir workspace + cd workspace + echo "workspace-folder=$(pwd)" >> $GITHUB_OUTPUT + git config --global user.name "Nico170420" + git config --global user.email "b170420nc@gmail.com" + repo init --depth=1 -u ${{ github.event.inputs.MANIFEST_URL }} -b ${{ github.event.inputs.MANIFEST_BRANCH }} + id: pwd + + - name: Repo Sync + run: | + repo sync -j$(nproc --all) --force-sync + working-directory: workspace + + - name: Clone device tree + run: | + git clone ${{ github.event.inputs.DEVICE_TREE_URL }} -b ${{ github.event.inputs.DEVICE_TREE_BRANCH }} ./${{ github.event.inputs.DEVICE_PATH }} + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + + - name: Clone common tree + if: | + github.event.inputs.COMMON_TREE_URL != null + && github.event.inputs.COMMON_PATH != null + run: | + git clone ${{ github.event.inputs.COMMON_TREE_URL }} -b ${{ github.event.inputs.DEVICE_TREE_BRANCH }} ./${{ github.event.inputs.COMMON_PATH }} + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + + - name: Check Build Tree + uses: haya14busa/action-cond@v1 + id: buildtree + with: + cond: ${{ github.event.inputs.MANIFEST_BRANCH == 'twrp-11' || github.event.inputs.MANIFEST_BRANCH == 'twrp-12.1' }} + if_true: twrp + if_false: omni + + - name: Sync Device Dependencies + run: | + bash ${GITHUB_WORKSPACE}/scripts/convert.sh ${{ github.event.inputs.DEVICE_PATH }}/${{ steps.buildtree.outputs.value }}.dependencies + repo sync -j$(nproc --all) + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + continue-on-error: true + + - name: Set Swap Space + uses: pierotofy/set-swap-space@master + with: + swap-size-gb: 12 + + - name: Building recovery + run: | + source build/envsetup.sh + export ALLOW_MISSING_DEPENDENCIES=true + lunch ${{ github.event.inputs.MAKEFILE_NAME }}-eng && make clean && make ${{ github.event.inputs.BUILD_TARGET }}image -j$(nproc --all) + working-directory: ${{ steps.pwd.outputs.workspace-folder }} + + - name: Upload to Release + uses: softprops/action-gh-release@v1 + with: + files: | + workspace/out/target/product/${{ github.event.inputs.DEVICE_NAME }}/${{ github.event.inputs.BUILD_TARGET }}.img + workspace/out/target/product/${{ github.event.inputs.DEVICE_NAME }}/*.zip + workspace/out/target/product/${{ github.event.inputs.DEVICE_NAME }}/*vendor*.img + name: ${{ github.event.inputs.DEVICE_NAME }}-${{ github.run_id }} + tag_name: ${{ github.run_id }} + body: | + Manifest: ${{ github.event.inputs.MANIFEST_BRANCH }} + Device: ${{ github.event.inputs.DEVICE_NAME }} + Target: ${{ github.event.inputs.BUILD_TARGET }}.img + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a3cfd1 --- /dev/null +++ b/README.md @@ -0,0 +1,121 @@ +## Automated TWRP compilation based on Github Action + +## Advertising + +1. OrangeFox is [here](https://github.com/azwhikaru/Action-OFRP-Builder) + +## Notice + +1. Github Actions service is **NOT** unlimited so to avoid waste, don't use unverified source code in this, the best used to automate builds of repositories that are already stabilized + +2. Before you make any changes, make sure that the repository you are operating in belongs to you. **"Fork" if you want to commit code, otherwise use "Use this template"** + +3. issues and Pull Requests may **NOT** get a reply. If you think is really necessary, use email on my profile to contact me + +4. Python 2 in Debian (Ubuntu) has been **removed**. If you are working on Android 8.1 and below, use *Recovery Build (Legacy)* + +5. Don't ask any questions about your source code, such as + - No rule to make ... + - Image ... out of size + +## Thanks to + +All contributors + +## Parameter Description + +| Name | Description | Example | +| -------------------- | ------------------------------------------------- | ------------------------------------------------------------ | +| `MANIFEST_URL` | Source address | https://github.com/minimal-manifest-twrp/platform_manifest_twrp_aosp.git | +| `MANIFEST_BRANCH` | Source branch | twrp-12.1 | +| `DEVICE_TREE_URL` | Device address | https://github.com/TeamWin/android_device_asus_I003D | +| `DEVICE_TREE_BRANCH` | Device branch | android-12.1 | +| `DEVICE_PATH` | Device location | device/asus/I003D | +| `COMMON_TREE_URL` | Common tree address | https://github.com/TeamWin/android_device_asus_sm8250-common | +| `COMMON_PATH` | Common tree location | device/asus/sm8250-common | +| `DEVICE_NAME` | Model name | I003D | +| `MAKEFILE_NAME` | Makefile name | twrp_I003D | +| `BUILD_TARGET` | Build Target Partition (boot/recovery/vendorboot) | recovery | + +----- + +## How to use + +``` +For example, your username is: JohnSmith +``` + +#### 0. If you want to commit code, click 'Fork' in the upper right corner of this repository + +![image](https://user-images.githubusercontent.com/37921907/177914706-c92476c5-7e14-4fb3-be94-0c8a11dae874.png) + +#### 1. If you just want to use it simply, click 'Use this template' in the upper right corner of this repository + +![image](https://github.com/azwhikaru/Action-TWRP-Builder/assets/37921907/fae6ce3c-bd4c-4bbe-8050-5dd29dff2522) + +#### 2. After waiting for the automatic redirection, you will see your own username + +![image](https://user-images.githubusercontent.com/37921907/177915106-5bde6fc9-303c-479e-b290-22b48efd1e4e.png) + +#### 3. Change the [username and email](https://github.com/CaptainThrowback/Action-Recovery-Builder/blob/main/.github/workflows/Recovery%20Build.yml#L100-L101) in the workflow to reflect your Github credentials (optional) + +## Setting up SSH Keys (optional) + +#### 4. Go to Settings, then select Deploy keys and select "Add deploy key" button. + +#### 5. On your Android device, install [Termux](https://github.com/termux/termux-app/releases) + +#### 6. Install openssh in Termux and generate ssh keys. (Do not use passphrase for keys) + +NOTE: When creating the deploy key for a repository like git@github.com:owner/repo.git or https://github.com/owner/repo, put that URL into the key comment. (Hint: Try ssh-keygen ... -C "git@github.com:owner/repo.git".) +owner = your Github username + +``` +pkg install openssh +ssh-keygen -t ed25519 -C "git@github.com:owner/Action-Recovery-Builder.git" +``` + +#### 7. Add the keys to your repo. In Termux, use the following commands: + +``` +cd /data/data/com.termux/files/usr/etc/ssh +cat ssh_host_ed25519_key.pub +``` + + Select and copy the key then paste in the box for Key. + You can name it whatever you choose for the title. + +#### 8. Now to add your private ssh key. Back in Termux: + +``` +cat ssh_host_ed25519_key +``` + + Copy the output from Termux. + + In your browser, select *Secrets* under the Security tab. + Select Actions + Select New repository secret + For the New secret name, it should be SSH_PRIVATE_KEY + Paste the output from ssh_host_ed25519_key into the Value box. + Then select Add secret. + +## Building the Recovery + +#### 9. Click 'Actions-Recovery Build' + +![image](https://user-images.githubusercontent.com/37921907/177915304-8731ed80-1d49-48c9-9848-70d0ac8f2720.png) + +#### 10. Click 'Run workflow' and fill in according to the above 'parameter description' + +![image](https://user-images.githubusercontent.com/37921907/177915346-71c29149-78fb-4a00-996f-5d84ffc9eb8c.png) + +#### 11. After filling in, click 'Run workflow' to start running + +----- + +## Compilation results + +Can be downloaded at [Release](../../releases) + +----- diff --git a/scripts/convert.sh b/scripts/convert.sh new file mode 100644 index 0000000..474bf83 --- /dev/null +++ b/scripts/convert.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +if [ -n "$1" ] && [ -e $1 ]; then + file=$1 +else + echo " ** Input File : $1 does not exist" + echo " ** Please specify the correct dependencies file" + echo " ** Usage : bash []" + exit 1 +fi + +if [ -n "$2" ]; then + manifest_path="$2" +elif [ -e .repo ]; then + mkdir -p .repo/local_manifests + manifest_path=".repo/local_manifests/roomservice.xml" +else + echo " ** Manifest file to create not specified." + echo " ** And .repo folder does not exist in $PWD" + echo " ** Either run the script from root of your source or specify a custom path+filename" + echo " ** Usage : bash []" + exit 1 +fi + + +if [ -e $manifest_path ]; then + sed -i 's@@@g' $manifest_path +else + echo "" > $manifest_path + echo "" >> $manifest_path +fi + +vars=( "remote" "repository" "target_path" "branch" "revision") + +for i in ${!vars[@]} ; do + value=$(grep "${vars[$i]}" "$file" | cut -d '"' -f4) + if [ "$value" != "" ]; then + declare -a ${vars[$i]}"_val"="( $value )" + fi +done + +for i in {0..5}; do + if [ "${repository_val[$i]}" != "" ] && [ "${target_path_val[$i]}" != "" ]; then + target_path="path=\"${target_path_val[$i]}\"" + repository=" name=\"${repository_val[$i]}\"" + if [ "${remote_val[$i]}" != "" ]; then + remote_for_repo=" remote=\"${remote_val[$i]}\"" + fi + if [ "${branch_val[$i]}" != "" ]; then + revision=" revision=\"${branch_val[$i]}\"" + elif [ "${revision_val[$i]}" != "" ]; then + revision=" revision=\"${revision_val[$i]}\"" + fi + echo " " >> $manifest_path + fi +done + +echo "" >> $manifest_path