Compile the kernel using docker #147
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #========================================================================== | |
| # Description: Compile the kernel using docker | |
| # Copyright (C) 2021 https://github.com/unifreq/openwrt_packit | |
| # Copyright (C) 2021 https://github.com/ophub/amlogic-s9xxx-armbian | |
| #========================================================================== | |
| name: Compile the kernel using docker | |
| on: | |
| repository_dispatch: | |
| workflow_dispatch: | |
| inputs: | |
| kernel_source: | |
| description: "Select the kernel source" | |
| required: false | |
| default: "unifreq" | |
| type: choice | |
| options: | |
| - unifreq | |
| - codesnas | |
| kernel_version: | |
| description: "Select kernel version" | |
| required: false | |
| default: "6.12.y" | |
| type: choice | |
| options: | |
| - 5.4.y | |
| - 5.10.y | |
| - 5.15.y | |
| - 6.1.y | |
| - 6.6.y | |
| - 6.12.y | |
| kernel_auto: | |
| description: "Auto use the latest kernel" | |
| required: false | |
| default: true | |
| type: boolean | |
| delete_source: | |
| description: "Delete the source after compilation" | |
| required: false | |
| default: true | |
| type: boolean | |
| kernel_package: | |
| description: "Select compile package list" | |
| required: false | |
| default: "all" | |
| type: choice | |
| options: | |
| - all | |
| - dtbs | |
| kernel_toolchain: | |
| description: "Select the compilation toolchain" | |
| required: false | |
| default: "gcc" | |
| type: choice | |
| options: | |
| - clang | |
| - gcc | |
| - gcc-14.2 | |
| - gcc-14.3 | |
| ccache_clear: | |
| description: "Set whether to clear the cache" | |
| required: false | |
| default: false | |
| type: boolean | |
| docker_image: | |
| description: "Select Armbian docker image" | |
| required: false | |
| default: "trixie" | |
| type: choice | |
| options: | |
| - trixie | |
| - bookworm | |
| - noble | |
| - jammy | |
| kernel_sign: | |
| description: "Set the kernel custom signature" | |
| required: false | |
| default: "-ophub" | |
| type: choice | |
| options: | |
| - -ophub | |
| - -yourname | |
| env: | |
| TZ: Etc/UTC | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04-arm | |
| if: ${{ github.event.repository.owner.id }} == ${{ github.event.sender.id }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Initialization environment | |
| id: init | |
| env: | |
| DEBIAN_FRONTEND: noninteractive | |
| run: | | |
| docker rmi -f $(docker images -q) 2>/dev/null || true | |
| [[ -n "${AGENT_TOOLSDIRECTORY}" ]] && sudo rm -rf "${AGENT_TOOLSDIRECTORY}" | |
| sudo rm -rf /usr/share/dotnet /usr/local/lib/android 2>/dev/null | |
| sudo swapoff -a | |
| sudo rm -f /swapfile /mnt/swapfile | |
| sudo -E apt-get -y update | |
| sudo -E apt-get -y purge azure-cli ghc* zulu* llvm* firefox google* dotnet* powershell openjdk* mongodb* moby* || true | |
| sudo -E apt-get -y install $(curl -fsSL https://ophub.org/ubuntu2404-build-armbian-depends) | |
| sudo -E systemctl daemon-reload | |
| #sudo -E apt-get -y full-upgrade | |
| sudo -E apt-get -y autoremove --purge | |
| sudo -E apt-get clean | |
| sudo sed -i '/NVM_DIR/d;/skel/d' /root/{.bashrc,.profile} | |
| sudo rm -rf ~/{.cargo,.dotnet,.rustup} | |
| sudo -E timedatectl set-timezone "${TZ:-Etc/UTC}" | |
| sudo -E ntpdate ntp.ubuntu.com 0.pool.ntp.org || true | |
| sudo -E timedatectl set-ntp true | |
| date -u | |
| timedatectl status || true | |
| echo "status=success" >> ${GITHUB_OUTPUT} | |
| - name: Create simulated physical disk | |
| id: disk | |
| run: | | |
| mnt_size=$(expr $(df -h /mnt | tail -1 | awk '{print $4}' | sed 's/[[:alpha:]]//g' | sed 's/\..*//') - 1) | |
| root_size=$(expr $(df -h / | tail -1 | awk '{print $4}' | sed 's/[[:alpha:]]//g' | sed 's/\..*//') - 4) | |
| sudo truncate -s "${mnt_size}"G /mnt/mnt.img | |
| sudo truncate -s "${root_size}"G /root.img | |
| sudo losetup /dev/loop6 /mnt/mnt.img | |
| sudo losetup /dev/loop7 /root.img | |
| sudo pvcreate /dev/loop6 | |
| sudo pvcreate /dev/loop7 | |
| sudo vgcreate github /dev/loop6 /dev/loop7 | |
| sudo lvcreate -n runner -l 100%FREE github | |
| sudo mkfs.xfs -f -i sparse=0 -b size=4096 /dev/github/runner | |
| sudo mkdir -p /builder | |
| sudo mount /dev/github/runner /builder | |
| sudo chown -R runner:runner /builder | |
| df -Th | |
| echo "status=success" >> ${GITHUB_OUTPUT} | |
| - name: Install Docker | |
| id: install | |
| working-directory: /builder | |
| if: ${{ steps.disk.outputs.status }} == 'success' && !cancelled() | |
| run: | | |
| df -hT ${PWD} | |
| curl -fsSL https://get.docker.com | sh | |
| sudo usermod -aG docker $USER | |
| sudo newgrp docker | |
| echo "status=success" >> ${GITHUB_OUTPUT} | |
| - name: Pull Docker Image [ ${{ inputs.docker_image }} ] | |
| id: pull | |
| working-directory: /builder | |
| if: ${{ steps.install.outputs.status }} == 'success' && !cancelled() | |
| run: | | |
| # Create a docker mapping directory | |
| mkdir -p /builder/{compile-kernel/{kernel,output},ccache} | |
| ln -sf /builder/compile-kernel/kernel /home/runner/work/_actions/ophub/amlogic-s9xxx-armbian/main/compile-kernel/kernel | |
| ln -sf /builder/compile-kernel/output /home/runner/work/_actions/ophub/amlogic-s9xxx-armbian/main/compile-kernel/output | |
| # Pull the Armbian Docker image | |
| docker run -d --privileged \ | |
| --name armbian-ophub \ | |
| -v /builder/compile-kernel:/opt/kernel/compile-kernel \ | |
| -v /builder/ccache:/root/.ccache \ | |
| -v /etc/localtime:/etc/localtime:ro \ | |
| -v /etc/timezone:/etc/timezone:ro \ | |
| -e CCACHE_DIR=/root/.ccache \ | |
| --restart=always \ | |
| ophub/armbian-${{ inputs.docker_image }}:arm64 | |
| echo "status=success" >> ${GITHUB_OUTPUT} | |
| - name: Get kernel source hash | |
| id: kernelhash | |
| if: ${{ steps.pull.outputs.status }} == 'success' && !cancelled() | |
| run: | | |
| # Get the latest source hash from the kernel repository | |
| api_url="https://api.github.com/repos/${{ inputs.kernel_source }}/linux-${{ inputs.kernel_version }}/git/ref/heads/main" | |
| source_hash=$(curl -fsSL -m 20 \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| ${api_url} | | |
| jq -r '.object.sha' | |
| ) | |
| [[ -z "${source_hash}" || "${source_hash}" == "null" ]] && source_hash="${{ github.sha }}" | |
| echo "source_hash=${source_hash}" >> ${GITHUB_ENV} | |
| echo "status=success" >> ${GITHUB_OUTPUT} | |
| - name: Cache ccache | |
| uses: actions/cache@v4 | |
| with: | |
| path: /builder/ccache | |
| key: kernel-${{ inputs.kernel_toolchain }}-${{ inputs.kernel_version }}-${{ env.source_hash }} | |
| restore-keys: | | |
| kernel-${{ inputs.kernel_toolchain }}-${{ inputs.kernel_version }}- | |
| - name: Compile the kernel [ ${{ inputs.kernel_version }} ] | |
| uses: ophub/amlogic-s9xxx-armbian@main | |
| if: ${{ steps.pull.outputs.status }} == 'success' && !cancelled() | |
| with: | |
| build_target: kernel | |
| kernel_source: ${{ inputs.kernel_source }} | |
| kernel_version: ${{ inputs.kernel_version }} | |
| kernel_auto: ${{ inputs.kernel_auto }} | |
| delete_source: ${{ inputs.delete_source }} | |
| kernel_package: ${{ inputs.kernel_package }} | |
| kernel_sign: ${{ inputs.kernel_sign }} | |
| kernel_toolchain: ${{ inputs.kernel_toolchain }} | |
| ccache_clear: ${{ inputs.ccache_clear }} | |
| - name: Upload Kernel to Release | |
| uses: ncipollo/release-action@main | |
| if: ${{ env.PACKAGED_STATUS }} == 'success' && !cancelled() | |
| with: | |
| tag: kernel_stable | |
| artifacts: ${{ env.PACKAGED_OUTPUTPATH }}/* | |
| allowUpdates: true | |
| removeArtifacts: false | |
| replacesArtifacts: true | |
| makeLatest: false | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| - These are Mainline LTS(Long Term Support) kernels that provide `stable` support for Armbian. | |
| - It works with most `Amlogic`, `Rockchip`, and `Allwinner` devices. For specific details, please refer to the instructions on the homepage of repository. | |
| - Dedicated BSP kernels for other Rockchip and Allwinner devices can be downloaded from the [ophub/kernel](https://github.com/ophub/kernel) repository. | |
| - 这些是主线 LTS(长期支持)内核,为 Armbian 提供`稳定`的支持。 | |
| - 适用于 `amlogic`,`rockchip`,`allwinner` 的大部分设备,具体可以参考仓库首页的说明。 | |
| - 其他的 Rockchip 和 Allwinner 设备专用 BSP 内核可以在 [ophub/kernel](https://github.com/ophub/kernel) 仓库里下载使用。 |