Skip to content

Build kernels

Build kernels #18

Workflow file for this run

name: "Build kernels"
env:
OUT_DIR: "${{ github.workspace }}/out"
on:
workflow_dispatch:
jobs:
Set-repos:
name: "🐂 Parse repos.json"
runs-on: ubuntu-latest
outputs:
repos: ${{ steps.generate-matrix.outputs.repos }}
builddate: ${{ steps.generate-builddate.outputs.builddate }}
steps:
- name: "😄 Checkout"
uses: actions/checkout@v3
- name: "😆 Generate Matrix"
id: generate-matrix
run: |
echo "repos<<EOF" >> $GITHUB_OUTPUT
jq -s '[.[][]]' repos*.json >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: "⏰ Set builddate"
id: generate-builddate
run: echo "builddate=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
Build-Kernel:
name: "🐎 Build kernel"
runs-on: ubuntu-22.04
needs:
- Set-repos
strategy:
max-parallel: 4
fail-fast: false
matrix:
repos: ${{ fromJSON(needs.Set-repos.outputs.repos) }}
env:
WORKSPACE: ${{ github.workspace }}
builddate: "${{ needs.Set-repos.outputs.builddate }}"
KERNEL_NAME: ${{ matrix.repos.kernelSource.name }}
KERNEL_REPO: ${{ matrix.repos.kernelSource.repo }}
KERNEL_BRANCH: ${{ matrix.repos.kernelSource.branch }}
KERNEL_DEVICE: ${{ matrix.repos.kernelSource.device }}
DEFCONFIG_NAME: ${{ matrix.repos.kernelSource.defconfig }}
withKernelSU: ${{ matrix.repos.withKernelSU }}
useAnykernel: ${{ matrix.repos.AnyKernel3.use }}
release: ${{ matrix.repos.AnyKernel3.release }}
steps:
- name: "⭐ Install prerequisites"
run: |
sudo apt-get update
sudo apt-get install -y build-essential bc curl git zip ftp gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi libssl-dev lftp zstd wget libfl-dev python2 python3 libarchive-tools
- name: "⏰ Setup Anykernel3"
env:
params: "${{ toJSON(matrix.repos.AnyKernel3) }}"
run: |
ANYKERNEL_REPO=$(echo $params | jq -r ".repo")
ANYKERNEL_BRANCH=$(echo $params | jq -r ".branch")
git clone --recursive --depth=1 -j $(nproc) --branch $ANYKERNEL_BRANCH $ANYKERNEL_REPO AnyKernel3
echo "🤔 Setup Anykernel3 => ($ANYKERNEL_REPO)"
- name: "🌟 Clone kernel source => (${{ env.KERNEL_REPO }})"
run: |
git clone --recursive --depth=1 -j $(nproc) --branch $KERNEL_BRANCH $KERNEL_REPO $KERNEL_NAME
echo "🤔 Clone kernel source => ($KERNEL_REPO)"
- name: "💫 Get toolchains"
env:
toolchains: "${{ toJSON(matrix.repos.toolchains) }}"
run: |
toolchains_num="$(echo $toolchains | jq 'length')"
echo "🤔 There is $toolchains_num defined toolchains."
for ((i=0;i<toolchains_num;i++)); do
toolchain_name=$(echo $toolchains | jq -r ".[$i].name")
toolchain_repo=$(echo $toolchains | jq -r ".[$i].repo")
toolchain_branch=$(echo $toolchains | jq -r ".[$i].branch")
git clone --recursive --depth=1 -j $(nproc) --branch $toolchain_branch $toolchain_repo $toolchain_name
echo "🤔 Clone $toolchain_name => ($toolchain_repo)"
jq -r ".[$i].binPath[] | tostring" <<< "$toolchains" | while read -r bin_path; do
echo "$WORKSPACE/$toolchain_name/$bin_path" >> $GITHUB_PATH
done
done
- name: "😎 Set args"
id: generate-args
env:
params: "${{ toJSON(matrix.repos.params) }}"
THREAD: $(nproc --all)
run: |
echo "🤔 PATH Variable: $PATH"
ARCH=$(echo $params | jq -r ".ARCH")
CC=$(echo $params | jq -r ".CC")
args="-j${{ env.THREAD }}"
if [ -n "${{ env.OUT_DIR }}" ]; then
mkdir -p ${{ env.OUT_DIR }} && args="$args O=${{ env.OUT_DIR }}"
fi
if [ -n "$ARCH" ]; then
args="$args ARCH=$ARCH"
fi
if [ -n "$CC" ]; then
args="$args CC=${{ env.WORKSPACE }}/$CC"
fi
while read -r externalCommand; do
args="$args $externalCommand"
done < <(jq -r '.externalCommand | to_entries[] | "\(.key)=${{ env.WORKSPACE }}/\(.value)"' <<< "$params")
echo "🤔 $args"
echo "ARCH=$ARCH" >> $GITHUB_OUTPUT
echo "args=$args" >> $GITHUB_OUTPUT
- name: "😋 Update KernelSU"
working-directory: ${{ env.KERNEL_NAME }}
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
if: ${{ env.withKernelSU == 'true' }}
run: |
if [ -d "./KernelSU" ]; then
rm -rf "./KernelSU"
fi
if [ -d "./drivers/kernelsu" ]; then
rm -rf "./drivers/kernelsu"
fi
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s main
echo -e "CONFIG_KPROBES=y" >> arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
echo -e "CONFIG_HAVE_KPROBES=y" >> arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
echo -e "CONFIG_KPROBE_EVENTS=y" >> arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
cat arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
- name: "👍 Make defconfig"
working-directory: ${{ env.KERNEL_NAME }}
env:
args: ${{ steps.generate-args.outputs.args }}
arch: ${{ steps.generate-args.outputs.ARCH }}
run: |
echo "PATH Variable: $PATH"
make ${{ env.args }} ${{ env.DEFCONFIG_NAME }}
- name: "🎶 Build kernel"
working-directory: ${{ env.KERNEL_NAME }}
env:
args: ${{ steps.generate-args.outputs.args }}
run: |
echo "PATH Variable: $PATH"
make ${args}
- name: "💛 Upload Image"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: Image-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image
if-no-files-found: ignore
retention-days: 7
- name: "💙 Upload Image.gz"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: Image.gz-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz
if-no-files-found: ignore
retention-days: 7
- name: "💜 Upload dtb"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: dtb-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtb
if-no-files-found: ignore
retention-days: 7
- name: "❤️ Upload dtbo.img"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: dtbo.img-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo.img
if-no-files-found: ignore
retention-days: 7
- name: "❤️ Pack AnyKernel3.zip"
if: ${{ env.useAnykernel == 'true' }}
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
anykernel: "${{ env.WORKSPACE }}/${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}_${{ env.builddate }}"
run: |
ls -al
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz-dtb" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz-dtb ./AnyKernel3/
fi
cd AnyKernel3/
zip -q -r "${{ env.anykernel }}.zip" *
- name: "💾 Upload AnyKernel3 image => (${{ env.builddate }})"
uses: actions/upload-artifact@v3
if: ${{ env.useAnykernel == 'true' }}
with:
name: "${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}_${{ env.builddate }}"
path: AnyKernel3/*
- name: 🧧 Create GitHub Release => (${{ env.builddate }})
continue-on-error: true
uses: softprops/action-gh-release@v1
if: ${{ env.useAnykernel == 'true' && env.release == 'true' }}
with:
tag_name: v${{ env.builddate }}.${{ github.run_number }}
files: "${{ env.WORKSPACE }}/${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}_${{ env.builddate }}.zip"
generate_release_notes: true