ci: fix check kernel patches job
[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: Opt-out from Git stricter repository ownership checks
89 run: |
90 git config --global --add safe.directory '*'
91
92 - name: Initialization environment
93 run: |
94 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
95 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
96 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
97 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
98
99 - name: Prepare prebuilt tools
100 shell: su buildbot -c "sh -e {0}"
101 working-directory: openwrt
102 run: |
103 mkdir -p staging_dir build_dir
104 ln -sf /prebuilt_tools/staging_dir/host staging_dir/host
105 ln -sf /prebuilt_tools/build_dir/host build_dir/host
106
107 ./scripts/ext-tools.sh --refresh
108
109 - name: Configure testing kernel
110 if: inputs.testing == true
111 shell: su buildbot -c "sh -e {0}"
112 working-directory: openwrt
113 run: |
114 echo CONFIG_TESTING_KERNEL=y >> .config
115
116 - name: Configure system
117 shell: su buildbot -c "sh -e {0}"
118 working-directory: openwrt
119 run: |
120 echo CONFIG_ALL_KMODS=y >> .config
121 echo CONFIG_DEVEL=y >> .config
122 echo CONFIG_AUTOREMOVE=y >> .config
123 echo CONFIG_CCACHE=y >> .config
124
125 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
126 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
127
128 make defconfig
129
130 - name: Build tools
131 shell: su buildbot -c "sh -e {0}"
132 working-directory: openwrt
133 run: make tools/quilt/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
134
135 - name: Refresh Kernel patches
136 shell: su buildbot -c "sh -e {0}"
137 working-directory: openwrt
138 run: make target/linux/refresh V=s
139
140 - name: Validate Refreshed Kernel Patches
141 working-directory: openwrt
142 run: |
143 . .github/workflows/scripts/ci_helpers.sh
144
145 if git diff --name-only --exit-code; then
146 success "Kernel patches for ${{ env.TARGET }}/${{ env.SUBTARGET }} seems ok"
147 else
148 err "Kernel patches for ${{ env.TARGET }}/${{ env.SUBTARGET }} require refresh. (run 'make target/linux/refresh' and force push this pr)"
149 err "You can also check the provided artifacts with the refreshed patch from this CI run."
150 mkdir ${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed
151 for f in $(git diff --name-only); do
152 cp --parents $f ${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed/
153 done
154 exit 1
155 fi
156
157 - name: Upload Refreshed Patches
158 if: failure()
159 uses: actions/upload-artifact@v3
160 with:
161 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed
162 path: openwrt/${{ env.TARGET }}-${{ env.SUBTARGET }}-refreshed