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