ci.yml 11 KB

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