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