diff --git a/.github/workflows/kernel-build.yml b/.github/workflows/kernel-build.yml index daff30e..66e0b88 100644 --- a/.github/workflows/kernel-build.yml +++ b/.github/workflows/kernel-build.yml @@ -46,11 +46,6 @@ jobs: timeout-minutes: 100 env: ARTIFACTS_ARCHIVE: "vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst" - BASE_BRANCH: >- - ${{ github.event_name == 'push' && github.ref_name - || github.base_ref - || 'bpf-next' - }} BUILD_SCHED_EXT_SELFTESTS: ${{ inputs.arch == 'x86_64' || inputs.arch == 'aarch64' && 'true' || '' }} CACHED_KERNEL_BUILD: ${{ github.event_name == 'push' || github.repository == 'libbpf/ci' && 'true' || '' }} KBUILD_OUTPUT: ${{ github.workspace }}/kbuild-output @@ -67,33 +62,31 @@ jobs: - if: ${{ inputs.download_sources }} name: Download bpf-next tree env: - FETCH_GIT_REPO: ${{ env.CACHED_KERNEL_BUILD }} + FETCH_DEPTH: ${{ env.CACHED_KERNEL_BUILD && 16 || 0 }} uses: ./get-linux-source with: dest: '.kernel' - - if: ${{ inputs.download_sources }} - name: Move linux source in place - shell: bash - run: | - mv .git /tmp/.git.not-kernel - cd .kernel - mv -t .. $(ls -A) - cd .. - rmdir .kernel - if: ${{ env.CACHED_KERNEL_BUILD }} uses: ./prepare-incremental-build with: - repo-root: ${{ env.REPO_ROOT }} - base-branch: ${{ env.BASE_BRANCH }} + repo-root: ${{ inputs.download_sources && '.kernel' || env.REPO_ROOT }} + base-branch: >- + ${{ github.repository == 'kernel-patches/bpf' && github.event_name == 'push' && github.ref_name + || github.repository == 'kernel-patches/bpf' && github.event_name != 'push' && github.base_ref + || 'master' + }} arch: ${{ inputs.arch }} toolchain_full: ${{ inputs.toolchain_full }} kbuild-output: ${{ env.KBUILD_OUTPUT }} - if: ${{ inputs.download_sources }} - name: Restore .git # is this really necessary? + name: Move linux source in place shell: bash run: | + cd .kernel rm -rf .git - mv /tmp/.git.not-kernel .git + mv -t .. $(ls -A) + cd .. + rmdir .kernel - uses: ./patch-kernel with: patches-root: '${{ github.workspace }}/ci/diffs' diff --git a/get-linux-source/checkout_latest_kernel.sh b/get-linux-source/checkout_latest_kernel.sh index 7d5f3ec..4b33ed3 100755 --- a/get-linux-source/checkout_latest_kernel.sh +++ b/get-linux-source/checkout_latest_kernel.sh @@ -6,7 +6,8 @@ source $(cd $(dirname $0) && pwd)/../helpers.sh CWD=$(pwd) -FETCH_GIT_REPO=${FETCH_GIT_REPO:-} +# 0 means just download a snapshot +FETCH_DEPTH=${FETCH_DEPTH:-0} echo KERNEL_ORIGIN = ${KERNEL_ORIGIN} echo KERNEL_BRANCH = ${KERNEL_BRANCH} @@ -31,28 +32,27 @@ if [ ! -d "${REPO_PATH}" ]; then mkdir -p $(dirname "${REPO_PATH}") cd $(dirname "${REPO_PATH}") # attempt to fetch desired bpf-next repo snapshot - if [ -n "${SNAPSHOT_URL}" ] && [ -z "${FETCH_GIT_REPO}" ] && \ + if [ -n "${SNAPSHOT_URL}" ] && [ "${FETCH_DEPTH}" -eq 0 ] && \ wget -U 'BPFCIBot/1.0 (bpf@vger.kernel.org)' -nv ${SNAPSHOT_URL} && \ tar xf bpf-next-${LINUX_SHA}.tar.gz --totals ; then mv bpf-next-${LINUX_SHA} $(basename ${REPO_PATH}) else - # but fallback to git fetch approach if that fails - mkdir -p $(basename ${REPO_PATH}) - cd $(basename ${REPO_PATH}) - git init - git remote add bpf-next ${KERNEL_ORIGIN} - # try shallow clone first - git fetch --depth 32 bpf-next - # check if desired SHA exists - if ! git cat-file -e ${LINUX_SHA}^{commit} ; then - # if not, fetch all of bpf-next; slow and painful - git fetch bpf-next - fi - git reset --hard ${LINUX_SHA} + # but fallback to git fetch approach if that fails + git clone --depth ${FETCH_DEPTH} ${KERNEL_ORIGIN} ${REPO_PATH} + cd "${REPO_PATH}" + # check if desired SHA exists + if ! git cat-file -e ${LINUX_SHA}^{commit} ; then + # if not, fetch all of bpf-next; slow and painful + git fetch origin + fi + git reset --hard ${LINUX_SHA} + cd - fi - if [ -z "${FETCH_GIT_REPO}" ]; then + if [ "${FETCH_DEPTH}" -eq 0 ]; then rm -rf ${REPO_PATH}/.git || true fi foldable end pull_kernel_srcs +else + echo "${REPO_PATH} directory already exists, will not download kernel sources" fi