This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
forked from microsoft/WSL2-Linux-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nathan Chancellor <[email protected]>
- Loading branch information
1 parent
a4a4784
commit 87a0aa0
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
BASE=$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"/.. && pwd) | ||
cd "${BASE}" || exit ${?} | ||
|
||
function clang_version() { | ||
echo __clang_version__ | "${1:?}" -E -xc - | tail -n1 | awk '{print $1}' | cut -d \" -f 2 | ||
} | ||
|
||
function clang_hash() { | ||
echo __clang_version__ | "${1:?}" -E -xc - | tail -n1 | awk '{print $3}' | cut -d \) -f 1 | ||
} | ||
|
||
function die() { | ||
printf "\n\033[01;31m%s\033[0m\n" "${1}" | ||
exit "${2:-33}" | ||
} | ||
|
||
function parse_parameters() { | ||
while (( ${#} )); do | ||
case ${1} in | ||
-f|--force) FORCE=true ;; | ||
-r|--release) RELEASE=true ;; | ||
-t|--tag) TAG=true ;; | ||
-v|--version) shift && VER_NUM=${1} ;; | ||
-v*) VER_NUM=${1//-v} ;; | ||
esac | ||
shift | ||
done | ||
|
||
: "${RELEASE:=false}" "${TAG:=false}" | ||
[[ ${RELEASE} == false && ${TAG} == false ]] && die "Either --tag or --release needs to be specified" | ||
[[ -z ${VER_NUM} ]] && die "Version number must be specified" | ||
} | ||
|
||
function set_variables() { | ||
[[ -n ${CBL_LLVM} && -d ${CBL_LLVM} ]] || die "LLVM folder could not be found" | ||
|
||
[[ -f localversion-next ]] || die "localversion-next could not be found!" | ||
NEXT_VERSION=$(cat localversion-next) | ||
|
||
MY_TAG=wsl2-cbl-kernel${NEXT_VERSION}-v${VER_NUM} | ||
} | ||
|
||
function do_tag() { | ||
${TAG} || return 0 | ||
|
||
${FORCE:=false} && git tag -d "${MY_TAG}" | ||
git tag --annotate "${MY_TAG}" \ | ||
--edit \ | ||
--message "Clang Built WSL2 Kernel v${VER_NUM} | ||
* Built with clang $(clang_version "${CBL_LLVM}"/clang) at https://github.com/llvm/llvm-project/commit/$(clang_hash "${CBL_LLVM}"/clang) | ||
* Updated to ${NEXT_VERSION/-}" \ | ||
--sign || die "Error creating tag" | ||
} | ||
|
||
function do_release() { | ||
${RELEASE} || return 0 | ||
|
||
KERNEL=out/x86_64/arch/x86/boot/bzImage | ||
[[ -f ${KERNEL} ]] || die "A kernel needs to be built to create a release" | ||
|
||
git rev-parse "${MY_TAG}" &>/dev/null || die "Could not find ${MY_TAG}" | ||
|
||
git push --force origin "${MY_TAG}" || die "Error pushing tag" | ||
hub release create -a "${KERNEL}" \ | ||
-m "$(git for-each-ref refs/tags/"${MY_TAG}" --format='%(contents)' | sed '/BEGIN PGP SIGNATURE/Q')" \ | ||
"${MY_TAG}" || die "Error creating release" | ||
} | ||
|
||
parse_parameters "${@}" | ||
set_variables | ||
do_tag | ||
do_release |