Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Syahrial Agni Prasetya committed Jun 25, 2021
0 parents commit abe715d
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM docker.io/library/ubuntu:focal
ENV DEBIAN_FRONTEND noninteractive
RUN set -ex; \
apt update; \
apt upgrade -y;
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Android Kernel Actions

Builds Android kernel from the kernel repository.

## Action inputs

| Input | Description |
| --- | --- |
| `arch` | Specify what Architecture target to use, currently only supports `arm64` |
| `compiler` | Specify which compiler to use, currently only supports `gcc-*` from Ubuntu repository |
| `zipper` | Specify the git repository of the flashable zip template, using [osm0sis's AnyKernel3](https://github.com/osm0sis/AnyKernel3) as base is recommended |
| `defconfig` | Specify what defconfig command to generate `.config` file |
| `image` | Specify what is the final build file, usually it's `Image.gz-dtb` or '`Image-dtb`' |

## Getting the build

You can use other actions to grab the flashable zip file and releases it.

## Available toolchains

### ARM64

- `gcc-7`
- `gcc-8`
- `gcc-9`
- `gcc-10`
- `clang-6.0`
- `clang-7`
- `clang-8`
- `clang-9`
- `clang-10`
- `clang-11`

## Example usage

### With [`ncipollo/release-action@v1`](https://github.com/ncipollo/release-action)
```yml
name: Build on Tag

on:
push:
tags: '*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Android kernel build
uses: lemniskett/android-kernel-actions@master
id: build
with:
arch: 'arm64'
compiler: 'gcc-9'
zipper: 'github.com/lemniskett/AnyKernel3'
defconfig: 'vince_defconfig'
image: 'Image.gz-dtb'

- uses: ncipollo/release-action@v1
with:
artifacts: ${{ steps.build.outputs.outfile }}
token: ${{ secrets.GITHUB_TOKEN }}
```
## Troubleshooting
### Error codes
- `1`: Packages fails to install
- `2`: .config fails to be generated
- `3`: Build fails
- `100`: Unsupported usage
- `127`: Unexpected error
34 changes: 34 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Android kernel build'
description: 'Build android kernel with GitHub Action'
author: 'Syahrial Agni Prasetya <[email protected]>'
branding:
icon: 'box'
color: 'green'
inputs:
arch:
description: 'Device architecture'
required: true
compiler:
description: 'Compiler to use'
required: true
zipper:
description: 'Zipper repository'
required: true
defconfig:
description: 'Defconfig to use'
required: true
image:
description: 'Kernel image name'
required: true
outputs:
outfile:
description: 'Zip file generated from build'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.arch }}
- ${{ inputs.compiler }}
- ${{ inputs.zipper }}
- ${{ inputs.defconfig }}
- ${{ inputs.image }}
90 changes: 90 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash

msg(){
echo "==> $*"
}

err(){
echo "==> $*" 1>&2
}

outfile(){
echo "::set-output name=outfile::$*"
}

workdir="$GITHUB_WORKSPACE"
arch="$1"
compiler="$2"
zipper="$3"
defconfig="$4"
image="$5"
tag="${GITHUB_REF/refs\/tags\//}"
repo_name="${GITHUB_REPOSITORY/*\/}"
zipper_path="zipper"

msg "Updating container..."
apt update && apt upgrade -y
msg "Installing essential packages..."
apt install git make bc bison curl zip kmod cpio flex libelf-dev libssl-dev libtfm-dev
msg "Installing toolchain..."
if [[ $arch = "arm64" ]]; then
if [[ $compiler = gcc-* ]]; then
if ! apt install "$compiler" "$compiler"-aarch64-linux-gnu "$compiler"-arm-linux-gnueabi; then
err "Compiler package not found, refer to the README for details"
exit 1
fi
ln -sf /usr/bin/"$compiler" /usr/bin/gcc
ln -sf /usr/bin/aarch64-linux-gnu-"$compiler" /usr/bin/aarch64-linux-gnu-gcc
ln -sf /usr/bin/arm-linux-gnueabi-"$compiler" /usr/bin/arm-linux-gnueabi-gcc
export ARCH="$arch"
export SUBARCH="$arch"
export CROSS_COMPILE="aarch64-linux-gnu-"
export CROSS_COMPILE_ARM32="arm-linux-gnueabi-"
make_opts="O=out"
elif [[ $compiler = clang-* ]]; then
compiler_version="${compiler/*-}"
if ! apt install "$compiler" lld-"$compiler_version" gcc gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi; then
err "Compiler package not found, refer to the README for details"
exit 1
fi
ln -sf /usr/bin/"$compiler" /usr/bin/clang
ln -sf /usr/bin/ld.lld-"$compiler_version" /usr/bin/ld.lld
ln -sf /usr/bin/llvm-ar-"$compiler_version" /usr/bin/llvm-ar
ln -sf /usr/bin/llvm-nm-"$compiler_version" /usr/bin/llvm-nm
ln -sf /usr/bin/llvm-strip-"$compiler_version" /usr/bin/llvm-strip
ln -sf /usr/bin/llvm-objcopy-"$compiler_version" /usr/bin/llvm-objcopy
ln -sf /usr/bin/llvm-objdump-"$compiler_version" /usr/bin/llvm-objdump
ln -sf /usr/bin/llvm-readelf-"$compiler_version" /usr/bin/llvm-readelf
export ARCH="$arch"
export SUBARCH="$arch"
export CLANG_TRIPLE="aarch64-linux-gnu-"
export CROSS_COMPILE="aarch64-linux-gnu-"
export CROSS_COMPILE_ARM32="arm-linux-gnueabi-"
make_opts="O=out CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf"
else
err "Currently this action only supports gcc-* and clang-*, refer to the README for more detail"
exit 100
fi
else
err "Currently this action only supports arm64, refer to the README for more detail"
exit 100
fi

msg "Generating defconfig from \`make $defconfig\`..."
if ! make "$make_opts" "$defconfig"; then
err "Failed generating .config, make sure it is actually available in arch/${arch}/configs/ and is a valid defconfig file"
exit 2
fi
msg "Begin building kernel..."
if ! make "$make_opts" -j"$(nproc --all)"; then
err "Failed building kernel, is the toolchain compatible with the kernel?"
exit 3
fi
msg "Packaging the kernel..."
zip_filename="${repo_name}-${tag}.zip"
git clone "$zipper" $zipper_path || exit 127
cp out/arch/"$arch"/boot/"$image" "$zipper_path"/"$image"
cd $zipper_path || exit 127
zip -r9 "$zip_filename" . -x '*.git' || exit 127
outfile "$zipper_path"/"$zip_filename"
cd "$workdir" || exit 127

0 comments on commit abe715d

Please sign in to comment.