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