prepare.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. name: Prepare and Build
  2. on:
  3. workflow_call:
  4. inputs:
  5. config_file:
  6. description: "Path to the JSON config file"
  7. required: true
  8. type: string
  9. feature_set:
  10. description: "Feature Set"
  11. required: false
  12. type: string
  13. ksu_branch:
  14. description: "KernelSU branch or commit (empty = latest dev)"
  15. required: false
  16. type: string
  17. default: ""
  18. susfs_commit:
  19. description: "SUSFS commit hash (empty = latest on auto-derived branch)"
  20. required: false
  21. type: string
  22. default: ""
  23. root_flavor:
  24. description: "Mutually exclusive root implementation (classic, next, or resukisu)"
  25. required: false
  26. type: string
  27. default: ""
  28. root_commit:
  29. description: "Exact root implementation commit"
  30. required: false
  31. type: string
  32. default: ""
  33. nomount_commit:
  34. description: "Exact NoMount commit"
  35. required: false
  36. type: string
  37. default: ""
  38. preserve_abi:
  39. description: "Keep ABI/KMI protection files intact and verify their hashes"
  40. required: false
  41. type: boolean
  42. default: false
  43. build_bypass:
  44. description: "Produce the legacy bypass image"
  45. required: false
  46. type: boolean
  47. default: true
  48. os_patch_level:
  49. description: "Optional filter: patch date (YYYY-MM), kernel sublevel, latest, or all"
  50. required: false
  51. type: string
  52. default: ""
  53. variant:
  54. description: "Artifact variant label"
  55. required: false
  56. type: string
  57. default: ""
  58. jobs:
  59. generate-matrix:
  60. runs-on: ubuntu-latest
  61. outputs:
  62. matrix: ${{ steps.final.outputs.matrix }}
  63. steps:
  64. - name: Checkout Repository
  65. uses: actions/checkout@v7
  66. - name: Read Config and Build Final Matrix
  67. id: final
  68. shell: bash
  69. run: |
  70. if [ ! -f "${{ inputs.config_file }}" ]; then
  71. echo "Error: Config file not found: ${{ inputs.config_file }}"
  72. exit 1
  73. fi
  74. CONFIG_JSON=$(cat "${{ inputs.config_file }}" | jq -c .)
  75. # Build { "include": [ {android_version:..., kernel_version:..., sublevel:..., os_patch_level:..., variant: ...}, ... ] }.
  76. # An explicit patch-level filter keeps manual validation dispatches bounded.
  77. FINAL=$(jq -cn \
  78. --argjson cfg "$CONFIG_JSON" \
  79. --arg requested_variant "${{ inputs.variant }}" '
  80. ($cfg.version | split("-")) as $version_parts
  81. | ($cfg.include) as $targets
  82. | {
  83. include: (
  84. [
  85. $targets[] as $item
  86. | {
  87. version: $cfg.version,
  88. android_version: $version_parts[0],
  89. kernel_version: $version_parts[1],
  90. sublevel: $item.sublevel,
  91. os_patch_level: $item.date,
  92. variant: (if $requested_variant == "" then "Normal" else $requested_variant end)
  93. }
  94. ]
  95. + (if $requested_variant == "" then [
  96. $targets[] as $item
  97. | select($item.variant != null)
  98. | {
  99. version: $cfg.version,
  100. android_version: $version_parts[0],
  101. kernel_version: $version_parts[1],
  102. sublevel: $item.sublevel,
  103. os_patch_level: $item.date,
  104. variant: $item.variant
  105. }
  106. ] else [] end)
  107. | unique_by([.android_version, .kernel_version, .sublevel, .os_patch_level, .variant])
  108. )
  109. }')
  110. SELECTED_PATCH_LEVEL="${{ inputs.os_patch_level }}"
  111. if [ "$SELECTED_PATCH_LEVEL" = "all" ]; then
  112. SELECTED_PATCH_LEVEL=""
  113. elif [ "$SELECTED_PATCH_LEVEL" = "latest" ]; then
  114. SELECTED_PATCH_LEVEL=$(jq -r '[.include[] | select(.date != "lts") | .date] | last // empty' "${{ inputs.config_file }}")
  115. fi
  116. if [ -n "$SELECTED_PATCH_LEVEL" ]; then
  117. FULL_FINAL="$FINAL"
  118. FINAL=$(jq -c --arg patch_level "$SELECTED_PATCH_LEVEL" '
  119. {include: [.include[] | select(.os_patch_level == $patch_level)]}
  120. ' <<< "$FINAL")
  121. # No date matched -- try interpreting the value as a kernel sublevel
  122. if [ "$(jq '.include | length' <<< "$FINAL")" -eq 0 ]; then
  123. FINAL=$(jq -c --arg sublevel "$SELECTED_PATCH_LEVEL" '
  124. {include: [.include[] | select(.sublevel == $sublevel)]}
  125. ' <<< "$FULL_FINAL")
  126. fi
  127. fi
  128. if [ "$(jq '.include | length' <<< "$FINAL")" -eq 0 ]; then
  129. echo "Error: no build targets match patch level '${SELECTED_PATCH_LEVEL}'." >&2
  130. exit 1
  131. fi
  132. echo "matrix=$FINAL" >> "$GITHUB_OUTPUT"
  133. build:
  134. needs: generate-matrix
  135. strategy:
  136. fail-fast: false
  137. matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
  138. uses: ./.github/workflows/build.yml
  139. with:
  140. version: ${{ matrix.version }}
  141. android_version: ${{ matrix.android_version }}
  142. kernel_version: ${{ matrix.kernel_version }}
  143. sublevel: ${{ matrix.sublevel }}
  144. os_patch_level: ${{ matrix.os_patch_level }}
  145. variant: ${{ matrix.variant }}
  146. feature_set: ${{ inputs.feature_set }}
  147. ksu_branch: ${{ inputs.ksu_branch }}
  148. susfs_commit: ${{ inputs.susfs_commit }}
  149. root_flavor: ${{ inputs.root_flavor }}
  150. root_commit: ${{ inputs.root_commit }}
  151. nomount_commit: ${{ inputs.nomount_commit }}
  152. preserve_abi: ${{ inputs.preserve_abi }}
  153. build_bypass: ${{ inputs.build_bypass }}
  154. secrets: inherit