274bae367ded566683afc5f6d377ef9192de36e0
[openwrt/openwrt.git] / .github / workflows / check-kernel-patches.yml
1 name: Refresh kernel for target
2
3 on:
4 workflow_call:
5 inputs:
6 target:
7 required: true
8 type: string
9 testing:
10 type: boolean
11 use_openwrt_container:
12 type: boolean
13 default: true
14
15 permissions:
16 contents: read
17
18 jobs:
19 setup_build:
20 name: Setup build
21 runs-on: ubuntu-latest
22 outputs:
23 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
24 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
25
26 steps:
27 - name: Set lower case owner name
28 id: lower_owner
29 run: |
30 OWNER_LC=$(echo "${{ github.repository_owner }}" \
31 | tr '[:upper:]' '[:lower:]')
32
33 if [ ${{ inputs.use_openwrt_container }} == "true" ]; then
34 OWNER_LC=openwrt
35 fi
36
37 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
38
39 # Per branch tools container tag
40 # By default stick to latest
41 # For official test targetting openwrt stable branch
42 # Get the branch or parse the tag and push dedicated tools containers
43 # For local test to use the correct container for stable release testing
44 # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
45 - name: Determine tools container tag
46 id: determine_tools_container
47 run: |
48 CONTAINER_TAG=latest
49 if [ -n "${{ github.base_ref }}" ]; then
50 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
51 CONTAINER_TAG="${{ github.base_ref }}"
52 fi
53 elif [ ${{ github.ref_type }} == "branch" ]; then
54 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
55 CONTAINER_TAG=${{ github.ref_name }}
56 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
57 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
58 fi
59 elif [ ${{ github.ref_type }} == "tag" ]; then
60 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
61 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
62 fi
63 fi
64 echo "Tools container to use tools:$CONTAINER_TAG"
65 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
66
67 check-patch:
68 name: Check Kernel patches
69 needs: setup_build
70 runs-on: ubuntu-latest
71
72 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
73
74 permissions:
75 contents: read
76 packages: read
77
78 steps:
79 - name: Checkout master directory
80 uses: actions/checkout@v3
81 with:
82 path: openwrt
83
84 - name: Fix permission
85 run: |
86 chown -R buildbot:buildbot openwrt
87
88 - name: Initialization environment
89 run: |
90 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
91 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
92 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
93 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
94
95 - name: Prepare prebuilt tools
96 shell: su buildbot -c "sh -e {0}"
97 working-directory: openwrt
98 run: |
99 mkdir -p staging_dir build_dir
100 ln -sf /prebuilt_tools/staging_dir/host staging_dir/host
101 ln -sf /prebuilt_tools/build_dir/host build_dir/host
102
103 ./scripts/ext-tools.sh --refresh
104
105 - name: Configure testing kernel
106 if: inputs.testing == true
107 shell: su buildbot -c "sh -e {0}"
108 working-directory: openwrt
109 run: |
110 echo CONFIG_TESTING_KERNEL=y >> .config
111
112 - name: Configure system
113 shell: su buildbot -c "sh -e {0}"
114 working-directory: openwrt
115 run: |
116 echo CONFIG_ALL_KMODS=y >> .config
117 echo CONFIG_DEVEL=y >> .config
118 echo CONFIG_AUTOREMOVE=y >> .config
119 echo CONFIG_CCACHE=y >> .config
120
121 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
122 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
123
124 make defconfig
125
126 - name: Build tools
127 shell: su buildbot -c "sh -e {0}"
128 working-directory: openwrt
129 run: make tools/quilt/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
130
131 - name: Refresh Kernel patches
132 shell: su buildbot -c "sh -e {0}"
133 working-directory: openwrt
134 run: make target/linux/refresh V=s
135
136 - name: Validate Refreshed Kernel Patches
137 shell: su buildbot -c "sh -e {0}"
138 working-directory: openwrt
139 run: |
140 . .github/workflows/scripts/ci_helpers.sh
141
142 if git diff --name-only --exit-code; then
143 success "Kernel patches for ${{ env.TARGET }}/${{ env.SUBTARGET }} seems ok"
144 else
145 err "Kernel patches for ${{ env.TARGET }}/${{ env.SUBTARGET }} require refresh. (run 'make target/linux/refresh' and force push this pr)"
146 err "You can also check the provided artifacts with the refreshed patch from this CI run."
147 mkdir ${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed
148 for f in $(git diff --name-only); do
149 cp --parents $f ${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed/
150 done
151 exit 1
152 fi
153
154 - name: Upload Refreshed Patches
155 if: failure()
156 uses: actions/upload-artifact@v3
157 with:
158 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed
159 path: openwrt/${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed