-
Notifications
You must be signed in to change notification settings - Fork 1
119 lines (111 loc) · 4.19 KB
/
build-linux.yml
File metadata and controls
119 lines (111 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Build Linux
on:
workflow_call:
inputs:
kernel-repo:
description: 'The Linux kernel repository to use.'
default: 'torvalds/linux'
required: false
type: string
rev:
description: 'The revision to build at.'
# By default just use the default branch HEAD.
default: ''
required: false
type: string
config:
description: 'Path to the kernel configuration to use.'
required: true
type: string
vmlinux:
description: 'Whether to include vmlinux in the artifacts.'
default: false
required: false
type: boolean
modules:
description: 'Whether to include kernel modules in the artifacts.'
default: false
required: false
type: boolean
outputs:
kernel-artifact-url:
description: "URL of the built (and uploaded) Linux kernel"
value: ${{ github.api_url }}/repos/${{ github.repository }}/actions/artifacts/${{ jobs.build.outputs.kernel-artifact-id }}/zip
jobs:
build:
name: Build Linux
runs-on: ubuntu-latest
outputs:
kernel-artifact-id: ${{ steps.upload-linux-kernel.outputs.artifact-id }}
steps:
- id: configure
run: |
targets="bzImage"
if [ "${{ inputs.vmlinux }}" = "true" ]; then
targets="${targets} vmlinux"
fi
if [ "${{ inputs.modules }}" = "true" ]; then
targets="${targets} modules"
fi
echo "targets=${targets}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v6
- uses: actions/cache/restore@v4
id: restore-cached-kernel
with:
path: build/
key: linux-kernel-${{ github.workflow_sha }}-${{ inputs.rev }}-${{ hashFiles(inputs.config) }}
- if: steps.restore-cached-kernel.outputs.cache-hit != 'true'
uses: actions/checkout@v6
with:
repository: ${{ inputs.kernel-repo }}
ref: ${{ inputs.rev }}
fetch-depth: 1
path: linux/
- if: steps.restore-cached-kernel.outputs.cache-hit != 'true'
name: Install required tools
run: |
sudo apt-get update
# `pahole` may be required, depending on the config in use.
sudo apt-get install --yes --no-install-recommends libelf-dev pahole
- if: steps.restore-cached-kernel.outputs.cache-hit != 'true'
name: Build kernel
run: |
config=$(readlink --canonicalize-existing ${{ inputs.config }})
build=$(pwd)/build
kbuild=$(pwd)/kbuild
pushd linux/
export KBUILD_OUTPUT="${kbuild}"
mkdir "${KBUILD_OUTPUT}"
KCONFIG_ALLCONFIG="${config}" make O="${KBUILD_OUTPUT}" allnoconfig
echo "::group::config"
cat "${KBUILD_OUTPUT}/.config"
echo "::endgroup::"
mkdir "${build}"
make O="${KBUILD_OUTPUT}" \
--jobs $(($(nproc) * 2)) ${{ steps.configure.outputs.targets }}
if [ "${{ inputs.vmlinux }}" = "true" ]; then
make O="${KBUILD_OUTPUT}" INSTALL_PATH="${build}/boot" install
cp "${KBUILD_OUTPUT}/vmlinux" "${build}/boot/vmlinux-$(make O="${KBUILD_OUTPUT}" -s kernelrelease)"
fi
if [ "${{ inputs.modules }}" = "true" ]; then
make O="${KBUILD_OUTPUT}" INSTALL_MOD_PATH="${build}" modules_install
rm -f "${build}/lib/modules"/*/build "${build}/lib/modules"/*/source
fi
cp "${KBUILD_OUTPUT}/arch/x86/boot/bzImage" "${build}/bzImage"
popd
- if: steps.restore-cached-kernel.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: build/
key: linux-kernel-${{ github.workflow_sha }}-${{ inputs.rev }}-${{ hashFiles(inputs.config) }}
- uses: actions/upload-artifact@v5
id: upload-linux-kernel
# TODO: Having a single path/name may be problematic should we
# ever opt to reusing this workflow multiple times with
# different inputs.
with:
name: linux-kernel
if-no-files-found: error
# The kernel image is already compressed.
compression-level: 0
path: build/