From 0ab51754448abd732968889025a411fc0d2c7119 Mon Sep 17 00:00:00 2001 From: Manu Bretelle Date: Tue, 24 Oct 2023 14:26:02 -0700 Subject: [PATCH] workflow: move build operations in a reusable workflow This is step 1 of running the kernel build from a re-useable workflow. This change simply move the "build" job in its own reusable workflow file. Signed-off-by: Manu Bretelle --- .github/workflows/kernel-build.yml | 118 +++++++++++++++++++++++++++++ .github/workflows/test.yml | 101 +++--------------------- 2 files changed, 129 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/kernel-build.yml diff --git a/.github/workflows/kernel-build.yml b/.github/workflows/kernel-build.yml new file mode 100644 index 00000000..8bd57f30 --- /dev/null +++ b/.github/workflows/kernel-build.yml @@ -0,0 +1,118 @@ + +name: Reusable build workflow + +on: + workflow_call: + inputs: + arch: + required: true + type: string + toolchain_full: + required: true + type: string + toolchain: + required: true + type: string + runs_on: + required: true + type: string + llvm-version: + required: true + type: string + kernel: + required: true + type: string + + +jobs: + build: + name: build for ${{ inputs.arch }} with ${{ inputs.toolchain_full }} + runs-on: ${{ fromJSON(inputs.runs_on) }} + timeout-minutes: 100 + env: + KERNEL: ${{ inputs.kernel }} + REPO_ROOT: ${{ github.workspace }} + REPO_PATH: "" + KBUILD_OUTPUT: kbuild-output/ + steps: + - uses: actions/checkout@v3 + # We fetch an actual bit of history here to facilitate incremental + # builds (which may check out some earlier upstream change). + with: + fetch-depth: 50 + - if: ${{ github.repository == 'kernel-patches/vmtest' }} + name: Download bpf-next tree + uses: libbpf/ci/get-linux-source@main + with: + dest: '.kernel' + - if: ${{ github.repository == 'kernel-patches/vmtest' }} + name: Move linux source in place + shell: bash + run: | + 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@v3 + 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 }} + - uses: libbpf/ci/patch-kernel@main + with: + patches-root: '${{ github.workspace }}/ci/diffs' + repo-root: '${{ github.workspace }}' + - name: Setup build environment + uses: libbpf/ci/setup-build-env@main + with: + llvm-version: ${{ inputs.llvm-version }} + - name: Build kernel image + uses: libbpf/ci/build-linux@main + with: + arch: ${{ inputs.arch }} + toolchain: ${{ inputs.toolchain }} + kbuild-output: ${{ env.KBUILD_OUTPUT }} + max-make-jobs: 32 + llvm-version: ${{ inputs.llvm-version }} + - name: Build selftests + uses: libbpf/ci/build-selftests@main + with: + toolchain: ${{ inputs.toolchain }} + kbuild-output: ${{ env.KBUILD_OUTPUT }} + max-make-jobs: 32 + llvm-version: ${{ inputs.llvm-version }} + - if: ${{ github.event_name != 'push' }} + name: Build samples + uses: libbpf/ci/build-samples@main + with: + toolchain: ${{ inputs.toolchain }} + kbuild-output: ${{ env.KBUILD_OUTPUT }} + max-make-jobs: 32 + llvm-version: ${{ inputs.llvm-version }} + - name: Tar artifacts + run: | + bash .github/scripts/tar-artifact.sh ${{ inputs.arch }} ${{ inputs.toolchain_full }} + - if: ${{ github.event_name != 'push' }} + name: Remove KBUILD_OUTPUT content + shell: bash + run: | + # Remove $KBUILD_OUTPUT to prevent cache creation for pull requests. + # Only on pushed changes are build artifacts actually cached, because + # of github.com/actions/cache's cache isolation logic. + rm -rf "${KBUILD_OUTPUT}" + - uses: actions/upload-artifact@v3 + with: + name: vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }} + if-no-files-found: error + path: vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf4af269..1e57c6d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,101 +32,22 @@ jobs: - id: set-matrix-impl run: | python3 .github/scripts/matrix.py + + # Build kernel and selftest build: - name: build for ${{ matrix.arch }} with ${{ matrix.toolchain_full }} + uses: ./.github/workflows/kernel-build.yml needs: set-matrix - runs-on: ${{ matrix.runs_on }} - timeout-minutes: 100 strategy: fail-fast: false matrix: ${{ fromJSON(needs.set-matrix.outputs.build-matrix) }} - env: - KERNEL: ${{ matrix.kernel }} - REPO_ROOT: ${{ github.workspace }} - REPO_PATH: "" - KBUILD_OUTPUT: kbuild-output/ - steps: - - uses: actions/checkout@v3 - # We fetch an actual bit of history here to facilitate incremental - # builds (which may check out some earlier upstream change). - with: - fetch-depth: 50 - - if: ${{ github.repository == 'kernel-patches/vmtest' }} - name: Download bpf-next tree - uses: libbpf/ci/get-linux-source@main - with: - dest: '.kernel' - - if: ${{ github.repository == 'kernel-patches/vmtest' }} - name: Move linux source in place - shell: bash - run: | - 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@v3 - with: - path: ${{ env.KBUILD_OUTPUT }} - key: kbuild-output-${{ matrix.arch }}-${{ matrix.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}-${{ steps.get-commit-metadata.outputs.timestamp }}-${{ steps.get-commit-metadata.outputs.commit }} - restore-keys: | - kbuild-output-${{ matrix.arch }}-${{ matrix.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}-${{ steps.get-commit-metadata.outputs.timestamp }}- - kbuild-output-${{ matrix.arch }}-${{ matrix.toolchain_full }}-${{ steps.get-commit-metadata.outputs.branch }}- - kbuild-output-${{ matrix.arch }}-${{ matrix.toolchain_full }}- - - name: Prepare incremental build - shell: bash - run: | - bash .github/scripts/prepare-incremental-builds.sh ${{ steps.get-commit-metadata.outputs.commit }} - - uses: libbpf/ci/patch-kernel@main - with: - patches-root: '${{ github.workspace }}/ci/diffs' - repo-root: '${{ github.workspace }}' - - name: Setup build environment - uses: libbpf/ci/setup-build-env@main - with: - llvm-version: ${{ matrix.llvm-version }} - - name: Build kernel image - uses: libbpf/ci/build-linux@main - with: - arch: ${{ matrix.arch }} - toolchain: ${{ matrix.toolchain }} - kbuild-output: ${{ env.KBUILD_OUTPUT }} - max-make-jobs: 32 - llvm-version: ${{ matrix.llvm-version }} - - name: Build selftests - uses: libbpf/ci/build-selftests@main - with: - toolchain: ${{ matrix.toolchain }} - kbuild-output: ${{ env.KBUILD_OUTPUT }} - max-make-jobs: 32 - llvm-version: ${{ matrix.llvm-version }} - - if: ${{ github.event_name != 'push' }} - name: Build samples - uses: libbpf/ci/build-samples@main - with: - toolchain: ${{ matrix.toolchain }} - kbuild-output: ${{ env.KBUILD_OUTPUT }} - max-make-jobs: 32 - llvm-version: ${{ matrix.llvm-version }} - - name: Tar artifacts - run: | - bash .github/scripts/tar-artifact.sh ${{ matrix.arch }} ${{ matrix.toolchain_full }} - - if: ${{ github.event_name != 'push' }} - name: Remove KBUILD_OUTPUT content - shell: bash - run: | - # Remove $KBUILD_OUTPUT to prevent cache creation for pull requests. - # Only on pushed changes are build artifacts actually cached, because - # of github.com/actions/cache's cache isolation logic. - rm -rf "${KBUILD_OUTPUT}" - - uses: actions/upload-artifact@v3 - with: - name: vmlinux-${{ matrix.arch }}-${{ matrix.toolchain_full }} - if-no-files-found: error - path: vmlinux-${{ matrix.arch }}-${{ matrix.toolchain_full }}.tar.zst + with: + arch: ${{ matrix.arch }} + toolchain_full: ${{ matrix.toolchain_full }} + toolchain: ${{ matrix.toolchain }} + runs_on: ${{ toJSON(matrix.runs_on) }} + llvm-version: ${{ matrix.llvm-version }} + kernel: ${{ matrix.kernel }} + test: if: ${{ github.event_name != 'push' }} name: ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }}