main.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. # Whenever an open PR is updated, the workflow will be triggered
  2. #
  3. # This can get expensive, so we do a lot of caching and checks to prevent unnecessary runs
  4. name: Rust CI
  5. on:
  6. push:
  7. branches:
  8. - main
  9. paths:
  10. - packages/**
  11. - examples/**
  12. - docs/guide/**
  13. - src/**
  14. - .github/**
  15. - lib.rs
  16. - Cargo.toml
  17. - Makefile.toml
  18. pull_request:
  19. types: [opened, synchronize, reopened, ready_for_review]
  20. branches:
  21. - main
  22. paths:
  23. - packages/**
  24. - examples/**
  25. - src/**
  26. - .github/**
  27. - lib.rs
  28. - Cargo.toml
  29. # workflow_dispatch:
  30. concurrency:
  31. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  32. cancel-in-progress: true
  33. env:
  34. CARGO_TERM_COLOR: always
  35. CARGO_INCREMENTAL: "0"
  36. RUST_BACKTRACE: 1
  37. rust_nightly: nightly-2024-10-20
  38. jobs:
  39. check-msrv:
  40. if: github.event.pull_request.draft == false
  41. name: Check MSRV
  42. runs-on: ubuntu-latest
  43. steps:
  44. - uses: actions/checkout@v4
  45. - uses: dtolnay/rust-toolchain@stable
  46. - uses: Swatinem/rust-cache@v2
  47. with:
  48. cache-all-crates: "true"
  49. save-if: ${{ github.ref == 'refs/heads/main' }}
  50. # https://github.com/foresterre/cargo-msrv/blob/4345edfe3f4fc91cc8ae6c7d6804c0748fae92ae/.github/workflows/msrv.yml
  51. - name: install_cargo_msrv
  52. run: cargo install cargo-msrv --all-features
  53. - name: version_of_cargo_msrv
  54. run: cargo msrv --version
  55. - name: run_cargo_msrv
  56. run: cargo msrv --output-format json verify -- cargo check
  57. - name: run_cargo_msrv_on_verify_failure
  58. if: ${{ failure() }}
  59. run: cargo msrv --output-format json -- cargo check
  60. test:
  61. if: github.event.pull_request.draft == false
  62. name: Test Suite
  63. runs-on: ubuntu-latest
  64. steps:
  65. - uses: actions/checkout@v4
  66. - name: Free Disk Space (Ubuntu)
  67. uses: jlumbroso/free-disk-space@v1.3.1
  68. with: # speed things up a bit
  69. large-packages: false
  70. docker-images: false
  71. swap-storage: false
  72. - run: sudo apt-get update
  73. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  74. - uses: dtolnay/rust-toolchain@stable
  75. - uses: Swatinem/rust-cache@v2
  76. with:
  77. cache-all-crates: "true"
  78. save-if: ${{ github.ref == 'refs/heads/main' }}
  79. - uses: davidB/rust-cargo-make@v1
  80. - uses: browser-actions/setup-firefox@latest
  81. - uses: jetli/wasm-pack-action@v0.4.0
  82. - run: cargo make tests
  83. release-test:
  84. if: github.event.pull_request.draft == false
  85. name: Test Suite with Optimizations
  86. runs-on: ubuntu-latest
  87. steps:
  88. - uses: actions/checkout@v4
  89. - name: Free Disk Space (Ubuntu)
  90. uses: jlumbroso/free-disk-space@v1.3.1
  91. with: # speed things up a bit
  92. large-packages: false
  93. docker-images: false
  94. swap-storage: false
  95. - run: sudo apt-get update
  96. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  97. - uses: dtolnay/rust-toolchain@stable
  98. - uses: Swatinem/rust-cache@v2
  99. with:
  100. cache-all-crates: "true"
  101. save-if: ${{ github.ref == 'refs/heads/main' }}
  102. - uses: davidB/rust-cargo-make@v1
  103. - uses: browser-actions/setup-firefox@latest
  104. - uses: jetli/wasm-pack-action@v0.4.0
  105. - run: cargo test --profile release-unoptimized --lib --bins --tests --examples --workspace --exclude dioxus-desktop --exclude dioxus-mobile
  106. fmt:
  107. if: github.event.pull_request.draft == false
  108. name: Rustfmt
  109. runs-on: ubuntu-latest
  110. steps:
  111. - uses: actions/checkout@v4
  112. - uses: dtolnay/rust-toolchain@stable
  113. with:
  114. components: rustfmt
  115. - uses: Swatinem/rust-cache@v2
  116. with:
  117. cache-all-crates: "true"
  118. save-if: ${{ github.ref == 'refs/heads/main' }}
  119. - run: cargo fmt --all -- --check
  120. typos:
  121. if: github.event.pull_request.draft == false
  122. name: Check for typos
  123. runs-on: ubuntu-latest
  124. steps:
  125. - uses: actions/checkout@v4
  126. - name: Check for typos
  127. uses: crate-ci/typos@master
  128. docs:
  129. if: github.event.pull_request.draft == false
  130. name: Docs
  131. runs-on: ubuntu-latest
  132. steps:
  133. - uses: actions/checkout@v4
  134. - run: sudo apt-get update
  135. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  136. - name: Install Rust ${{ env.rust_nightly }}
  137. uses: dtolnay/rust-toolchain@nightly
  138. with:
  139. toolchain: ${{ env.rust_nightly }}
  140. - uses: Swatinem/rust-cache@v2
  141. with:
  142. cache-all-crates: "true"
  143. save-if: ${{ github.ref == 'refs/heads/main' }}
  144. - name: "doc --lib --all-features"
  145. run: |
  146. cargo doc --workspace --no-deps --all-features --document-private-items
  147. # env:
  148. # RUSTFLAGS: --cfg docsrs
  149. # RUSTDOCFLAGS: --cfg docsrs
  150. # todo: re-enable warnings, private items
  151. # RUSTDOCFLAGS: --cfg docsrs -Dwarnings
  152. # --document-private-items
  153. # Check for invalid links in the repository
  154. link-check:
  155. if: github.event.pull_request.draft == false
  156. name: Check For Invalid Links
  157. runs-on: ubuntu-latest
  158. steps:
  159. - uses: actions/checkout@v4
  160. - name: Restore lychee cache
  161. uses: actions/cache@v4
  162. with:
  163. path: .lycheecache
  164. key: cache-lychee-${{ github.sha }}
  165. restore-keys: cache-lychee-
  166. - name: Run lychee
  167. uses: lycheeverse/lychee-action@v2
  168. with:
  169. args: --base . --config ./lychee.toml './**/*.md'
  170. fail: true
  171. check:
  172. if: github.event.pull_request.draft == false
  173. name: Check
  174. runs-on: ubuntu-latest
  175. steps:
  176. - uses: actions/checkout@v4
  177. - run: sudo apt-get update
  178. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
  179. - uses: dtolnay/rust-toolchain@stable
  180. - uses: Swatinem/rust-cache@v2
  181. with:
  182. cache-all-crates: "true"
  183. save-if: ${{ github.ref == 'refs/heads/main' }}
  184. - run: cargo check --workspace --all-features --all-targets
  185. clippy:
  186. if: github.event.pull_request.draft == false
  187. name: Clippy
  188. runs-on: ubuntu-latest
  189. steps:
  190. - uses: actions/checkout@v4
  191. - run: sudo apt-get update
  192. - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
  193. - uses: dtolnay/rust-toolchain@stable
  194. with:
  195. components: rustfmt, clippy
  196. - uses: Swatinem/rust-cache@v2
  197. with:
  198. cache-all-crates: "true"
  199. save-if: ${{ github.ref == 'refs/heads/main' }}
  200. - run: cargo clippy --workspace --examples --tests --all-features --all-targets -- -D warnings
  201. # Only run semver checks if the PR is not a draft and does not have the breaking label
  202. # Breaking PRs don't need to follow semver since they are breaking changes
  203. # However, this means we won't attempt to backport them, so you should be careful about using this label, as it will
  204. # likely make future backporting difficult
  205. #
  206. # todo: fix this so even if breaking changes have been merged, the fix can be backported
  207. #
  208. # This will stop working once the first breaking change has been merged, so we should really try to just backport the fix
  209. # and *then* run the semver checks. Basically "would backporting this PR cause a breaking change on stable?"
  210. #
  211. # semver:
  212. # if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'breaking')
  213. # name: Semver Check
  214. # runs-on: ubuntu-latest
  215. # steps:
  216. # - uses: actions/checkout@v4
  217. # - uses: dtolnay/rust-toolchain@stable
  218. # - uses: Swatinem/rust-cache@v2
  219. # with:
  220. # cache-all-crates: "true"
  221. # save-if: ${{ github.ref == 'refs/heads/main' }}
  222. # - name: Check semver
  223. # uses: obi1kenobi/cargo-semver-checks-action@v2
  224. # with:
  225. # manifest-path: ./Cargo.toml
  226. # exclude: "dioxus-cli, dioxus-ext"
  227. playwright:
  228. if: github.event.pull_request.draft == false
  229. name: Playwright Tests
  230. runs-on: ubuntu-latest
  231. steps:
  232. # Do our best to cache the toolchain and node install steps
  233. - uses: actions/checkout@v4
  234. - uses: actions/setup-node@v4
  235. with:
  236. node-version: 16
  237. - name: Free Disk Space (Ubuntu)
  238. uses: jlumbroso/free-disk-space@v1.3.1
  239. with: # speed things up a bit
  240. large-packages: false
  241. docker-images: false
  242. swap-storage: false
  243. - name: Install Rust
  244. uses: dtolnay/rust-toolchain@master
  245. with:
  246. toolchain: stable
  247. targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
  248. - uses: Swatinem/rust-cache@v2
  249. with:
  250. cache-all-crates: "true"
  251. save-if: ${{ github.ref == 'refs/heads/main' }}
  252. - name: Install dependencies
  253. run: npm ci
  254. working-directory: ./packages/playwright-tests
  255. - name: Install Playwright
  256. run: npm install -D @playwright/test
  257. working-directory: ./packages/playwright-tests
  258. - name: Install Playwright Browsers
  259. run: npx playwright install --with-deps
  260. working-directory: ./packages/playwright-tests
  261. - name: Run Playwright tests
  262. run: npx playwright test
  263. working-directory: ./packages/playwright-tests
  264. - uses: actions/upload-artifact@v4
  265. if: always()
  266. with:
  267. name: playwright-report
  268. path: playwright-report/
  269. retention-days: 30
  270. matrix_test:
  271. runs-on: ${{ matrix.platform.os }}
  272. if: github.event.pull_request.draft == false
  273. env:
  274. RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
  275. strategy:
  276. matrix:
  277. platform:
  278. - {
  279. target: x86_64-pc-windows-msvc,
  280. os: windows-latest,
  281. toolchain: "1.79.0",
  282. cross: false,
  283. command: "test",
  284. args: "--all --tests",
  285. }
  286. - {
  287. target: aarch64-apple-darwin,
  288. os: macos-latest,
  289. toolchain: "1.79.0",
  290. cross: false,
  291. command: "test",
  292. args: "--all --tests",
  293. }
  294. - {
  295. target: x86_64-apple-darwin,
  296. os: macos-13,
  297. toolchain: "1.79.0",
  298. cross: false,
  299. command: "test",
  300. args: "--all --tests",
  301. }
  302. - {
  303. target: aarch64-apple-ios,
  304. os: macos-latest,
  305. toolchain: "1.79.0",
  306. cross: false,
  307. command: "build",
  308. args: "--package dioxus-mobile",
  309. }
  310. - {
  311. target: aarch64-linux-android,
  312. os: ubuntu-latest,
  313. toolchain: "1.79.0",
  314. cross: true,
  315. command: "build",
  316. args: "--package dioxus-mobile",
  317. }
  318. steps:
  319. - uses: actions/checkout@v4
  320. - name: Free Disk Space (Ubuntu)
  321. if: ${{ matrix.platform.os == 'ubuntu-latest' }}
  322. uses: jlumbroso/free-disk-space@v1.3.1
  323. with: # speed things up a bit
  324. large-packages: false
  325. docker-images: false
  326. swap-storage: false
  327. - name: install stable
  328. uses: dtolnay/rust-toolchain@master
  329. with:
  330. toolchain: ${{ matrix.platform.toolchain }}
  331. targets: ${{ matrix.platform.target }}
  332. components: rustfmt
  333. - name: Install nasm for windows (tls)
  334. if: ${{ matrix.platform.target == 'x86_64-pc-windows-msvc' }}
  335. uses: ilammy/setup-nasm@v1
  336. - name: Install cross
  337. if: ${{ matrix.platform.cross == true }}
  338. uses: taiki-e/install-action@cross
  339. - uses: Swatinem/rust-cache@v2
  340. with:
  341. key: "${{ matrix.platform.target }}"
  342. cache-all-crates: "true"
  343. save-if: ${{ github.ref == 'refs/heads/main' }}
  344. - name: test
  345. run: |
  346. ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}