-
Notifications
You must be signed in to change notification settings - Fork 1
263 lines (236 loc) · 9.66 KB
/
Build-Kernels.yml
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Build Kernels
on:
schedule:
- cron: '52 */3 * * *'
workflow_dispatch:
inputs:
debug_enabled:
description: 'Debug session enabled'
required: false
default: false
type: boolean
release:
description: 'Delivery Channel'
required: false
default: 'Artifact'
type: choice
options:
- "Artifact"
- "Release"
jobs:
## CONFIG ##############################################################################
job-config:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
cancel: ${{ steps.prebuild-checks.outputs.cancel }}
defaults:
run:
shell: bash
steps:
- name: "✔️ Pre-build checks"
id: prebuild-checks
run: |
body="/home/runner/body.txt"
jsonFile="/home/runner/kernels.json"
WSL_DATE="$( wget -qO- https://api.github.com/repos/microsoft/WSL2-Linux-Kernel/commits | jq '.[1].commit.committer.date' -r )"
LAST_DATE="$( wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases/latest | jq .published_at -r )" || LAST_DATE="2000.01.01T00:00:00Z"
echo "The last WSL2 Kernel commit date is: $WSL_DATE"
echo "The last Release in this repo was on: $LAST_DATE"
if [[ $WSL_DATE > $LAST_DATE ]]; then
echo "NEW KERNEL SOURCE!!!!"
echo "# KERNEL UPDATES" > $body
echo >> $body
wget -qO- https://api.github.com/repos/microsoft/WSL2-Linux-Kernel/releases/latest | jq .body -r >> $body
fi
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
echo "NEW IMPROVEMENT!!!!"
[ -f $body ] && echo >> $body
echo "# IMPROVEMENTS" >> $body
echo >> $body
fi
if [ -f $body ]; then
echo "{}" | jq "\
.commitDate |= \"${WSL_DATE}\" |\
.buildDate |= \"$(TZ=UTC date +'%Y.%m.%dT%H:%M:%SZ')\"" > $jsonFile
echo "cancel=false" >> $GITHUB_OUTPUT
else
echo "NOTHING NEW. CANCELLING ACTION..."
echo "cancel=true" >> $GITHUB_OUTPUT
fi
- name: "⏬ Download repository"
if: steps.prebuild-checks.outputs.cancel != 'true'
uses: actions/checkout@v3
- name: "⏬ Fetch latest WSL kernel source"
if: steps.prebuild-checks.outputs.cancel != 'true'
run: git clone --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.git src
# latest rolling release: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
# Microsoft config file: https://github.com/microsoft/WSL2-Linux-Kernel/raw/linux-msft-wsl-5.15.y/Microsoft/config-wsl
- name: "🪄 Prepare Build jobs"
id: set-matrix
if: steps.prebuild-checks.outputs.cancel != 'true'
shell: pwsh
run: |
jq ".version |= \`"$(cd src;make kernelversion;cd ..)\`"" ~/kernels.json | set-content kernels.json
7z a metadata.7z ~/body.txt kernels.json
$m=@{include = @()}
(gci *.dif).baseName | % { $m.include+=@{config = $_} }
"matrix=$(($m | ConvertTo-Json -compress) -replace '"','`"')" >> $env:GITHUB_OUTPUT
- name: "💾 Save metadata"
if: steps.prebuild-checks.outputs.cancel != 'true'
uses: actions/[email protected]
id: cache-metadata
with:
key: ${{ github.sha }}-metadata
path: ./metadata.7z
- name: "💾 Save Build Folder"
if: steps.prebuild-checks.outputs.cancel != 'true'
uses: actions/[email protected]
id: cache-sources
with:
path: ./*
key: ${{ github.sha }}-repo
## BUILD ##############################################################################
job-build:
needs: [ job-config ]
if: needs.job-config.outputs.cancel != 'true'
name: "Build configuration ${{ matrix.config }}"
runs-on: ubuntu-latest
strategy:
matrix: ${{ FromJson(needs.job-config.outputs.matrix) }}
# config: ${{ FromJson(needs.job-config.outputs.configs) }}
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: "⏬ Download and Install Toolchain"
run: sudo apt -y install build-essential flex bison dwarves libssl-dev libelf-dev python3 bc jq aria2 p7zip-full
- name: "📂 Load Build Folder"
uses: actions/[email protected]
id: cache-sources
with:
path: ./*
key: ${{ github.sha }}-repo
- name: "⚙️ Build WSL2 Kernel with ${{ matrix.config }} configuration for Windows 64 bits"
run: |
## NOTE: dif file generated after `makeconfig nconfig` with instruction:
# diff -u Microsoft/config-wsl .config | grep "^[+-][^+^-].*" > ../<CONFIG>.dif
difFile="$(pwd)/${{ matrix.config }}.dif"
cd src
sed "s/-standard-/-${{ matrix.config }}-/" Microsoft/config-wsl > .config
while read line; do
case ${line:0:1} in
+) echo "adding : ${line:1}"
echo ${line:1} >> .config ;;
-) echo "removing: ${line:1}"
sed -i "/${line:1}/d" .config ;;
esac
done < $difFile
yes '' | make -j$(($(nproc)*2+1)) LOCALVERSION="" || true
cp arch/x86/boot/bzImage ../WSL2kernel_${{ matrix.config }}
# echo "${{ matrix.config }}" > ../WSL2kernel_${{ matrix.config }}
- name: "👍 Upload Image as Artifact"
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.config }}
path: |
WSL2kernel_${{ matrix.config }}
src/.config
## PUBLISH ##############################################################################
job-publish:
if: needs.job-config.outputs.cancel != 'true'
needs:
- job-config
- job-build
name: "Publish"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: "⏬ Download repository"
uses: actions/checkout@v3
- name: "📬 Receive Images from Build Jobs"
uses: actions/download-artifact@v3
with:
path: ./artifacts
- name: "📬 Receive metadata"
uses: actions/[email protected]
id: cache-metadata
with:
key: ${{ github.sha }}-metadata
path: ./metadata.7z
- name: "🚮 Recycle Cache"
uses: snnaplab/delete-branch-cache-action@v1
- name: "🚮 Recycle Artifacts"
uses: geekyeggo/delete-artifact@v2
with:
name: '*'
- name: "📦 Create Package"
run: |
7z e metadata.7z
APP_VERSION=$(cat wsl2kernel.ps1 | grep -Po "(?<=\sv)[\d\.\-]+")
KERNEL_VERSION=$(jq .version -r kernels.json)
BUILD_VERSION="${KERNEL_VERSION}-${APP_VERSION}"
echo "BUILD_VERSION=${BUILD_VERSION}" >> $GITHUB_ENV
ls -1 *.dif | sed "s|\..*||g" | while read c; do
cp "artifacts/${c}/WSL2kernel_${c}" "WSL2kernel_${c}_${KERNEL_VERSION}"
description=$(head -1 "${c}.dif" | sed "s|\r||")
json=$(jq ".kernels |= . + [{ \"config\": \"${c}\",
\"description\": \"${description}\" }]" kernels.json)
echo $json > kernels.json
done
7z a -aoa -tzip -- "WSL2kernel_${BUILD_VERSION}.zip" \
*.ps1 \
WSL2k* \
LICENSE \
README.md \
kernels.json
7z l "WSL2kernel_${BUILD_VERSION}.zip"
- name: "👍 Upload Artifact"
uses: actions/upload-artifact@v3
if: env.CANCEL != 'true' && github.event.inputs.release == 'Artifact'
with:
name: ${{ env.BUILD_VERSION }}
path: |
*zip
body.txt
artifacts/*/src/.config
- name: "🎉 Publish a new release"
uses: softprops/[email protected]
# WARNING: before useing this action go to https://github.com/OWNER/REPO/settings/actions
# and in **Workflow Permissions** section give actions **Read and Write permissions**.
if: github.event_name != 'workflow_dispatch' || github.event.inputs.release == 'Release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.BUILD_VERSION }}
body_path: body.txt
files: |
WSL2kernel_*
# - name: "🔧 Prepare debug session"
# if: github.event.inputs.debug_enabled == 'true'
# run: |
# ## install zsh
# sudo apt install zsh zsh-syntax-highlighting
# ## oh-my-posh
# sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
# sudo chmod +x /usr/local/bin/oh-my-posh
# ## setting rc files
# echo "eval \"\$(oh-my-posh init \$(oh-my-posh get shell))\"" >> ~/.bashrc
# echo "eval \"\$(oh-my-posh init \$(oh-my-posh get shell))\"" >> ~/.zshrc
# ## Default profiles
# wget -q https://github.com/okibcn/miniU/raw/main/Github_Linux/.nanorc -O ~/.nanorc
# wget -q https://github.com/okibcn/miniU/raw/main/Github_Linux/profile.sh -O ~/profile.sh
# cp /etc/bash.bashrc ~
# cat ~/profile.sh >> ~/bash.bashrc
# sudo cp ~/bash.bashrc /etc/bash.bashrc -f
# cp ~/profile.sh ~/.zshrc
# - name: "🐞 Debug session"
# uses: mxschmitt/action-tmate@v3
# if: github.event.inputs.debug_enabled == 'true'
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ## More info at https://til.simonwillison.net/github-actions/debug-tmate
# ## or https://github.com/mxschmitt/action-tmate