π§ Build kernel #5
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
| name: π§ Build linux kernel | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| config: | |
| description: 'π Kernel config name (ej: config-6.10.7-debian12)' | |
| required: true | |
| default: 'config-6.10.7-debian12' | |
| patch: | |
| description: 'π§© Optional patch name (from patchs/ in repo)' | |
| required: false | |
| default: '' | |
| localversion: | |
| description: 'π Local version name (ej: -custom, -local..)' | |
| required: true | |
| default: '' | |
| tag: | |
| description: 'π·οΈ Git tag from torvalds/linux repo (used if no URL)' | |
| required: false | |
| default: '' | |
| url: | |
| description: 'π¦ Kernel tarball URL (.tar.gz or .tar.xz)' | |
| required: false | |
| default: '' | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-kernel: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: π§Ή Clean up space | |
| run: | | |
| sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache | |
| df -h | |
| - name: βοΈ Install build dependencies | |
| run: | | |
| sudo apt update -qq | |
| sudo apt install -y git build-essential fakeroot bc bison flex libelf-dev libssl-dev \ | |
| libncurses5-dev libncurses-dev dwarves debhelper rsync python3 ccache curl jq patch | |
| - name: π₯ Download kernel tarball | |
| if: ${{ inputs.url != '' }} | |
| id: download_tarball | |
| run: | | |
| FILENAME=$(basename "${{ inputs.url }}") | |
| EXT="${FILENAME##*.}" | |
| if [[ "$EXT" != "gz" && "$EXT" != "xz" ]]; then | |
| echo "β Only .tar.gz or .tar.xz are allowed" | |
| exit 1 | |
| fi | |
| echo "β¬οΈ Downloading kernel package..." | |
| curl -L -o kernel_package.tar."$EXT" "${{ inputs.url }}" | |
| mkdir -p kernel_build | |
| tar -xf kernel_package.tar."$EXT" -C kernel_build --strip-components=1 | |
| TAG=$(echo "$FILENAME" | sed -E 's/linux-([0-9]+\.[0-9]+\.[0-9]+)\.tar\.(gz|xz)/\1/') | |
| echo "kernel_tag=$TAG" >> $GITHUB_ENV | |
| - name: π₯ Clone torvalds/linux repo | |
| if: ${{ inputs.url == '' }} | |
| id: clone_repo | |
| run: | | |
| git clone --depth 1 --branch ${{ inputs.tag }} https://github.com/torvalds/linux kernel_build | |
| echo "kernel_tag=${{ inputs.tag }}" >> $GITHUB_ENV | |
| - name: π Download .config and optional patch from GitHub | |
| run: | | |
| CONFIG_INPUT="${{ inputs.config }}" | |
| PATCH_INPUT="${{ inputs.patch }}" | |
| mkdir -p kernel_build | |
| # Descargar .config | |
| CONFIG_URL="https://raw.githubusercontent.com/azagramac/build-kernel-linux/refs/heads/master/configs/${CONFIG_INPUT}" | |
| echo "β¬οΈ Downloading config from $CONFIG_URL..." | |
| curl -L -o kernel_build/.config "$CONFIG_URL" | |
| # Descargar patch solo si se pasa | |
| if [ -n "$PATCH_INPUT" ]; then | |
| PATCH_URL="https://raw.githubusercontent.com/azagramac/build-kernel-linux/refs/heads/master/patchs/${PATCH_INPUT}" | |
| echo "β¬οΈ Downloading patch from $PATCH_URL..." | |
| if curl -L -f -o kernel_build/patch_file.patch "$PATCH_URL"; then | |
| echo "β Patch downloaded successfully" | |
| else | |
| echo "β οΈ Patch $PATCH_INPUT not found, skipping..." | |
| fi | |
| fi | |
| - name: π§ Apply kernel config | |
| run: | | |
| cd kernel_build | |
| echo "π§ Applying configuration..." | |
| scripts/config --enable IKHEADERS | |
| scripts/config --enable DEBUG_INFO | |
| make olddefconfig | |
| - name: π§© Apply patch | |
| run: | | |
| cd kernel_build | |
| if [ -f patch_file.patch ]; then | |
| echo "π§ Applying patch patch_file.patch" | |
| patch -p1 < patch_file.patch || true | |
| else | |
| echo "β οΈ No patch to apply, continuing build" | |
| fi | |
| - name: π Show kernel version | |
| run: | | |
| cd kernel_build | |
| echo "π·οΈ Kernel to be built: $(make kernelrelease)" | |
| - name: π§ Build kernel | |
| run: | | |
| cd kernel_build | |
| make -j$(nproc) bindeb-pkg LOCALVERSION=${{ inputs.localversion }} KDEB_PKGVERSION=1 | |
| - name: π Get compiled kernel version | |
| id: get_version | |
| run: | | |
| cd kernel_build | |
| echo "version=$(make kernelrelease)" >> $GITHUB_OUTPUT | |
| - name: π¦ Move .deb artifacts | |
| run: | | |
| mkdir -p artifacts | |
| find .. -name "*.deb" -exec cp {} artifacts/ \; | |
| find .. -name "*.changes" -exec cp {} artifacts/ \; | |
| find .. -name "*.buildinfo" -exec cp {} artifacts/ \; | |
| - name: π Read .changes for release body | |
| id: release_body | |
| run: | | |
| CHANGES_FILE=$(find artifacts -name "*.changes" | head -n1) | |
| BODY=$(cat "$CHANGES_FILE") | |
| echo "body<<EOF" >> $GITHUB_OUTPUT | |
| echo "$BODY" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: π Upload Linux Kernel | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: kernel-${{ github.run_number }} | |
| name: "Kernel ${{ steps.get_version.outputs.version }}" | |
| body: ${{ steps.release_body.outputs.body }} | |
| files: artifacts/*.deb | |
| overwrite_files: true | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |