CI: label-kernel: support compile testing kernel version and all target
[openwrt/openwrt.git] / .github / workflows / label-kernel.yml
1 # ci:kernel:x86:64 is going to trigger CI kernel check jobs for x86/64 target
2
3 name: Build kernel and check patches for target specified in labels
4 on:
5 pull_request:
6 types:
7 - labeled
8
9 jobs:
10 set_target:
11 if: startsWith(github.event.label.name, 'ci:kernel:')
12 name: Set target
13 runs-on: ubuntu-latest
14 outputs:
15 targets_subtargets: ${{ steps.set_target.outputs.targets_subtargets }}
16 targets: ${{ steps.set_target.outputs.targets }}
17
18 steps:
19 - name: Checkout
20 uses: actions/checkout@v3
21
22 - name: Parse label
23 id: parse_label
24 env:
25 CI_EVENT_LABEL_NAME: ${{ github.event.label.name }}
26 run: |
27 echo "$CI_EVENT_LABEL_NAME" | sed -n 's/ci:kernel:\([^:]*\):\([^:]*\):*\([^:]*\)$/target=\1/p' | tee --append $GITHUB_OUTPUT
28 echo "$CI_EVENT_LABEL_NAME" | sed -n 's/ci:kernel:\([^:]*\):\([^:]*\):*\([^:]*\)$/subtarget=\2/p' | tee --append $GITHUB_OUTPUT
29 echo "$CI_EVENT_LABEL_NAME" | sed -n 's/ci:kernel:\([^:]*\):\([^:]*\):*\([^:]*\)$/testing=\3/p' | tee --append $GITHUB_OUTPUT
30
31 - name: Set targets
32 id: set_target
33 run: |
34 ALL_TARGETS="$(perl ./scripts/dump-target-info.pl kernels 2>/dev/null)"
35
36 TARGETS_SUBTARGETS="$(echo "$ALL_TARGETS" | sort -u -t '/' -k1)"
37 TARGETS="$(echo "$ALL_TARGETS" | sort -u -t '/' -k1,1)"
38
39 [ "${{ steps.parse_label.outputs.subtarget }}" = "first" ] && TARGETS_SUBTARGETS=$TARGETS
40
41 JSON_TARGETS_SUBTARGETS='['
42 FIRST=1
43 while IFS= read -r line; do
44 TARGET_SUBTARGET=$(echo $line | cut -d " " -f 1)
45 TARGET=$(echo $TARGET_SUBTARGET | cut -d "/" -f 1)
46 SUBTARGET=$(echo $TARGET_SUBTARGET | cut -d "/" -f 2)
47
48 [ "${{ steps.parse_label.outputs.target }}" != "all" ] && [ "${{ steps.parse_label.outputs.target }}" != "$TARGET" ] && continue
49 [ "${{ steps.parse_label.outputs.subtarget }}" != "all" ] && [ "${{ steps.parse_label.outputs.subtarget }}" != "first" ] &&
50 [ "${{ steps.parse_label.outputs.subtarget }}" != $SUBTARGET ] && continue
51 if [ "${{ steps.parse_label.outputs.testing }}" = "testing" ]; then
52 TESTING_KERNEL_VER=$(echo $line | cut -d " " -f 3)
53 [ -z "$TESTING_KERNEL_VER" ] && continue
54 fi
55
56 TUPLE='{"target":"'"$TARGET"'","subtarget":"'"$SUBTARGET"'","testing":"'"$TESTING_KERNEL_VER"'"}'
57 [[ $FIRST -ne 1 ]] && JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"','
58 JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS""$TUPLE"
59 FIRST=0
60 done <<< "$TARGETS_SUBTARGETS"
61 JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"']'
62
63 JSON_TARGETS='['
64 FIRST=1
65 while IFS= read -r line; do
66 TARGET_SUBTARGET=$(echo $line | cut -d " " -f 1)
67 TARGET=$(echo $TARGET_SUBTARGET | cut -d "/" -f 1)
68 SUBTARGET=$(echo $TARGET_SUBTARGET | cut -d "/" -f 2)
69
70 [ "${{ steps.parse_label.outputs.target }}" != "all" ] && [ "${{ steps.parse_label.outputs.target }}" != $TARGET ] && continue
71 if [ "${{ steps.parse_label.outputs.testing }}" = "testing" ]; then
72 TESTING_KERNEL_VER=$(echo $line | cut -d " " -f 3)
73 [ -z "$TESTING_KERNEL_VER" ] && continue
74 fi
75
76 TUPLE='{"target":"'"$TARGET"'","subtarget":"'"$SUBTARGET"'","testing":"'"$TESTING_KERNEL_VER"'"}'
77 [[ $FIRST -ne 1 ]] && JSON_TARGETS="$JSON_TARGETS"','
78 JSON_TARGETS="$JSON_TARGETS""$TUPLE"
79 FIRST=0
80 done <<< "$TARGETS"
81 JSON_TARGETS="$JSON_TARGETS"']'
82
83 echo -e "\n---- targets to build ----\n"
84 echo "$JSON_TARGETS_SUBTARGETS"
85 echo -e "\n---- targets to build ----\n"
86
87 echo -e "\n---- targets to check patch ----\n"
88 echo "$JSON_TARGETS"
89 echo -e "\n---- targets to check patch ----\n"
90
91 echo "targets_subtargets=$JSON_TARGETS_SUBTARGETS" >> $GITHUB_OUTPUT
92 echo "targets=$JSON_TARGETS" >> $GITHUB_OUTPUT
93
94 build_kernel:
95 name: Build Kernel with external toolchain
96 needs: set_target
97 permissions:
98 contents: read
99 packages: read
100 actions: write
101 uses: ./.github/workflows/build.yml
102 strategy:
103 fail-fast: False
104 matrix:
105 include: ${{fromJson(needs.set_target.outputs.targets_subtargets)}}
106 with:
107 container_name: toolchain
108 target: ${{ matrix.target }}
109 subtarget: ${{ matrix.subtarget }}
110 testing: ${{ matrix.testing != '' && true }}
111 build_kernel: true
112 build_all_kmods: true
113
114 check-kernel-patches:
115 name: Check Kernel patches
116 needs: set_target
117 permissions:
118 contents: read
119 packages: read
120 actions: write
121 strategy:
122 fail-fast: False
123 matrix:
124 include: ${{fromJson(needs.set_target.outputs.targets)}}
125 uses: ./.github/workflows/check-kernel-patches.yml
126 with:
127 target: ${{ matrix.target }}
128 subtarget: ${{ matrix.subtarget }}
129 testing: ${{ matrix.testing != '' && true }}