kernel.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. name: Build Kernel
  2. on:
  3. pull_request:
  4. paths:
  5. - '.github/workflows/check-kernel-patches.yml'
  6. - '.github/workflows/build.yml'
  7. - '.github/workflows/kernel.yml'
  8. - 'include/kernel*'
  9. - 'package/kernel/**'
  10. - 'target/linux/**'
  11. push:
  12. paths:
  13. - '.github/workflows/check-kernel-patches.yml'
  14. - '.github/workflows/build.yml'
  15. - '.github/workflows/kernel.yml'
  16. - 'include/kernel*'
  17. - 'package/kernel/**'
  18. - 'target/linux/**'
  19. branches-ignore:
  20. - master
  21. permissions:
  22. contents: read
  23. concurrency:
  24. group: ${{ github.workflow }}-${{ github.ref }}
  25. cancel-in-progress: ${{ github.event_name == 'pull_request' }}
  26. jobs:
  27. determine_targets:
  28. name: Set targets
  29. runs-on: ubuntu-latest
  30. outputs:
  31. targets_subtargets: ${{ steps.find_targets.outputs.targets_subtargets }}
  32. targets: ${{ steps.find_targets.outputs.targets }}
  33. steps:
  34. - name: Checkout
  35. uses: actions/checkout@v3
  36. with:
  37. fetch-depth: 2
  38. - name: Get changed files
  39. id: changed-files
  40. uses: tj-actions/changed-files@v35
  41. - name: Set targets
  42. id: find_targets
  43. run: |
  44. ALL_TARGETS="$(perl ./scripts/dump-target-info.pl targets 2>/dev/null)"
  45. CHANGED_FILES="$(echo ${{ steps.changed-files.outputs.all_changed_files }} | tr ' ' '\n')"
  46. TARGETS_SUBTARGETS="$(echo "$ALL_TARGETS" | sort -u -t '/' -k1 | awk '{ print $1 }')"
  47. TARGETS="$(echo "$ALL_TARGETS" | sort -u -t '/' -k1,1 | awk '{ print $1 }')"
  48. # On testing non-specific target, skip testing each subtarget if we are testing pr
  49. if [ ${{ github.event_name }} != 'push' ]; then
  50. if echo "$CHANGED_FILES" | grep -v -q target/linux ||
  51. echo "$CHANGED_FILES" | grep -q target/linux/generic; then
  52. TARGETS_SUBTARGETS=$TARGETS
  53. fi
  54. fi
  55. JSON_TARGETS_SUBTARGETS='['
  56. FIRST=1
  57. for TARGET in $TARGETS_SUBTARGETS; do
  58. if echo "$CHANGED_FILES" | grep -v -q target/linux ||
  59. echo "$CHANGED_FILES" | grep -q target/linux/generic ||
  60. echo "$CHANGED_FILES" | grep -q $(echo $TARGET | cut -d "/" -f 1); then
  61. TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
  62. [[ $FIRST -ne 1 ]] && JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"','
  63. JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS""$TUPLE"
  64. FIRST=0
  65. fi
  66. done
  67. JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"']'
  68. JSON_TARGETS='['
  69. FIRST=1
  70. for TARGET in $TARGETS; do
  71. if echo "$CHANGED_FILES" | grep -v -q target/linux ||
  72. echo "$CHANGED_FILES" | grep -q target/linux/generic ||
  73. echo "$CHANGED_FILES" | grep -q $(echo $TARGET | cut -d "/" -f 1); then
  74. TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
  75. [[ $FIRST -ne 1 ]] && JSON_TARGETS="$JSON_TARGETS"','
  76. JSON_TARGETS="$JSON_TARGETS""$TUPLE"
  77. FIRST=0
  78. fi
  79. done
  80. JSON_TARGETS="$JSON_TARGETS"']'
  81. echo -e "\n---- targets to build ----\n"
  82. echo "$JSON_TARGETS_SUBTARGETS"
  83. echo -e "\n---- targets to build ----\n"
  84. echo -e "\n---- targets to check patch ----\n"
  85. echo "$JSON_TARGETS"
  86. echo -e "\n---- targets to check patch ----\n"
  87. echo "targets_subtargets=$JSON_TARGETS_SUBTARGETS" >> $GITHUB_OUTPUT
  88. echo "targets=$JSON_TARGETS" >> $GITHUB_OUTPUT
  89. build:
  90. name: Build Kernel with external toolchain
  91. needs: determine_targets
  92. permissions:
  93. contents: read
  94. packages: read
  95. actions: write
  96. strategy:
  97. fail-fast: False
  98. matrix:
  99. include: ${{fromJson(needs.determine_targets.outputs.targets_subtargets)}}
  100. uses: ./.github/workflows/build.yml
  101. with:
  102. container_name: toolchain
  103. target: ${{ matrix.target }}
  104. subtarget: ${{ matrix.subtarget }}
  105. build_kernel: true
  106. build_all_kmods: true
  107. upload_ccache_cache: ${{ github.repository_owner == 'openwrt' }}
  108. check-kernel-patches:
  109. name: Check Kernel patches
  110. needs: determine_targets
  111. permissions:
  112. contents: read
  113. packages: read
  114. strategy:
  115. fail-fast: False
  116. matrix:
  117. include: ${{fromJson(needs.determine_targets.outputs.targets)}}
  118. uses: ./.github/workflows/check-kernel-patches.yml
  119. with:
  120. target: ${{ matrix.target }}
  121. subtarget: ${{ matrix.subtarget }}
  122. upload-ccache-cache-in-s3:
  123. if: github.event_name == 'push' && github.repository_owner == 'openwrt'
  124. name: Upload ccache cache to s3
  125. needs: [determine_targets, build]
  126. strategy:
  127. fail-fast: False
  128. matrix:
  129. include: ${{fromJson(needs.determine_targets.outputs.targets_subtargets)}}
  130. secrets:
  131. s3_access_key: ${{ secrets.GCS_S3_ACCESS_KEY }}
  132. s3_secret_key: ${{ secrets.GCS_S3_SECRET_KEY }}
  133. uses: ./.github/workflows/upload-file-s3.yml
  134. with:
  135. endpoint: https://storage.googleapis.com
  136. bucket: openwrt-ci-cache
  137. download_id: ${{ matrix.target }}-${{ matrix.subtarget }}-ccache-cache
  138. filename: ccache-kernel-${{ matrix.target }}-${{ matrix.subtarget }}.tar