Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Build kernel

Build kernel #626

Workflow file for this run

name: Build kernel
on:
push:
branches: [main]
tags:
- linux-wsl-*
- linux-msft-wsl-*
schedule:
- cron: "30 17 * * *"
workflow_dispatch:
jobs:
build-kernel:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/[email protected]
- name: Check Kernel Version
id: get_version
run: |
if [[ "$EVENT_NAME" == "push" ]]; then
if [[ "$REF_TYPE" == "tag" ]]; then
MSFT_KERNEL_VER=${GITHUB_REF##*/}
MSFT_KERNEL_INFO=$(curl -sX GET "https://api.github.com/repos/microsoft/WSL2-Linux-Kernel/releases")
MSFT_KERNEL_URL=$(echo "${MSFT_KERNEL_INFO}" | jq -r ".[] | select(.tag_name == \"$MSFT_KERNEL_VER\").tarball_url")
MSFT_KERNEL_BODY=$(echo "${MSFT_KERNEL_INFO}" | jq -r ".[] | select(.tag_name == \"$MSFT_KERNEL_VER\").body")
echo -e "## Features\n${MSFT_KERNEL_BODY}" >/tmp/bodyfile.txt
sed -i "s|\(^[[:space:]]\+KERNEL_URL=\).*|\1${MSFT_KERNEL_URL}|g" build-kernel.sh
echo "MSFT_KERNEL_VER=$MSFT_KERNEL_VER" >> $GITHUB_OUTPUT
fi
else
REPO_KERNEL_INFO=$(curl -sX GET "https://api.github.com/repos/${{ github.repository }}/releases")
REPO_MSFT_KERNEL_VER=$(echo "${REPO_KERNEL_INFO}" | jq -r '[.[] | select(.prerelease == false)][0] | .tag_name')
REPO_KERNEL_VER=$(echo "${REPO_KERNEL_INFO}" | jq -r '[.[] | select(.prerelease == true)][0] | .tag_name')
MSFT_KERNEL_INFO=$(curl -sX GET "https://api.github.com/repos/microsoft/WSL2-Linux-Kernel/releases/latest")
MSFT_KERNEL_VER=$(echo "${MSFT_KERNEL_INFO}" | jq -r '.tag_name')
KERNEL_INFO=$(curl --silent https://www.kernel.org | sed -n '/<td id="latest_link">/,/<\/td>/p')
KERNEL_VER=linux-wsl-$(echo "${KERNEL_INFO}" | grep -Pom1 '(?<=>)([[:digit:]]{1,3}\.){1,2}[[:digit:]]{1,3}')
if [ "$KERNEL_VER" != "$REPO_KERNEL_VER" ]; then
KERNEL_URL=$(echo "${KERNEL_INFO}" | grep -Po 'http[^"]+')
sed -i "s|\(^[[:space:]]\+KERNEL_URL=\).*|\1${KERNEL_URL}|g" build-kernel.sh
echo "MSFT_KERNEL_VER=$KERNEL_VER" >> $GITHUB_OUTPUT
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
elif [ "$MSFT_KERNEL_VER" != "$REPO_MSFT_KERNEL_VER" ]; then
MSFT_KERNEL_URL=$(echo "${MSFT_KERNEL_INFO}" | jq -r '.tarball_url')
MSFT_KERNEL_BODY=$(echo "${MSFT_KERNEL_INFO}" | jq -r '.body')
echo -e "## Features\n${MSFT_KERNEL_BODY}" >/tmp/bodyfile.txt
sed -i "s|\(^[[:space:]]\+KERNEL_URL=\).*|\1${MSFT_KERNEL_URL}|g" build-kernel.sh
echo "MSFT_KERNEL_VER=$MSFT_KERNEL_VER" >> $GITHUB_OUTPUT
fi
fi
env:
EVENT_NAME: ${{ github.event_name }}
REF_TYPE: ${{ github.ref_type }}
- name: Create Pull Request
if: ${{ steps.get_version.outputs.MSFT_KERNEL_VER }}
id: cpr
uses: peter-evans/[email protected]
with:
add-paths: build-kernel.sh
base: main
commit-message: Update ${{ steps.get_version.outputs.MSFT_KERNEL_VER }}
author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
branch: release/${{ steps.get_version.outputs.MSFT_KERNEL_VER }}
delete-branch: true
title: Update ${{ steps.get_version.outputs.MSFT_KERNEL_VER }}
body: This PR will be merged automatically.
- name: Merge for Dependabot PRs
if: ${{ steps.get_version.outputs.MSFT_KERNEL_VER && steps.cpr.outputs.pull-request-url }}
run: gh pr merge $PR_URL --auto --delete-branch --squash
env:
PR_URL: ${{ steps.cpr.outputs.pull-request-url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Release
if: ${{ steps.get_version.outputs.MSFT_KERNEL_VER || github.event_name == 'push' }}
timeout-minutes: 100
run: |
git pull
docker compose up
docker compose down
tee -a /tmp/bodyfile.txt <<-EOF
## sha256sum
\`\`\`
$(cat *.sha256)
\`\`\`
EOF
- name: GH Release
if: ${{ steps.get_version.outputs.MSFT_KERNEL_VER }}
uses: softprops/action-gh-release@v1
with:
body_path: /tmp/bodyfile.txt
prerelease: ${{ steps.get_version.outputs.IS_PRERELEASE == 'true' }}
files: |
wsl2-kernel-amd64
wsl2-kernel-arm64
tag_name: ${{ steps.get_version.outputs.MSFT_KERNEL_VER }}
fail_on_unmatched_files: true
- name: Prune old releases
if: ${{ steps.get_version.outputs.MSFT_KERNEL_VER }}
run: |
git fetch --tags
LINUX_TAGS=$(git tag --sort=committerdate -l "linux-wsl-*" | head -n-2)
for TAG in ${LINUX_TAGS[@]}; do
gh release delete ${TAG} --yes
git tag -d ${TAG}
done
MSFT_TAGS=$(git tag --sort=committerdate -l "linux-msft-wsl-*" | head -n-3)
for TAG in ${MSFT_TAGS[@]}; do
gh release delete ${TAG} --yes
git tag -d ${TAG}
done
git push --tags --prune
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Rclone Sync
if: ${{ steps.get_version.outputs.IS_PRERELEASE }}
run: |
mkdir -p .config/rclone
tee -a .config/rclone/rclone.conf >/dev/null <<-EOF
${{ secrets.RCLONE_CONFIG }}
EOF
docker run --rm --volume ${PWD}/.config:/config --volume ${PWD}/wsl2-kernel-amd64:/data/wsl2-kernel-amd64 rclone/rclone copy /data/wsl2-kernel-amd64 drive:/devtools/wslkernel/
docker run --rm --volume ${PWD}/.config:/config --volume ${PWD}/wsl2-kernel-arm64:/data/wsl2-kernel-arm64 rclone/rclone copy /data/wsl2-kernel-arm64 drive:/devtools/wslkernel/
rm -rf .config/rclone