main.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. name: Rust CI
  2. on:
  3. push:
  4. branches:
  5. - master
  6. paths:
  7. - packages/**
  8. - examples/**
  9. - docs/guide/**
  10. - src/**
  11. - .github/**
  12. - lib.rs
  13. - Cargo.toml
  14. - Makefile.toml
  15. - playwright-tests/**
  16. pull_request:
  17. types: [opened, synchronize, reopened, ready_for_review]
  18. branches:
  19. - master
  20. paths:
  21. - packages/**
  22. - examples/**
  23. - src/**
  24. - .github/**
  25. - lib.rs
  26. - Cargo.toml
  27. concurrency:
  28. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  29. cancel-in-progress: true
  30. env:
  31. CARGO_TERM_COLOR: always
  32. CARGO_INCREMENTAL: "0"
  33. SCCACHE_GHA_ENABLED: "true"
  34. # RUSTC_WRAPPER: "sccache"
  35. SCCACHE_IDLE_TIMEOUT: "0"
  36. SCCACHE_GHA_VERSION: "sccache"
  37. SCCACHE_BYPASS_CHECK: "on"
  38. jobs:
  39. check:
  40. if: github.event.pull_request.draft == false
  41. name: Check
  42. runs-on: ubuntu-latest
  43. steps:
  44. - uses: actions/checkout@v4
  45. - run: sudo apt-get update
  46. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  47. - uses: dtolnay/rust-toolchain@stable
  48. - uses: Swatinem/rust-cache@v2
  49. with:
  50. cache-all-crates: "true"
  51. save-if: ${{ github.ref == 'refs/heads/master' }}
  52. - uses: ilammy/setup-nasm@v1
  53. - run: cargo check --all --examples --tests
  54. test:
  55. if: github.event.pull_request.draft == false
  56. name: Test Suite
  57. runs-on: ubuntu-latest
  58. steps:
  59. - uses: actions/checkout@v4
  60. - run: sudo apt-get update
  61. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  62. - uses: dtolnay/rust-toolchain@stable
  63. - uses: Swatinem/rust-cache@v2
  64. with:
  65. cache-all-crates: "true"
  66. save-if: ${{ github.ref == 'refs/heads/master' }}
  67. - uses: ilammy/setup-nasm@v1
  68. - uses: davidB/rust-cargo-make@v1
  69. - uses: browser-actions/setup-firefox@latest
  70. - uses: jetli/wasm-pack-action@v0.4.0
  71. - run: cargo make tests
  72. fmt:
  73. if: github.event.pull_request.draft == false
  74. name: Rustfmt
  75. runs-on: ubuntu-latest
  76. steps:
  77. - uses: actions/checkout@v4
  78. - uses: ilammy/setup-nasm@v1
  79. - uses: dtolnay/rust-toolchain@stable
  80. with:
  81. components: rustfmt
  82. - uses: Swatinem/rust-cache@v2
  83. with:
  84. cache-all-crates: "true"
  85. save-if: ${{ github.ref == 'refs/heads/master' }}
  86. - run: cargo fmt --all -- --check
  87. clippy:
  88. if: github.event.pull_request.draft == false
  89. name: Clippy
  90. runs-on: ubuntu-latest
  91. steps:
  92. - uses: actions/checkout@v4
  93. - run: sudo apt-get update
  94. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  95. - uses: ilammy/setup-nasm@v1
  96. - uses: dtolnay/rust-toolchain@stable
  97. with:
  98. components: rustfmt, clippy
  99. - uses: Swatinem/rust-cache@v2
  100. with:
  101. cache-all-crates: "true"
  102. save-if: ${{ github.ref == 'refs/heads/master' }}
  103. - run: cargo clippy --workspace --examples --tests -- -D warnings
  104. miri:
  105. if: github.event.pull_request.draft == false
  106. name: Miri
  107. runs-on: ubuntu-latest
  108. env:
  109. CARGO_UNSTABLE_SPARSE_REGISTRY: 'true'
  110. RUSTFLAGS: -Dwarnings
  111. RUST_BACKTRACE: 1
  112. MIRIFLAGS: -Zmiri-tag-gc=1
  113. # Change to specific Rust release to pin
  114. rust_stable: stable
  115. rust_nightly: nightly-2023-11-16
  116. rust_clippy: 1.70.0
  117. steps:
  118. - uses: actions/checkout@v4
  119. - uses: ilammy/setup-nasm@v1
  120. - name: Install Rust ${{ env.rust_nightly }}
  121. uses: dtolnay/rust-toolchain@master
  122. with:
  123. toolchain: ${{ env.rust_nightly }}
  124. components: miri
  125. - uses: Swatinem/rust-cache@v2
  126. with:
  127. cache-all-crates: "true"
  128. save-if: ${{ github.ref == 'refs/heads/master' }}
  129. - name: miri
  130. # Many of tests in tokio/tests and doctests use #[tokio::test] or
  131. # #[tokio::main] that calls epoll_create1 that Miri does not support.
  132. # run: cargo miri test --features full --lib --no-fail-fast
  133. run: |
  134. cargo miri test --package dioxus-core -- --exact --nocapture
  135. cargo miri test --package dioxus-native-core --test miri_native -- --exact --nocapture
  136. env:
  137. MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields
  138. PROPTEST_CASES: 10
  139. playwright:
  140. if: github.event.pull_request.draft == false
  141. name: Playwright Tests
  142. runs-on: ubuntu-latest
  143. steps:
  144. # Do our best to cache the toolchain and node install steps
  145. - uses: actions/checkout@v4
  146. - uses: ilammy/setup-nasm@v1
  147. - uses: actions/setup-node@v4
  148. with:
  149. node-version: 16
  150. - name: Install Rust
  151. uses: dtolnay/rust-toolchain@master
  152. with:
  153. toolchain: stable
  154. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  155. - uses: Swatinem/rust-cache@v2
  156. with:
  157. cache-all-crates: "true"
  158. save-if: ${{ github.ref == 'refs/heads/master' }}
  159. - name: Install dependencies
  160. run: npm ci
  161. working-directory: ./playwright-tests
  162. - name: Install Playwright
  163. run: npm install -D @playwright/test
  164. working-directory: ./playwright-tests
  165. - name: Install Playwright Browsers
  166. run: npx playwright install --with-deps
  167. working-directory: ./playwright-tests
  168. # Cache the CLI by using cargo run internally
  169. # - name: Install Dioxus CLI
  170. # uses: actions-rs/cargo@v1
  171. # with:
  172. # command: install
  173. # args: --path packages/cli
  174. - name: Run Playwright tests
  175. run: npx playwright test
  176. working-directory: ./playwright-tests
  177. - uses: actions/upload-artifact@v4
  178. if: always()
  179. with:
  180. name: playwright-report
  181. path: playwright-report/
  182. retention-days: 30
  183. matrix_test:
  184. runs-on: ${{ matrix.platform.os }}
  185. if: github.event.pull_request.draft == false
  186. env:
  187. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  188. strategy:
  189. matrix:
  190. platform:
  191. - {
  192. target: x86_64-pc-windows-msvc,
  193. os: windows-latest,
  194. toolchain: "1.70.0",
  195. cross: false,
  196. command: "test",
  197. args: "--all --tests",
  198. }
  199. - {
  200. target: x86_64-apple-darwin,
  201. os: macos-latest,
  202. toolchain: "1.70.0",
  203. cross: false,
  204. command: "test",
  205. args: "--all --tests",
  206. }
  207. - {
  208. target: aarch64-apple-ios,
  209. os: macos-latest,
  210. toolchain: "1.70.0",
  211. cross: false,
  212. command: "build",
  213. args: "--package dioxus-mobile",
  214. }
  215. - {
  216. target: aarch64-linux-android,
  217. os: ubuntu-latest,
  218. toolchain: "1.70.0",
  219. cross: true,
  220. command: "build",
  221. args: "--package dioxus-mobile",
  222. }
  223. steps:
  224. - uses: actions/checkout@v4
  225. - uses: ilammy/setup-nasm@v1
  226. - name: install stable
  227. uses: dtolnay/rust-toolchain@master
  228. with:
  229. toolchain: ${{ matrix.platform.toolchain }}
  230. targets: ${{ matrix.platform.target }}
  231. components: rustfmt
  232. - name: Install cross
  233. if: ${{ matrix.platform.cross == true }}
  234. uses: taiki-e/install-action@cross
  235. - uses: Swatinem/rust-cache@v2
  236. with:
  237. # The prefix cache key, this can be changed to start a new cache manually.
  238. # default: "v0-rust"
  239. # prefix-key: ""
  240. # A cache key that is used instead of the automatic `job`-based key,
  241. # and is stable over multiple jobs.
  242. # default: empty
  243. # shared-key: ""
  244. # An additional cache key that is added alongside the automatic `job`-based
  245. # cache key and can be used to further differentiate jobs.
  246. # default: empty
  247. key: "${{ matrix.platform.target }}"
  248. # A whitespace separated list of env-var *prefixes* who's value contributes
  249. # to the environment cache key.
  250. # The env-vars are matched by *prefix*, so the default `RUST` var will
  251. # match all of `RUSTC`, `RUSTUP_*`, `RUSTFLAGS`, `RUSTDOC_*`, etc.
  252. # default: "CARGO CC CFLAGS CXX CMAKE RUST"
  253. # env-vars: ""
  254. # The cargo workspaces and target directory configuration.
  255. # These entries are separated by newlines and have the form
  256. # `$workspace -> $target`. The `$target` part is treated as a directory
  257. # relative to the `$workspace` and defaults to "target" if not explicitly given.
  258. # default: ". -> target"
  259. # workspaces: ""
  260. # Additional non workspace directories to be cached, separated by newlines.
  261. # cache-directories: ""
  262. # Determines whether workspace `target` directories are cached.
  263. # If `false`, only the cargo registry will be cached.
  264. # default: "true"
  265. # cache-targets: ""
  266. # Determines if the cache should be saved even when the workflow has failed.
  267. # default: "false"
  268. # cache-on-failure: "true"
  269. # Determines which crates are cached.
  270. # If `true` all crates will be cached, otherwise only dependent crates will be cached.
  271. # Useful if additional crates are used for CI tooling.
  272. # default: "false"
  273. cache-all-crates: "true"
  274. # save-if: ${{ github.ref == 'refs/heads/master' }}
  275. # Determiners whether the cache should be saved.
  276. # If `false`, the cache is only restored.
  277. # Useful for jobs where the matrix is additive e.g. additional Cargo features,
  278. # or when only runs from `master` should be saved to the cache.
  279. # default: "true"
  280. # save-if: ""
  281. # To only cache runs from `master`:
  282. save-if: ${{ github.ref == 'refs/heads/master' }}
  283. # Specifies what to use as the backend providing cache
  284. # Can be set to either "github" or "buildjet"
  285. # default: "github"
  286. # cache-provider: ""
  287. # - uses: mozilla-actions/sccache-action@v0.0.3
  288. # with:
  289. # workspaces: core -> ../target
  290. # save-if: ${{ matrix.features.key == 'all' }}
  291. - name: test
  292. run: |
  293. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}
  294. # Coverage is disabled until we can fix it
  295. # coverage:
  296. # name: Coverage
  297. # runs-on: ubuntu-latest
  298. # container:
  299. # image: xd009642/tarpaulin:develop-nightly
  300. # options: --security-opt seccomp=unconfined
  301. # steps:
  302. # - name: Checkout repository
  303. # uses: actions/checkout@v4
  304. # - name: Generate code coverage
  305. # run: |
  306. # apt-get update &&\
  307. # apt-get install build-essential &&\
  308. # apt install libwebkit2gtk-4.0-dev libgtk-3-dev libayatana-appindicator3-dev -y &&\
  309. # cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out Xml
  310. # - name: Upload to codecov.io
  311. # uses: codecov/codecov-action@v2
  312. # with:
  313. # fail_ci_if_error: false