ci.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. name: aya-ci
  2. on:
  3. push:
  4. pull_request:
  5. schedule:
  6. - cron: 00 4 * * *
  7. env:
  8. CARGO_TERM_COLOR: always
  9. jobs:
  10. lint:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - uses: actions/checkout@v4
  14. - uses: dtolnay/rust-toolchain@nightly
  15. with:
  16. components: clippy,miri,rustfmt,rust-src
  17. # Installed *after* nightly so it is the default.
  18. - uses: dtolnay/rust-toolchain@stable
  19. - uses: Swatinem/rust-cache@v2
  20. - uses: taiki-e/install-action@v2
  21. with:
  22. tool: cargo-hack,taplo-cli
  23. - run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror
  24. - uses: DavidAnson/markdownlint-cli2-action@v20
  25. - run: taplo fmt --check
  26. - run: cargo +nightly fmt --all -- --check
  27. - run: ./clippy.sh
  28. - run: cargo xtask public-api
  29. if: github.event_name == 'pull_request'
  30. - run: cargo xtask public-api --bless
  31. if: github.event_name != 'pull_request' && github.repository_owner == 'aya-rs'
  32. - uses: peter-evans/create-pull-request@v7
  33. if: github.event_name != 'pull_request' && github.repository_owner == 'aya-rs'
  34. with:
  35. # GitHub actions aren't allowed to trigger other actions to prevent
  36. # abuse; the canonical workaround is to use a sufficiently authorized
  37. # token.
  38. #
  39. # See https://github.com/peter-evans/create-pull-request/issues/48.
  40. token: ${{ secrets.CRABBY_GITHUB_TOKEN }}
  41. branch: create-pull-request/public-api
  42. commit-message: 'public-api: regenerate'
  43. title: 'public-api: regenerate'
  44. body: |
  45. **Automated changes**
  46. - name: Run miri
  47. run: |
  48. set -euxo pipefail
  49. cargo +nightly hack miri test --all-targets --feature-powerset \
  50. --exclude aya-ebpf \
  51. --exclude aya-ebpf-bindings \
  52. --exclude aya-log-ebpf \
  53. --exclude integration-ebpf \
  54. --exclude integration-test \
  55. --workspace
  56. build-test-aya:
  57. strategy:
  58. fail-fast: false
  59. matrix:
  60. arch:
  61. - aarch64-unknown-linux-gnu
  62. - armv7-unknown-linux-gnueabi
  63. - powerpc64le-unknown-linux-gnu
  64. - riscv64gc-unknown-linux-gnu
  65. - s390x-unknown-linux-gnu
  66. - x86_64-unknown-linux-gnu
  67. runs-on: ubuntu-latest
  68. steps:
  69. - uses: actions/checkout@v4
  70. - uses: dtolnay/rust-toolchain@stable
  71. with:
  72. targets: ${{ matrix.arch }}
  73. - uses: Swatinem/rust-cache@v2
  74. - uses: taiki-e/install-action@cargo-hack
  75. # This is magic, it sets `$CARGO_BUILD_TARGET`.
  76. - uses: taiki-e/setup-cross-toolchain-action@v1
  77. with:
  78. target: ${{ matrix.arch }}
  79. - name: Build
  80. run: |
  81. set -euxo pipefail
  82. cargo hack build --all-targets --feature-powerset \
  83. --exclude aya-ebpf \
  84. --exclude aya-ebpf-bindings \
  85. --exclude aya-log-ebpf \
  86. --exclude integration-ebpf \
  87. --exclude xtask \
  88. --workspace
  89. - name: Test
  90. env:
  91. RUST_BACKTRACE: full
  92. run: |
  93. set -euxo pipefail
  94. cargo hack test --all-targets --feature-powerset \
  95. --exclude aya-ebpf \
  96. --exclude aya-ebpf-bindings \
  97. --exclude aya-log-ebpf \
  98. --exclude integration-ebpf \
  99. --exclude integration-test \
  100. --exclude xtask \
  101. --workspace
  102. - name: Doctests
  103. env:
  104. RUST_BACKTRACE: full
  105. run: |
  106. set -euxo pipefail
  107. cargo hack test --doc --feature-powerset \
  108. --exclude aya-ebpf \
  109. --exclude aya-ebpf-bindings \
  110. --exclude aya-log-ebpf \
  111. --exclude init \
  112. --exclude integration-ebpf \
  113. --exclude integration-test \
  114. --exclude xtask \
  115. --workspace
  116. build-test-aya-ebpf:
  117. strategy:
  118. fail-fast: false
  119. matrix:
  120. bpf_target_arch:
  121. - aarch64
  122. - arm
  123. - mips
  124. - powerpc64
  125. - riscv64
  126. - s390x
  127. - x86_64
  128. target:
  129. - bpfel-unknown-none
  130. - bpfeb-unknown-none
  131. runs-on: ubuntu-latest
  132. steps:
  133. - uses: actions/checkout@v4
  134. - uses: dtolnay/rust-toolchain@nightly
  135. with:
  136. components: rust-src
  137. # Installed *after* nightly so it is the default.
  138. - uses: dtolnay/rust-toolchain@stable
  139. - uses: Swatinem/rust-cache@v2
  140. - run: cargo install --git https://github.com/aya-rs/bpf-linker.git
  141. - uses: taiki-e/install-action@cargo-hack
  142. - name: Build
  143. env:
  144. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
  145. run: |
  146. set -euxo pipefail
  147. cargo +nightly hack build \
  148. --target ${{ matrix.target }} \
  149. -Z build-std=core \
  150. --package aya-ebpf \
  151. --package aya-log-ebpf \
  152. --feature-powerset
  153. - name: Test
  154. env:
  155. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
  156. RUST_BACKTRACE: full
  157. run: |
  158. set -euxo pipefail
  159. cargo hack test \
  160. --doc \
  161. --package aya-ebpf \
  162. --package aya-log-ebpf \
  163. --feature-powerset
  164. run-integration-test:
  165. strategy:
  166. fail-fast: false
  167. matrix:
  168. include:
  169. - target: x86_64-apple-darwin
  170. # macos-14 is arm64[0] which doesn't support nested
  171. # virtualization[1].
  172. #
  173. # [0] https://github.com/actions/runner-images#available-images
  174. #
  175. # [1] https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#limitations-for-arm64-macos-runners
  176. os: macos-13
  177. # We don't use ubuntu-latest because we care about the apt packages available.
  178. - target: x86_64-unknown-linux-gnu
  179. os: ubuntu-22.04
  180. - target: aarch64-unknown-linux-gnu
  181. os: ubuntu-22.04-arm
  182. runs-on: ${{ matrix.os }}
  183. steps:
  184. - uses: actions/checkout@v4
  185. with:
  186. submodules: recursive
  187. - name: Install prerequisites
  188. if: runner.os == 'Linux'
  189. # ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
  190. # enum values was added in clang 15[1] which isn't in `$PATH`.
  191. #
  192. # [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
  193. #
  194. # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
  195. run: |
  196. set -euxo pipefail
  197. sudo apt update
  198. sudo apt -y install lynx qemu-system-{arm,x86} musl-tools
  199. echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
  200. - name: Install prerequisites
  201. if: runner.os == 'macOS'
  202. # The curl shipped on macOS doesn't contain
  203. # https://github.com/curl/curl/commit/85efbb92b8e6679705e122cee45ce76c56414a3e which is
  204. # needed for proper handling of `--etag-{compare,save}`.
  205. #
  206. # The tar shipped on macOS doesn't support --wildcards, so we need GNU tar.
  207. #
  208. # The clang shipped on macOS doesn't support BPF, so we need LLVM from brew.
  209. #
  210. # We need a musl C toolchain to compile our `test-distro` since some of
  211. # our dependencies have build scripts that compile C code (i.e xz2).
  212. # This is provided by `brew install filosottile/musl-cross/musl-cross`.
  213. run: |
  214. set -euxo pipefail
  215. brew update
  216. # https://github.com/actions/setup-python/issues/577
  217. find /usr/local/bin -type l -exec sh -c 'readlink -f "$1" \
  218. | grep -q ^/Library/Frameworks/Python.framework/Versions/' _ {} \; -exec rm -v {} \;
  219. brew install --formula curl dpkg gnu-tar llvm lynx pkg-config qemu
  220. echo $(brew --prefix curl)/bin >> $GITHUB_PATH
  221. echo $(brew --prefix gnu-tar)/libexec/gnubin >> $GITHUB_PATH
  222. echo $(brew --prefix llvm)/bin >> $GITHUB_PATH
  223. brew install filosottile/musl-cross/musl-cross
  224. ln -s "$(brew --prefix musl-cross)/bin/x86_64-linux-musl-gcc" /usr/local/bin/musl-gcc
  225. - uses: dtolnay/rust-toolchain@nightly
  226. with:
  227. components: rust-src
  228. # Installed *after* nightly so it is the default.
  229. - uses: dtolnay/rust-toolchain@stable
  230. with:
  231. targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
  232. - uses: Swatinem/rust-cache@v2
  233. - name: Install libLLVM
  234. # Download libLLVM from Rust CI to ensure that the libLLVM version
  235. # matches exactly with the version used by the current Rust nightly. A
  236. # mismatch between libLLVM (used by bpf-linker) and Rust's LLVM version
  237. # can lead to linking issues.
  238. run: |
  239. set -euxo pipefail
  240. # Get the partial SHA from Rust nightly.
  241. rustc_sha=$(rustc +nightly --version | grep -oE '[a-f0-9]{7,40}')
  242. # Get the full SHA from GitHub.
  243. rustc_sha=$(curl -sfSL https://api.github.com/repos/rust-lang/rust/commits/$rustc_sha \
  244. --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
  245. --header 'content-type: application/json' \
  246. | jq -r '.sha')
  247. mkdir -p /tmp/rustc-llvm
  248. curl -sfSL https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-${{ matrix.target }}.tar.xz | \
  249. tar -xJ --strip-components 2 -C /tmp/rustc-llvm
  250. echo /tmp/rustc-llvm/bin >> $GITHUB_PATH
  251. # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also
  252. # --force so that bpf-linker gets always relinked against the latest LLVM downloaded above.
  253. #
  254. # Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so.
  255. - run: cargo install --git https://github.com/aya-rs/bpf-linker.git --no-default-features --force
  256. - uses: actions/cache@v4
  257. with:
  258. path: test/.tmp
  259. key: ${{ runner.arch }}-${{ runner.os }}-test-cache
  260. - name: Download debian kernels
  261. if: runner.arch == 'ARM64'
  262. # TODO: enable tests on kernels before 6.0.
  263. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/arm64 arm64 6.1 6.12
  264. - name: Download debian kernels
  265. if: runner.arch == 'X64'
  266. # TODO: enable tests on kernels before 6.0.
  267. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/amd64 amd64 6.1 6.12
  268. - name: Cleanup stale kernels and modules
  269. run: |
  270. set -euxo pipefail
  271. rm -rf test/.tmp/boot test/.tmp/lib
  272. - name: Extract debian kernels
  273. run: |
  274. set -euxo pipefail
  275. # The wildcard '**/boot/*' extracts kernel images and config.
  276. # The wildcard '**/modules/*' extracts kernel modules.
  277. # Modules are required since not all parts of the kernel we want to
  278. # test are built-in.
  279. find test/.tmp -name '*.deb' -print0 | xargs -t -0 -I {} \
  280. sh -c "dpkg --fsys-tarfile {} | tar -C test/.tmp \
  281. --wildcards --extract '**/boot/*' '**/modules/*' --file -"
  282. - name: Run local integration tests
  283. if: runner.os == 'Linux'
  284. run: cargo xtask integration-test local
  285. - name: Run virtualized integration tests
  286. if: runner.os == 'Linux'
  287. run: |
  288. set -euxo pipefail
  289. .github/scripts/find_kernels.py | xargs -t -0 \
  290. cargo xtask integration-test vm --cache-dir test/.tmp \
  291. --github-api-token ${{ secrets.GITHUB_TOKEN }} \
  292. - name: Run virtualized integration tests
  293. if: runner.os == 'macOS'
  294. env:
  295. # This sets the linker to the one installed by FiloSottile/musl-cross.
  296. CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: x86_64-linux-musl-gcc
  297. run: |
  298. set -euxo pipefail
  299. .github/scripts/find_kernels.py | xargs -t -0 \
  300. cargo xtask integration-test vm --cache-dir test/.tmp \
  301. --github-api-token ${{ secrets.GITHUB_TOKEN }} \
  302. # Provides a single status check for the entire build workflow.
  303. # This is used for merge automation, like Mergify, since GH actions
  304. # has no concept of "when all status checks pass".
  305. # https://docs.mergify.com/conditions/#validating-all-status-checks
  306. build-workflow-complete:
  307. needs:
  308. - lint
  309. - build-test-aya
  310. - build-test-aya-ebpf
  311. - run-integration-test
  312. runs-on: ubuntu-latest
  313. steps:
  314. - run: echo 'Build Complete'