1name: build and release 2 3on: 4 push: 5 tags: 6 - 'v[0-9]+.[0-9]+.[0-9]*' 7 8concurrency: 9 group: ${{ github.workflow }}-${{ github.event.after }} 10 cancel-in-progress: true 11 12env: 13 # https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.0 14 LLVM_URL_PREFIX: https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0 15 LLVM_arm64: clang+llvm-15.0.0-aarch64-linux-gnu 16 LLVM_amd64: clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4 17 18jobs: 19 build: 20 name: Build static bpftool binary 21 runs-on: ubuntu-22.04 22 env: 23 TARGETARCH: ${{ matrix.arch }} 24 FILE_STRING_ARCH_amd64: x86-64 25 FILE_STRING_ARCH_arm64: aarch64 26 strategy: 27 matrix: 28 arch: [arm64, amd64] 29 30 steps: 31 # amd64 needs the dependencies to build bpftool 32 - name: Install dependencies (amd64) 33 if: matrix.arch == 'amd64' 34 run: | 35 sudo apt-get update 36 sudo apt-get install -y libelf-dev libcap-dev 37 38 - name: Download and extract compiled LLVM release 39 env: 40 LLVM: ${{ env[format('LLVM_{0}', matrix.arch)] }} 41 run: | 42 curl -L -O "${{ env.LLVM_URL_PREFIX}}/${{ env.LLVM }}.tar.xz" 43 tar -xvf "${{ env.LLVM }}.tar.xz" 44 45 - name: Checkout bpftool code 46 uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 47 with: 48 submodules: recursive 49 # Create a new directory to avoid wiping out LLVM on bpftool checkout 50 path: 'bpftool' 51 52 - name: Build static bpftool natively for amd64 53 if: matrix.arch == 'amd64' 54 working-directory: 'bpftool' 55 env: 56 LLVM_PATH: ${{ env[format('LLVM_{0}', matrix.arch)] }} 57 run: | 58 EXTRA_CFLAGS=--static \ 59 LLVM_CONFIG="${GITHUB_WORKSPACE}/${{ env.LLVM_PATH }}/bin/llvm-config" \ 60 LLVM_STRIP="${GITHUB_WORKSPACE}/${{ env.LLVM_PATH }}/bin/llvm-strip" \ 61 HOSTAR="${GITHUB_WORKSPACE}/${{ env.LLVM_PATH }}/bin/llvm-ar" \ 62 make -j -C src V=1 63 strip src/bpftool 64 65 - name: Set up QEMU 66 uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 67 if: matrix.arch == 'arm64' 68 with: 69 platforms: arm64 70 71 # The emulated build leverages Docker and Ubuntu 22.04 container image 72 # distribution to have all the needed arm64 packages. 73 - name: Build static bpftool for arm64 with emulation 74 if: matrix.arch == 'arm64' 75 env: 76 LLVM_PATH: ${{ env[format('LLVM_{0}', matrix.arch)] }} 77 run: | 78 docker run --platform linux/arm64 --rm -v $(pwd):/build ubuntu:22.04 \ 79 bash -c "apt-get update && \ 80 apt-get install -y make pkg-config gcc \ 81 libelf-dev libcap-dev libstdc++-11-dev zlib1g-dev && \ 82 cd /build/bpftool && \ 83 EXTRA_CFLAGS=--static \ 84 LLVM_CONFIG='/build/${{ env.LLVM_PATH }}/bin/llvm-config' \ 85 LLVM_STRIP='/build/${{ env.LLVM_PATH }}/bin/llvm-strip' \ 86 CLANG='/build/${{ env.LLVM_PATH }}/bin/clang' \ 87 make -j -C src V=1 && \ 88 strip src/bpftool" 89 90 - name: Test bpftool binary 91 working-directory: 'bpftool/src' 92 env: 93 ARCH: ${{ env[format('FILE_STRING_ARCH_{0}', matrix.arch)] }} 94 run: | 95 file ./bpftool | \ 96 tee /dev/stderr | \ 97 grep -q "${{ env.ARCH }}" 98 ./bpftool 2>&1 | grep -q Usage 99 ./bpftool -p version | \ 100 tee /dev/stderr | \ 101 jq --exit-status ".features | .llvm and .skeletons" 102 ldd ./bpftool 2>&1 | \ 103 tee /dev/stderr | \ 104 grep -q 'not a dynamic executable' 105 106 - name: Upload Artifact 107 uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 108 with: 109 name: ${{ format('bpftool_{0}', matrix.arch) }} 110 path: bpftool/src/bpftool 111 112 draft-release: 113 name: Create a draft release 114 runs-on: ubuntu-22.04 115 needs: build 116 permissions: 117 contents: write 118 steps: 119 - name: Download artifacts from build 120 uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 121 122 - name: Rename binaries and compress 123 run: | 124 archive_amd64="bpftool-${{ github.ref_name }}-amd64.tar.gz" 125 archive_arm64="bpftool-${{ github.ref_name }}-arm64.tar.gz" 126 tar -C bpftool_amd64 -I 'gzip -9' -cvf "${archive_amd64}" bpftool 127 tar -C bpftool_arm64 -I 'gzip -9' -cvf "${archive_arm64}" bpftool 128 sha256sum "${archive_amd64}" > "${archive_amd64}.sha256sum" 129 sha256sum "${archive_arm64}" > "${archive_arm64}.sha256sum" 130 131 - name: Checkout bpftool and libbpf code 132 uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 133 with: 134 submodules: recursive 135 path: 'bpftool' 136 137 - name: Package source code including submodules 138 uses: qmonnet/git-archive-all-action@791fb850881cf58b1d1fcc9b06c01940080bba0a # v1.0.1 139 with: 140 output-files: bpftool-libbpf-${{ github.ref_name }}-sources.tar.gz 141 base-repo: bpftool 142 143 - name: Create draft release and add artifacts 144 uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15 145 with: 146 draft: true 147 files: bpftool* 148