CI: kernel: test each subtarget on 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 if we are testing pr
58 if [ ${{ github.event_name }} != 'push' ]; then
59 if echo "$CHANGED_FILES" | grep -v -q target/linux ||
60 echo "$CHANGED_FILES" | grep -q target/linux/generic; then
61 TARGETS_SUBTARGETS=$TARGETS
62 fi
63 fi
64
65 JSON_TARGETS_SUBTARGETS='['
66 FIRST=1
67 for TARGET in $TARGETS_SUBTARGETS; do
68 if echo "$CHANGED_FILES" | grep -v -q target/linux ||
69 echo "$CHANGED_FILES" | grep -q target/linux/generic ||
70 echo "$CHANGED_FILES" | grep -q $(echo $TARGET | cut -d "/" -f 1); then
71 TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
72 [[ $FIRST -ne 1 ]] && JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"','
73 JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS""$TUPLE"
74 FIRST=0
75 fi
76 done
77 JSON_TARGETS_SUBTARGETS="$JSON_TARGETS_SUBTARGETS"']'
78
79 JSON_TARGETS='['
80 FIRST=1
81 for TARGET in $TARGETS; do
82 if echo "$CHANGED_FILES" | grep -v -q target/linux ||
83 echo "$CHANGED_FILES" | grep -q target/linux/generic ||
84 echo "$CHANGED_FILES" | grep -q $(echo $TARGET | cut -d "/" -f 1); then
85 TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
86 [[ $FIRST -ne 1 ]] && JSON_TARGETS="$JSON_TARGETS"','
87 JSON_TARGETS="$JSON_TARGETS""$TUPLE"
88 FIRST=0
89 fi
90 done
91 JSON_TARGETS="$JSON_TARGETS"']'
92
93 echo -e "\n---- targets to build ----\n"
94 echo "$JSON_TARGETS_SUBTARGETS"
95 echo -e "\n---- targets to build ----\n"
96
97 echo -e "\n---- targets to check patch ----\n"
98 echo "$JSON_TARGETS"
99 echo -e "\n---- targets to check patch ----\n"
100
101 echo "targets_subtargets=$JSON_TARGETS_SUBTARGETS" >> $GITHUB_OUTPUT
102 echo "targets=$JSON_TARGETS" >> $GITHUB_OUTPUT
103
104 build:
105 name: Build Kernel with external toolchain
106 needs: determine_targets
107 permissions:
108 contents: read
109 packages: read
110 actions: write
111 strategy:
112 fail-fast: False
113 matrix:
114 include: ${{fromJson(needs.determine_targets.outputs.targets_subtargets)}}
115 uses: ./.github/workflows/build.yml
116 with:
117 container_name: toolchain
118 target: ${{ matrix.target }}
119 subtarget: ${{ matrix.subtarget }}
120 build_kernel: true
121 build_all_kmods: true
122 upload_ccache_cache: ${{ github.repository_owner == 'openwrt' }}
123
124 check-kernel-patches:
125 name: Check Kernel patches
126 needs: determine_targets
127 permissions:
128 contents: read
129 packages: read
130 strategy:
131 fail-fast: False
132 matrix:
133 include: ${{fromJson(needs.determine_targets.outputs.targets)}}
134 uses: ./.github/workflows/check-kernel-patches.yml
135 with:
136 target: ${{ matrix.target }}
137 subtarget: ${{ matrix.subtarget }}
138
139 upload-ccache-cache-in-s3:
140 if: github.event_name == 'push' && github.repository_owner == 'openwrt'
141 name: Upload ccache cache to s3
142 needs: [determine_targets, build]
143 strategy:
144 fail-fast: False
145 matrix:
146 include: ${{fromJson(needs.determine_targets.outputs.targets_subtargets)}}
147 secrets:
148 s3_access_key: ${{ secrets.GCS_S3_ACCESS_KEY }}
149 s3_secret_key: ${{ secrets.GCS_S3_SECRET_KEY }}
150 uses: ./.github/workflows/upload-file-s3.yml
151 with:
152 endpoint: https://storage.googleapis.com
153 bucket: openwrt-ci-cache
154 download_id: ${{ matrix.target }}-${{ matrix.subtarget }}-ccache-cache
155 filename: ccache-kernel-${{ matrix.target }}-${{ matrix.subtarget }}.tar