Skip to content

Commit

Permalink
Factor out tar-artifacts action (#148)
Browse files Browse the repository at this point in the history
Rework tar-artifact.sh script, making it suitable for use as an
independent github action.

Use tar -rf (append) to accumulate files of interest before
compressing with zstd.

Control groups of artifacts to include (e.g. selftests/bpf,
selftests/sched_ext) with environment variables.
  • Loading branch information
theihor authored Oct 24, 2024
1 parent eb86fb2 commit 4c85516
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 116 deletions.
107 changes: 0 additions & 107 deletions .github/scripts/tar-artifact.sh

This file was deleted.

26 changes: 17 additions & 9 deletions .github/workflows/kernel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ jobs:
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: 100
env:
ARCHIVE_MAKE_HELPERS: ${{ github.repository != 'kernel-patches/bpf' && 'true' || '' }}
KERNEL: ${{ inputs.kernel }}
REPO_ROOT: ${{ github.workspace }}
REPO_PATH: ""
KBUILD_OUTPUT: ${{ github.workspace }}/kbuild-output
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' || '' }}
KBUILD_OUTPUT: ${{ github.workspace }}/kbuild-output
KERNEL: ${{ inputs.kernel }}
REPO_PATH: ""
REPO_ROOT: ${{ github.workspace }}
steps:
- uses: actions/checkout@v4
# We fetch an actual bit of history here to facilitate incremental
Expand Down Expand Up @@ -140,9 +140,17 @@ jobs:
max-make-jobs: 32
llvm-version: ${{ inputs.llvm-version }}
- name: Tar artifacts
working-directory: ${{ env.REPO_ROOT }}
run: |
bash .github/scripts/tar-artifact.sh ${{ inputs.arch }} ${{ inputs.toolchain_full }}
id: tar-artifacts
uses: ./tar-artifacts
env:
ARCHIVE_BPF_SELFTESTS: 'true'
ARCHIVE_MAKE_HELPERS: ${{ github.repository != 'kernel-patches/bpf' && 'true' || '' }}
ARCHIVE_SCHED_EXT_SELFTESTS: ${{ env.BUILD_SCHED_EXT_SELFTESTS }}
with:
arch: ${{ inputs.arch }}
archive: ${{ env.ARTIFACTS_ARCHIVE }}
kbuild-output: ${{ env.KBUILD_OUTPUT }}
repo-root: ${{ env.REPO_ROOT }}
- if: ${{ github.event_name != 'push' }}
name: Remove KBUILD_OUTPUT content
shell: bash
Expand All @@ -155,4 +163,4 @@ jobs:
with:
name: vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}${{ inputs.release && '-release' || '' }}
if-no-files-found: error
path: vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst
path: ${{ env.ARTIFACTS_ARCHIVE }}
34 changes: 34 additions & 0 deletions tar-artifacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Tar build artifacts

This action creates a tarball with kbuild-output and other build
artifacts necessary to run the selftests.

The action is expected to be executed by a workflow with access to the
Linux kernel repository.

## Required inputs

* `arch` - Kernel build architecture, required to find image_name
* `archive` - path to the produced .zst archive
* `kbuild-output` - Path to the kernel build output
* `repo-root` - Path to the root of the Linux kernel repository

# Archive options

Essential content of the directory passed via `kbuild-output` input is
always included in the tarball.

For selftests artifacts the script checks environment variables to
determine what to include. These are handled as bash flags:
emptystring means false, any other value means true.

* `ARCHIVE_BPF_SELFTESTS` - add `tools/testing/selftests/bpf` binaries
under `selftests/bpf` in the tarball
* `ARCHIVE_MAKE_HELPERS` - add all the Linux repo makefiles and other
scripts
* `ARCHIVE_SCHED_EXT_SELFTESTS` - add
`tools/testing/selftests/sched_ext` binaries under
`selftests/sched_ext` in the tarball



26 changes: 26 additions & 0 deletions tar-artifacts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'Tar build artifacts'
inputs:
arch:
description: 'Target arch of the kernel, required for finding the image'
required: true
archive:
description: 'Path to the output archive'
required: true
kbuild-output:
description: 'Path to the kernel build output for archiving'
required: true
repo-root:
description: "Path to the root of the kernel repository"
required: true

runs:
using: "composite"
steps:
- name: Run tar-artifacts.sh
env:
KBUILD_OUTPUT: ${{ inputs.kbuild-output }}
REPO_ROOT: ${{ inputs.repo-root }}
ARCH: ${{ inputs.arch }}
shell: bash
run:
${GITHUB_ACTION_PATH}/tar-artifacts.sh ${{ inputs.archive }}
79 changes: 79 additions & 0 deletions tar-artifacts/tar-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

set -eux -o pipefail

if [ ! -d "${REPO_ROOT:-}" ]; then
echo "REPO_ROOT must be a directory: ${REPO_ROOT}"
exit 1
fi

if [ ! -d "${KBUILD_OUTPUT:-}" ]; then
echo "KBUILD_OUTPUT must be a directory: ${KBUILD_OUTPUT}"
exit 1
fi

zst_tarball="$1"
arch="${ARCH}"

ARCHIVE_BPF_SELFTESTS="${ARCHIVE_BPF_SELFTESTS:-true}"
ARCHIVE_MAKE_HELPERS="${ARCHIVE_MAKE_HELPERS:-}"
ARCHIVE_SCHED_EXT_SELFTESTS="${ARCHIVE_SCHED_EXT_SELFTESTS:-}"

tarball=$(mktemp ./artifacts.XXXXXXXX.tar)

source "${GITHUB_ACTION_PATH}/../helpers.sh"

# Strip debug information, which is excessively large (consuming
# bandwidth) while not actually being used (the kernel does not use
# DWARF to symbolize stacktraces).
"${arch}"-linux-gnu-strip --strip-debug "${KBUILD_OUTPUT}"/vmlinux

image_name=$(make -C ${REPO_ROOT} ARCH="$(platform_to_kernel_arch "${arch}")" -s image_name)
kbuild_output_file_list=(
".config"
"${image_name}"
"include/config/auto.conf"
"include/generated/autoconf.h"
"vmlinux"
)

tar -rf "${tarball}" -C "${KBUILD_OUTPUT}" \
--transform "s,^,kbuild-output/," \
"${kbuild_output_file_list[@]}"

# In case artifacts are restored not to the kernel repo root,
# package up a bunch of additional infrastructure to support running
# 'make kernelrelease' and bpf tool checks later on.
if [[ -n "${ARCHIVE_MAKE_HELPERS}" ]]; then
find "${REPO_ROOT}" -iname Makefile -printf '%P\n' \
| tar -rf "${tarball}" -C "${REPO_ROOT}" -T -
tar -rf "${tarball}" -C "${REPO_ROOT}" \
--exclude '*.o' \
--exclude '*.d' \
"scripts/" \
"tools/testing/selftests/bpf/" \
"tools/include/" \
"tools/bpf/bpftool/"
fi

if [[ -n "${ARCHIVE_BPF_SELFTESTS}" ]]; then
# add .bpf.o files
find "${REPO_ROOT}/tools/testing/selftests/bpf" \
-name "*.bpf.o" -printf 'selftests/bpf/%P\n' \
| tar -rf "${tarball}" -C "${REPO_ROOT}/tools/testing" -T -
# add other relevant files
tar -rf "${tarball}" -C "${REPO_ROOT}/tools/testing" \
--exclude '*.cmd' \
--exclude '*.d' \
--exclude '*.h' \
--exclude '*.o' \
--exclude '*.output' \
selftests/bpf/
fi

if [[ -n "${ARCHIVE_SCHED_EXT_SELFTESTS}" ]]; then
tar -rf "${tarball}" -C "${REPO_ROOT}/tools/testing" selftests/sched_ext/
fi

zstd -T0 -19 -i "${tarball}" -o "${zst_tarball}"

0 comments on commit 4c85516

Please sign in to comment.