Skip to content

Commit

Permalink
Feature: Add system & twrp builder.
Browse files Browse the repository at this point in the history
* Add DogDayBuilder.
* Move kernel builder to seperate directory.
* Add OrangeFox builder.
* Add a script to clear all tags and releases.
  • Loading branch information
easterNday committed Nov 17, 2023
1 parent f8d6f9d commit 93465d7
Show file tree
Hide file tree
Showing 34 changed files with 1,692 additions and 974 deletions.
2 changes: 2 additions & 0 deletions .Scripts/CleanUp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Delete all tags & releases
gh release list | awk -F '\\t' '{print $3}' | while read -r line; do gh release delete -y "$line" --cleanup-tag; done
6 changes: 3 additions & 3 deletions .github/workflows/build.yml → .github/workflows/kernel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build kernels
on:
push:
paths:
- ".github/workflows/build.yml"
- ".github/workflows/kernel.yml"
workflow_dispatch:
schedule:
- cron: "14 13 * * 5"
Expand All @@ -25,7 +25,7 @@ jobs:
id: generate-matrix
run: |
echo "CONFIGS<<EOF" >> $GITHUB_OUTPUT
jq -s '[.[][]]' configs/*.config.json >> $GITHUB_OUTPUT
jq -s '[.[][]]' Kernel/configs/*.config.json >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Set compile time.
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:

# Set output & ccache directory
OUT_DIR: "${{ github.workspace }}/out"
CCACHE_DIR: "${{ github.workspace }}/out"
CCACHE_DIR: "${{ github.workspace }}/ccache"
steps:
# Set swap space
- name: 📐 Set swap to 10G
Expand Down
127 changes: 127 additions & 0 deletions .github/workflows/twrp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Build TWRPs

on:
push:
paths:
- ".github/workflows/twrp.yml"
workflow_dispatch:
schedule:
- cron: "14 13 * * 5"

jobs:
Read-configuration:
name: 🏧 Parse *.config.json
runs-on: ubuntu-latest
outputs:
CONFIGS: ${{ steps.generate-matrix.outputs.CONFIGS }}
BUILD_DATE: ${{ steps.generate-builddate.outputs.BUILDDATE }}
steps:
# This action checks-out your CONFIGSitory under $GITHUB_WORKSPACE, so your workflow can access it.
- name: ♈ Checkout
uses: actions/checkout@v4

# Match the configuration files in the CONFIGS directory, read the contents and merge them into an array.
- name: ♉ Generate Matrix
id: generate-matrix
run: |
echo "CONFIGS<<EOF" >> $GITHUB_OUTPUT
jq -s '[.[][]]' TWRP/configs/*.config.json >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Set compile time.
- name: ♊ Set builddate
id: generate-builddate
run: echo "BUILDDATE=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT

Build-TWRP:
name: 🛄 Build TWRP
runs-on: ubuntu-latest
needs:
- Read-configuration
strategy:
max-parallel: 4
fail-fast: false
matrix:
CONFIG: ${{ fromJSON(needs.Read-configuration.outputs.CONFIGS) }}
env:
# Basic configuration
WORKSPACE: ${{ github.workspace }}
BUILD_DATE: ${{ needs.Read-configuration.outputs.BUILD_DATE }}

# OrangeFox sync scripts configuration
OF_LOCATION: ${{ github.workspace }}/OrangeFox
OF_SYNC_REPO: ${{ matrix.CONFIG.OrangeFox.Repo }}
OF_SYNC_BRANCH: ${{ matrix.CONFIG.OrangeFox.Branch }}

# DeviceTree configuration
DEVICE_REPO: ${{ matrix.CONFIG.Device.Repo }}
DEVICE_BRANCH: ${{ matrix.CONFIG.Device.Branch }}
DEVICE_LOCATION: ${{ matrix.CONFIG.Device.Location }}
DEVICE_NAME: ${{ matrix.CONFIG.Device.DeviceName }}
DEVICE_MAKEFILE: ${{ matrix.CONFIG.Device.Makefile }}
DEVICE_BOOT_PARTITION: ${{ matrix.CONFIG.Device.BootPartition }}

# Set output & ccache directory
OUT_DIR: "${{ github.workspace }}/out"
CCACHE_DIR: "${{ github.workspace }}/ccache"
steps:
# Clean up the workspace and make room for compilation
- name: ♋ Cleanup
uses: rokibhasansagar/slimhub_actions@main

- name: ♌ Prepare the build environment
run: |
cd ~
sudo apt install git aria2 -y
git clone https://gitlab.com/OrangeFox/misc/scripts
cd scripts
sudo bash setup/android_build_env.sh
sed -i 's/cd -/cd ../g' setup/install_android_sdk.sh
sudo bash setup/install_android_sdk.sh
- name: ♍ Sync OrangeFox sources and minimal manifest
run: |
git clone ${{ env.OF_SYNC_REPO }} sync
cd sync
./orangefox_sync.sh --branch ${{ env.OF_SYNC_BRANCH }} --path ${{ env.OF_LOCATION }}
- name: ♎ Place device trees and kernel
working-directory: ${{ env.OF_LOCATION }}
run: |
git clone --recursive --depth=1 -j $(nproc) --branch ${{ env.DEVICE_BRANCH }} ${{ env.DEVICE_REPO }} ${{ env.DEVICE_LOCATION }}
- name: ♏ Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 12

- name: ♐ Build it
working-directory: ${{ env.OF_LOCATION }}
continue-on-error: true
run: |
set +e
source build/envsetup.sh
export ALLOW_MISSING_DEPENDENCIES=true
export FOX_BUILD_DEVICE=thyme
export LC_ALL="C"
set -e
lunch ${{ env.DEVICE_MAKEFILE }}-eng && mka adbd ${{ env.DEVICE_BOOT_PARTITION }}image -j$(nproc --all)
- name: ♑Take the OrangeFox build
uses: actions/upload-artifact@v3
with:
name: OrangeFox
if-no-files-found: warn
path: |
${{ env.OUT_DIR }}/target/product/${{ env.DEVICE_NAME }}/*${{ env.DEVICE_NAME }}.img
${{ env.OUT_DIR }}/target/product/${{ env.DEVICE_NAME }}/*${{ env.DEVICE_NAME }}.zip
- name: ♒ Create GitHub Release => (${{ env.BUILD_DATE }})
continue-on-error: true
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.BUILD_DATE }}.${{ github.run_number }}
files: |
${{ env.OUT_DIR }}/target/product/${{ env.DEVICE_NAME }}/*${{ env.DEVICE_NAME }}.img
${{ env.OUT_DIR }}/target/product/${{ env.DEVICE_NAME }}/*${{ env.DEVICE_NAME }}.zip
generate_release_notes: true
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
147 changes: 147 additions & 0 deletions Kernel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Build Your Own Kernel

English | [中文文档](./README.zh_CN.md)

In this part, we will use `Github Action` to perform kernel cloud compilation. The directory structure of this project is as follows:

```sh
.
├── configs
│   ├── markw.config.json
│   ├── thyme.config.json
│   └── wayne.config.json
└── LXC
   ├── LXC_defconfig
   └── Patches
      ├── cgroup.patch
      └── xt_qtaguid.patch
```

The contents and functions of each part are as follows:

- **configs**: used to store the detailed configuration of all kernels to be compiled (kernel source code address, compilation tool chain, compilation parameters and additional compilation options)
- **LXC**: stores some configuration files and patches required for kernel support `Docker`
- **LXC_defconfig**: Options that need to be enabled for kernel support `Docker`
- **Patches**: Some patches that need to be applied

## Development progress

- [x] `AnyKernel3` original and customized versions supported
- [x] `KernelSU` compilation support
- [x] `Docker` compilation support
- [x] Use repository owner information to compile
- [ ] Use `MagiskBoot` to generate `boot.img`
- [ ] Compile kernel script locally
- [ ] Web page configuration Json compilation configuration file (to be released soon)
- [ ] Cloud compiled kernel web page

## Github Action

### Introduction to the compilation process

The `Github Action` file for compiling the kernel is [kernel.yml](../.github/workflows/kernel.yml). This Action contains the following two jobs:

- `Read-configuration`: used to read the configuration files in the `configs` folder
- `Build-Kernel`: Compile the text kernel according to the read configuration file, and perform functions such as uploading

### Compilation process timeline

```mermaid
%%{init: { 'logLevel': 'debug', 'theme': 'neutral' } }%%
timeline
How to build a Kernel
section Read configuration
Checkout repository
Generate configuration matrix
Set builddate
section Kernel Build
Prepare : 📐 Set swap to 10G : 😄 Checkout repository
: ⭐ Install prerequisites for Ubuntu : 🚄 Setup ccache : 🚅 Restore cache
: 🌟 Clone kernel source : 💫 Get toolchains
Basic configuration : 😎 Set build args : 😋 Setup KernelSU : 😋 Setup LXC Docker
: 👍 Build kernel
section Post build
Upload Artifact : 💛 Upload Image : 💙 Upload Image.gz : 💙 Upload Image.gz-dtb
: 💜 Upload dtb : ❤️ Upload dtbo.img : ☢️ Upload output directory
Pack Anykernel3 : ⏰ Get Anykernel3 : ⏰ Pack your kernel : 💾 Upload AnyKernel3 package
Release
```

## Configuration file parsing

Please see [Compile Configuration](./configs/) for specific configuration methods.

## Instructions

The basic usage of this project is as follows:

1. `fork` this project on GitHub

2. Modify the `config/*.config.json` file through the Github web page or pull it locally, and submit the changes

3. View the `Action` page of the Github page and find `Build kernels` and `Run workflow`

4. After the compilation is completed, you can enter the corresponding page to download the compiled product.

5. Use your favorite packaging software for kernel packaging ([AnyKernel3](https://github.com/osm0sis/AnyKernel3), [Android-Image-Kitchen](https://github.com/osm0sis/Android-Image-Kitchen), [MagiskBoot](https://github.com/topjohnwu/Magisk/releases), etc. **Currently this project only integrates AnyKernel3**)

![Artifacts](https://github.com/DogDayAndroid/Android-Builder/blob/main/.assets/artifacts.png?raw=true)

## Local build

### 1. Run `Action` locally

If you don't want to repeatedly execute `Action` on `Github`, you can use [nektos/act](https://github.com/nektos/act) to test this build process and output it in the local environment.

After installing [nektos/act](https://github.com/nektos/act) and execute the following instructions:

```sh
# Collect build files into the /tmp/artifacts folder:
act --artifact-server-path /tmp/artifacts
```

If you need to place it in a local location you like, please change `/tmp/artifacts` to your preferred directory.

If an error is reported during the process, please add the parameter `-v` and re-execute to obtain the error report and submit an `issue`. The specific command is as follows:

```sh
# Collect build files into the /tmp/artifacts folder:
act --artifact-server-path /tmp/artifacts -v
```

## FAQ

### 1. GitHub release failed with status: `403`

When you use `softprops/action-gh-release@v1` to publish `Release`, you may encounter the following error:

```plaintext
👩‍🏭 Creating new GitHub release for tag v20230619.7...
⚠️ GitHub release failed with status: 403
undefined
retrying... (2 retries remaining)
👩‍🏭 Creating new GitHub release for tag v20230619.7...
⚠️ GitHub release failed with status: 403
undefined
retrying... (1 retries remaining)
👩‍🏭 Creating new GitHub release for tag v20230619.7...
⚠️ GitHub release failed with status: 403
undefined
retrying... (0 retries remaining)
❌ Too many retries. Aborting...
Error: Too many retries.
```

This is caused by your `Workflow` not having **read and write permission**:

![workflow permissions](https://github.com/DogDayAndroid/Android-Builder/blob/main/.assets/FAQ/workflow%20permissions.png?raw=true)

Open the corresponding read and write permissions as shown above, and then re-run `Action` to publish your own `Release`

# Acknowledgments

- [weishu](https://github.com/tiann) : Developer of KernelSU
- [AKR Android Developer Community](https://www.akr-developers.com/) : Provides build tutorials
- [DogDayAndroid/KSU_Thyme_BuildBot](https://github.com/DogDayAndroid/KSU_Thyme_BuildBot) : Predecessor of this project
- [xiaoleGun/KernelSU_Action](https://github.com/xiaoleGun/KernelSU_Action) : Drawing on some Github Actions
- [UtsavBalar1231/Drone-scripts](https://github.com/UtsavBalar1231/Drone-scripts) : Drawing on some Github Actions
Loading

0 comments on commit 93465d7

Please sign in to comment.