Skip to content

Build kernels

Build kernels #13

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/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-latest
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 }}
ccache: ${{ matrix.repos.ccache }}
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 gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi libssl-dev libfl-dev
sudo apt-get install -y curl git ftp lftp wget libarchive-tools ccache python2 python2-dev
sudo apt-get install -y zip unzip tar gzip bzip2 rar unrar
- name: "🚄 Create cache key from `repos`"
if: ${{ env.ccache == 'true' }}
id: ccache_key
run: |
ccache -o compression=false -o cache_dir=$HOME/.ccache
echo "CACHE_KEY=$(echo -n '${{ toJSON(matrix.repos) }}' | base64 -w 0 | cut -c -48)" >> $GITHUB_OUTPUT
- name: "🚅 Cache ccache files"
if: ${{ env.ccache == 'true' }}
uses: actions/cache@v3
with:
path: |
~/.ccache
${{ env.OUT_DIR }}
key: ccache-${{ env.KERNEL_NAME }}-${{ steps.ccache_key.outputs.CACHE_KEY }}-${{ env.builddate }}
restore-keys: |
ccache-${{ env.KERNEL_NAME }}-${{ steps.ccache_key.outputs.CACHE_KEY }}-${{ env.builddate }}
- 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")
# Github
toolchain_repo=$(echo $toolchains | jq -r ".[$i].repo")
toolchain_branch=$(echo $toolchains | jq -r ".[$i].branch")
# From archive
toolchain_url=$(echo $toolchains | jq -r ".[$i].url")
echo $toolchain_url
if [ -z "${toolchain_url:-}" ] || [ "$toolchain_url" = "null" ]; then
git clone --recursive --depth=1 -j $(nproc) --branch $toolchain_branch $toolchain_repo $toolchain_name
echo "🤔 Clone $toolchain_name => ($toolchain_repo)"
else
wget "$toolchain_url"
filename="${toolchain_url##*/}"
mkdir -p $toolchain_name
case "$filename" in
*.zip)
unzip -d $toolchain_name "$filename"
;;
*.tar)
tar xvf "$filename" -C $toolchain_name
;;
*.tar.gz)
tar zxvf "$filename" -C $toolchain_name
;;
*.rar)
unrar x "$filename" $toolchain_name
;;
*)
echo "unknown file type: $filename"
;;
esac
fi
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
if [[ "$CC" == *"/"* ]]; then
CC=${{ env.WORKSPACE }}/$CC
fi
if [ ${{ env.ccache }} = true ]; then
args="$args CC=\"ccache $CC\""
else
args="$args CC=$CC"
fi
fi
while read -r externalCommand; do
key=$(echo "$externalCommand" | cut -d= -f1)
value=$(echo "$externalCommand" | cut -d= -f2)
if [[ "$value" == *"/"* ]]; then
value="${{ env.WORKSPACE }}/$value"
fi
args="$args $key=$value"
done < <(jq -r '.externalCommand | to_entries[] | "\(.key)=\(.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 ${{ env.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 Image.gz-dtb"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: Image.gz-dtb-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz-dtb
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" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image ./AnyKernel3/
fi
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz ./AnyKernel3/
fi
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo ./AnyKernel3/
fi
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo.img" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo.img ./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