.github: split out from kernel into common.sh

To avoid duplicates, we should split out common parts into
separate functions in `common.sh`.
Make kernel-apply-patch.sh use the helper functions.
This commit is contained in:
Dongsu Park 2020-04-09 11:14:36 +02:00 committed by Kai Lüke
parent de65e80178
commit e45323dc37
2 changed files with 63 additions and 28 deletions

View File

@ -0,0 +1,54 @@
#!/bin/bash
set -euo pipefail
readonly SDK_OUTER_TOPDIR="${HOME}/flatcar-sdk"
readonly SDK_OUTER_SRCDIR="${SDK_OUTER_TOPDIR}/src"
readonly SDK_INNER_SRCDIR="/mnt/host/source/src"
readonly BUILDBOT_USERNAME="Flatcar Buildbot"
readonly BUILDBOT_USEREMAIL="buildbot@flatcar-linux.org"
function enter() ( cd ../../..; exec cork enter -- $@ )
# caller needs to set pass a parameter as a branch name to be created.
function checkout_branches() {
TARGET_BRANCH=$1
[[ -z "${TARGET_BRANCH}" ]] && echo "No target branch specified. exit." && exit 1
git -C "${SDK_OUTER_SRCDIR}/scripts" checkout -B "${BASE_BRANCH}" "github/${BASE_BRANCH}"
git -C "${SDK_OUTER_SRCDIR}/third_party/portage-stable" checkout -B "${BASE_BRANCH}" "github/${BASE_BRANCH}"
git -C "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" checkout -B "${TARGET_BRANCH}" "github/${BASE_BRANCH}"
}
function generate_patches() {
CATEGORY_NAME=$1
PKGNAME_SIMPLE=$2
PKGNAME_DESC=$3
pushd "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" >/dev/null || exit
enter ebuild "${SDK_INNER_SRCDIR}/third_party/coreos-overlay/${CATEGORY_NAME}/${PKGNAME_SIMPLE}/${PKGNAME_SIMPLE}-${VERSION_NEW}.ebuild" manifest --force
# We can only create the actual commit in the actual source directory, not under the SDK.
# So create a format-patch, and apply to the actual source.
git add ${CATEGORY_NAME}/${PKGNAME_SIMPLE}
git commit -a -m "${CATEGORY_NAME}: Upgrade ${PKGNAME_DESC} ${VERSION_OLD} to ${VERSION_NEW}"
# Generate metadata after the main commit was done.
enter "${SDK_INNER_SRCDIR}/scripts/update_metadata" --commit coreos
# Create 2 patches, one for the main ebuilds, the other for metadata changes.
git format-patch -2 HEAD
popd || exit
}
function apply_patches() {
git config user.name "${BUILDBOT_USERNAME}"
git config user.email "${BUILDBOT_USEREMAIL}"
git reset --hard HEAD
git fetch origin
git checkout -B "${BASE_BRANCH}" "origin/${BASE_BRANCH}"
git am "${SDK_OUTER_SRCDIR}"/third_party/coreos-overlay/0*.patch
}

View File

@ -2,16 +2,14 @@
set -euo pipefail
branch="linux-${VERSION_NEW}"
. .github/workflows/common.sh
git -C ~/flatcar-sdk/src/scripts checkout -B "${BASE_BRANCH}" "github/${BASE_BRANCH}"
git -C ~/flatcar-sdk/src/third_party/portage-stable checkout -B "${BASE_BRANCH}" "github/${BASE_BRANCH}"
checkout_branches "linux-${VERSION_NEW}"
pushd ~/flatcar-sdk/src/third_party/coreos-overlay >/dev/null || exit
git checkout -B "${branch}" "github/${BASE_BRANCH}"
pushd "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" >/dev/null || exit
versionOld=$(sed -n "s/^DIST patch-\(${KERNEL_VERSION}.[0-9]*\).*/\1/p" sys-kernel/coreos-sources/Manifest)
[[ "${VERSION_NEW}" = "$versionOld" ]] && echo "already the latest Kernel, nothing to do" && exit
VERSION_OLD=$(sed -n "s/^DIST patch-\(${KERNEL_VERSION}.[0-9]*\).*/\1/p" sys-kernel/coreos-sources/Manifest)
[[ "${VERSION_NEW}" = "${VERSION_OLD}" ]] && echo "already the latest Kernel, nothing to do" && exit
for pkg in sources modules kernel; do \
pushd "sys-kernel/coreos-${pkg}" >/dev/null || exit; \
@ -20,27 +18,10 @@ for pkg in sources modules kernel; do \
popd >/dev/null || exit; \
done
function enter() ( cd ../../..; exec cork enter -- $@ )
popd >/dev/null || exit
enter ebuild "/mnt/host/source/src/third_party/coreos-overlay/sys-kernel/coreos-sources/coreos-sources-${VERSION_NEW}.ebuild" manifest --force
generate_patches sys-kernel coreos-{sources,kernel,modules} Linux
# We can only create the actual commit in the actual source directory, not under the SDK.
# So create a format-patch, and apply to the actual source.
git add sys-kernel/coreos-* metadata
git commit -a -m "sys-kernel: Upgrade Linux ${versionOld} to ${VERSION_NEW}"
apply_patches
# Generate metadata after the main commit was done.
enter /mnt/host/source/src/scripts/update_metadata --commit coreos
# Create 2 patches, one for the main ebuilds, the other for metadata changes.
git format-patch -2 HEAD
popd || exit
git config user.name 'Flatcar Buildbot'
git config user.email 'buildbot@flatcar-linux.org'
git reset --hard HEAD
git fetch origin
git checkout -B "${BASE_BRANCH}" "origin/${BASE_BRANCH}"
git am ~/flatcar-sdk/src/third_party/coreos-overlay/0*.patch
echo ::set-output name=VERSION_OLD::"${versionOld}"
echo ::set-output name=VERSION_OLD::"${VERSION_OLD}"