diff --git a/.github/scripts/get-commit-metadata.sh b/.github/scripts/get-commit-metadata.sh deleted file mode 100644 index f178786..0000000 --- a/.github/scripts/get-commit-metadata.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -branch="${GITHUB_BASE_REF}" - -if [ "${GITHUB_EVENT_NAME}" = 'push' ]; then - branch="${GITHUB_REF_NAME}" -fi - -echo "branch=${branch}" >> "${GITHUB_OUTPUT}" - -upstream="${branch//_base/}" -commit="$( - git rev-parse "origin/${upstream}" &> /dev/null \ - || ( - git fetch --quiet --prune --no-tags --depth=1 --no-recurse-submodules origin "+refs/heads/${upstream}:refs/remotes/origin/${upstream}" && \ - git rev-parse "origin/${upstream}" - ) -)" -timestamp_utc="$(TZ=utc git show --format='%cd' --no-patch --date=iso-strict-local "${commit}")" - -echo "timestamp=${timestamp_utc}" >> "${GITHUB_OUTPUT}" -echo "commit=${commit}" >> "${GITHUB_OUTPUT}" -echo "Most recent upstream commit is ${commit}" diff --git a/.github/workflows/kernel-build.yml b/.github/workflows/kernel-build.yml index f26bf1d..ee32c9b 100644 --- a/.github/workflows/kernel-build.yml +++ b/.github/workflows/kernel-build.yml @@ -49,6 +49,11 @@ jobs: REPO_ROOT: ${{ github.workspace }} REPO_PATH: "" KBUILD_OUTPUT: kbuild-output/ + BASE_BRANCH: >- + ${{ github.event_name == 'push' && github.ref_name + || github.base_ref + || 'bpf-next_base' + }} steps: - uses: actions/checkout@v4 # We fetch an actual bit of history here to facilitate incremental @@ -67,23 +72,12 @@ jobs: rm -rf .kernel/.git cp -rf .kernel/. . rm -rf .kernel - - name: Get commit meta-data - id: get-commit-metadata - run: | - bash .github/scripts/get-commit-metadata.sh - - name: Pull recent KBUILD_OUTPUT contents - uses: actions/cache@v4 + - uses: ./prepare-incremental-build with: - path: ${{ env.KBUILD_OUTPUT }} - key: kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}-${{ steps.get-commit-metadata.outputs.timestamp }}-${{ steps.get-commit-metadata.outputs.commit }} - restore-keys: | - kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}-${{ steps.get-commit-metadata.outputs.timestamp }}- - kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}- - kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}- - - name: Prepare incremental build - shell: bash - run: | - bash .github/scripts/prepare-incremental-builds.sh ${{ steps.get-commit-metadata.outputs.commit }} + repo-root: ${{ env.REPO_ROOT }} + base-branch: ${{ env.BASE_BRANCH }} + arch: ${{ inputs.arch }} + toolchain_full: ${{ inputs.toolchain_full }} - uses: ./patch-kernel with: repo-root: '${{ github.workspace }}' diff --git a/prepare-incremental-build/action.yml b/prepare-incremental-build/action.yml new file mode 100644 index 0000000..bfdbcb1 --- /dev/null +++ b/prepare-incremental-build/action.yml @@ -0,0 +1,52 @@ +name: 'Prepare incremental kernel build' +description: 'Pull cached kernel build output from previous runs and prepare the repo for incremental build' +inputs: + repo-root: + description: "Root of the kernel repository" + required: true + default: ${{ github.workspace }} + base-branch: + description: "Base branch for cache lookup" + required: true + default: bpf-next_base + arch: + required: true + type: string + description: "Part of cache lookup key" + toolchain_full: + required: true + type: string + description: "Part of cache lookup key" + kbuild-output: + required: true + type: string + description: "Path to KBUILD_OUTPUT" + default: kbuild-output + +runs: + using: "composite" + steps: + + - name: Get commit meta-data for cache lookup + id: get-commit-metadata + shell: bash + working-directory: ${{ inputs.repo-root }} + run: ${GITHUB_ACTION_PATH}/get-commit-metadata.sh ${{ inputs.base-branch }} + + - name: Pull recent KBUILD_OUTPUT contents + uses: actions/cache@v4 + with: + path: ${{ inputs.kbuild-output }} + key: kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}-${{ steps.get-commit-metadata.outputs.timestamp }}-${{ steps.get-commit-metadata.outputs.commit }} + restore-keys: | + kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}-${{ steps.get-commit-metadata.outputs.timestamp }}- + kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}- + kbuild-output-${{ inputs.arch }}-${{ inputs.toolchain_full }}- + + - name: Prepare incremental build + shell: bash + env: + KBUILD_OUTPUT: ${{ inputs.kbuild-output }} + working-directory: ${{ inputs.repo-root }} + run: ${GITHUB_ACTION_PATH}/prepare-incremental-builds.sh ${{ steps.get-commit-metadata.outputs.commit }} + diff --git a/prepare-incremental-build/get-commit-metadata.sh b/prepare-incremental-build/get-commit-metadata.sh new file mode 100755 index 0000000..99ad601 --- /dev/null +++ b/prepare-incremental-build/get-commit-metadata.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# branch="${GITHUB_BASE_REF}" + +# if [ "${GITHUB_EVENT_NAME}" = 'push' ]; then +# branch="${GITHUB_REF_NAME}" +# fi + +set -eux + +branch=${1:-bpf-next_base} + +echo "branch=${branch}" >> "${GITHUB_OUTPUT}" + +upstream="${branch//_base/}" + +git fetch --quiet --prune --no-tags --depth=1 --no-recurse-submodules \ + origin "+refs/heads/${upstream}:refs/remotes/origin/${upstream}" +commit=$(git rev-parse "origin/${upstream}") + +timestamp_utc="$(TZ=utc git show --format='%cd' --no-patch --date=iso-strict-local "${commit}")" + +echo "timestamp=${timestamp_utc}" >> "${GITHUB_OUTPUT}" +echo "commit=${commit}" >> "${GITHUB_OUTPUT}" +echo "Most recent upstream commit is ${commit}" + diff --git a/.github/scripts/prepare-incremental-builds.sh b/prepare-incremental-build/prepare-incremental-builds.sh old mode 100644 new mode 100755 similarity index 100% rename from .github/scripts/prepare-incremental-builds.sh rename to prepare-incremental-build/prepare-incremental-builds.sh