action.yml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. name: 'Build Kernel'
  2. description: 'Builds kernel using legacy build.sh or Bazel (kleaf)'
  3. inputs:
  4. bypass:
  5. description: 'Whether to add the bypass hack or not'
  6. required: true
  7. version:
  8. description: 'Kernel config version (e.g., android14-6.1)'
  9. required: true
  10. runs:
  11. using: composite
  12. steps:
  13. - name: 'Build Kernel'
  14. shell: bash
  15. working-directory: ${{ github.workspace }}/kernel
  16. run: |
  17. set -euo pipefail
  18. if [ "${{ inputs.bypass }}" = "true" ]; then
  19. if [[ ${{ inputs.version }} == "android14-6.1" || ${{ inputs.version }} == "android15-6.6" || ${{ inputs.version }} == "android16-6.12" ]]; then
  20. TARGET_FILE="${{ github.workspace }}/kernel/common/kernel/module/version.c"
  21. else
  22. TARGET_FILE="${{ github.workspace }}/kernel/common/kernel/module.c"
  23. fi
  24. sed -i '/bad_version:/{:a;n;/return 0;/{s/return 0;/return 1;/;b};ba}' "$TARGET_FILE"
  25. if ! grep -A 5 "bad_version:" "$TARGET_FILE" | grep -q "return 1;"; then
  26. echo "Patch failed! 'return 1;' not found at bad_version:"
  27. grep -A 10 "bad_version:" "$TARGET_FILE" || true
  28. exit 1
  29. fi
  30. else
  31. echo "Bypass hack not applied as per input parameter."
  32. fi
  33. rm -rf "out"
  34. GKI_KCONFIG_FRAGMENT_PATH="${{ github.workspace }}/wild_gki.fragment"
  35. GKI_DEFCONFIG_WRAPPER_PATH="${{ github.workspace }}/wild_gki.wrap.sh"
  36. cat > "${GKI_DEFCONFIG_WRAPPER_PATH}" <<EOF
  37. append_cmd POST_DEFCONFIG_CMDS 'if [ -f "${GKI_KCONFIG_FRAGMENT_PATH}" ]; then \${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -O \${OUT_DIR} \${OUT_DIR}/.config "${GKI_KCONFIG_FRAGMENT_PATH}"; fi && (cd \${KERNEL_DIR} && make O=\${OUT_DIR} olddefconfig)'
  38. EOF
  39. # Override expensive GKI build.sh artifact defaults we do not need in CI.
  40. GKI_BUILD_CONFIG_FRAGMENT_PATH="${{ github.workspace }}/gki_build_overrides.fragment"
  41. cat > "${GKI_BUILD_CONFIG_FRAGMENT_PATH}" <<'EOF'
  42. BUILD_GKI_ARTIFACTS=
  43. BUILD_GKI_CERTIFICATION_TOOLS=0
  44. BUILD_SYSTEM_DLKM=0
  45. # Skip heavy packaging steps we don't need in CI
  46. SKIP_VENDOR_BOOT=1
  47. SKIP_EXT_MODULES=1
  48. SKIP_CP_KERNEL_HDR=1
  49. SKIP_MRPROPER=1
  50. EOF
  51. if [ -f "build/build.sh" ]; then
  52. #SKIP_MRPROPER=1 \
  53. LTO=thin \
  54. GKI_DEFCONFIG_FRAGMENT="${GKI_DEFCONFIG_WRAPPER_PATH}" \
  55. GKI_BUILD_CONFIG_FRAGMENT="${GKI_BUILD_CONFIG_FRAGMENT_PATH}" \
  56. BUILD_CONFIG=common/build.config.gki.aarch64 \
  57. build/build.sh -j"$(nproc)" \
  58. CC="/usr/bin/ccache clang" \
  59. CXX="/usr/bin/ccache clang+" \
  60. HOSTCC="/usr/bin/ccache clang" \
  61. HOSTCXX="/usr/bin/ccache clang+" \
  62. LD="${{ github.workspace }}/kernel/common/ld-wrapper" \
  63. HOSTLD="${{ github.workspace }}/kernel/common/ld-wrapper"
  64. else
  65. tools/bazel info output_base
  66. cp "${{ github.workspace }}/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
  67. tools/bazel build \
  68. --linkopt="--thinlto-cache-dir=/home/runner/.ld_cache" \
  69. --config=local \
  70. --defconfig_fragment=//common:arch/arm64/configs/wild_gki.fragment \
  71. --disk_cache=/home/runner/.cache/bazel/disk \
  72. //common:kernel_aarch64
  73. tools/bazel info output_base
  74. fi
  75. ls
  76. ls out
  77. - name: 'Gather Build Artifacts'
  78. shell: bash
  79. working-directory: ${{ github.workspace }}
  80. run: |
  81. set -euo pipefail
  82. PATCH_FILE="${{ github.action_path }}/patches/bypass.patch"
  83. if [ -f "$PATCH_FILE" ]; then
  84. patch -d "${{ github.workspace }}/AnyKernel3" -p1 < "$PATCH_FILE"
  85. fi
  86. if [ -f "${{ github.workspace }}/kernel/out/${{ inputs.version }}/dist/Image" ]; then
  87. if [[ ${{ inputs.bypass }} == "true" ]]; then
  88. cp "${{ github.workspace }}/kernel/out/${{ inputs.version }}/dist/Image" "${{ github.workspace }}/AnyKernel3/Bypass-Image"
  89. else
  90. cp "${{ github.workspace }}/kernel/out/${{ inputs.version }}/dist/Image" "${{ github.workspace }}/AnyKernel3/Image"
  91. fi
  92. exit 0
  93. fi
  94. if [ -f "${{ github.workspace }}/kernel/bazel-bin/common/kernel_aarch64/Image" ]; then
  95. if [[ ${{ inputs.bypass }} == "true" ]]; then
  96. cp "${{ github.workspace }}/kernel/bazel-bin/common/kernel_aarch64/Image" "${{ github.workspace }}/AnyKernel3/Bypass-Image"
  97. else
  98. cp "${{ github.workspace }}/kernel/bazel-bin/common/kernel_aarch64/Image" "${{ github.workspace }}/AnyKernel3/Image"
  99. fi
  100. exit 0
  101. fi
  102. exit 1