CI: ignore master branch for push events
[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 strategy:
109 fail-fast: False
110 matrix:
111 include: ${{fromJson(needs.determine_targets.outputs.targets_subtargets)}}
112 uses: ./.github/workflows/build.yml
113 with:
114 container_name: toolchain
115 target: ${{ matrix.target }}
116 subtarget: ${{ matrix.subtarget }}
117 build_kernel: true
118 build_all_kmods: true
119
120 check-kernel-patches:
121 name: Check Kernel patches
122 needs: determine_targets
123 permissions:
124 contents: read
125 packages: read
126 strategy:
127 fail-fast: False
128 matrix:
129 include: ${{fromJson(needs.determine_targets.outputs.targets)}}
130 uses: ./.github/workflows/check-kernel-patches.yml
131 with:
132 target: ${{ matrix.target }}
133 subtarget: ${{ matrix.subtarget }}
134