CI: rework build workflow to have split target and subtarget directly
[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 TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
68 [[ $FIRST -ne 1 ]] && JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"','
69 JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS""$TUPLE"
70 FIRST=0
71 fi
72 done
73 JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"']'
74
75 JSON_TARGETS='['
76 FIRST=1
77 for TARGET in $TARGETS; do
78 if echo "$CHANGED_FILES" | grep -v -q target/linux ||
79 echo "$CHANGED_FILES" | grep -q target/linux/generic ||
80 echo "$CHANGED_FILES" | grep -q $(echo $TARGET | cut -d "/" -f 1); then
81 TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
82 [[ $FIRST -ne 1 ]] && JSON_TARGETS="$JSON_TARGETS"','
83 JSON_TARGETS="$JSON_TARGETS""$TUPLE"
84 FIRST=0
85 fi
86 done
87 JSON_TARGETS="$JSON_TARGETS"']'
88
89 echo -e "\n---- targets to build ----\n"
90 echo "$JSON_TARGETS_SUBTARGETS"
91 echo -e "\n---- targets to build ----\n"
92
93 echo -e "\n---- targets to check patch ----\n"
94 echo "$JSON_TARGETS"
95 echo -e "\n---- targets to check patch ----\n"
96
97 echo "targets_subtargets=$JSON_TARGETS_SUBTARGETS" >> $GITHUB_OUTPUT
98 echo "targets=$JSON_TARGETS" >> $GITHUB_OUTPUT
99
100 build:
101 name: Build Kernel with external toolchain
102 needs: determine_targets
103 permissions:
104 contents: read
105 packages: read
106 strategy:
107 fail-fast: False
108 matrix:
109 include: ${{fromJson(needs.determine_targets.outputs.targets_subtargets)}}
110 uses: ./.github/workflows/build.yml
111 with:
112 target: ${{ matrix.target }}
113 subtarget: ${{ matrix.subtarget }}
114 build_kernel: true
115 build_all_kmods: true
116
117 check-kernel-patches:
118 name: Check Kernel patches
119 needs: determine_targets
120 permissions:
121 contents: read
122 packages: read
123 strategy:
124 fail-fast: False
125 matrix:
126 include: ${{fromJson(needs.determine_targets.outputs.targets)}}
127 uses: ./.github/workflows/check-kernel-patches.yml
128 with:
129 target: ${{ matrix.target }}
130 subtarget: ${{ matrix.subtarget }}
131