main.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. name: CI
  2. on:
  3. push:
  4. branches: ["main"]
  5. pull_request:
  6. merge_group:
  7. types: [checks_requested]
  8. env:
  9. CARGO_NET_GIT_FETCH_WITH_CLI: true
  10. jobs:
  11. Test:
  12. strategy:
  13. matrix:
  14. os: [ubuntu-latest, macos-latest, windows-latest]
  15. rust: [1.63.0, 1.67.0, stable, beta, nightly]
  16. exclude:
  17. - os: macos-latest
  18. rust: 1.67.0
  19. - os: windows-latest
  20. rust: 1.67.0
  21. - os: macos-latest
  22. rust: beta
  23. - os: windows-latest
  24. rust: beta
  25. runs-on: ${{ matrix.os }}
  26. steps:
  27. - uses: actions/checkout@v4
  28. - uses: dtolnay/rust-toolchain@master
  29. with:
  30. toolchain: ${{ matrix.rust }}
  31. components: ${{ matrix.rust == 'nightly' && 'rust-src' || '' }}
  32. # Add toolchain for no_std tests
  33. - run: rustup toolchain install nightly
  34. - name: Downgrade deps on Rust 1.63.0
  35. if: |
  36. matrix.rust == '1.63.0'
  37. run: |
  38. cargo update -p idna_adapter --precise 1.1.0
  39. - name: Downgrade deps on Rust 1.67.0
  40. if: |
  41. matrix.rust == '1.67.0'
  42. run: |
  43. cargo update -p zerofrom --precise 0.1.4
  44. cargo update -p yoke --precise 0.7.4
  45. cargo update -p litemap --precise 0.7.3
  46. - name: Add `aarch64-unknown-none` toolchain for `no_std` tests
  47. if: |
  48. matrix.os == 'ubuntu-latest' &&
  49. matrix.rust == 'nightly'
  50. run: rustup target add aarch64-unknown-none && rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
  51. - run: cargo build --all-targets
  52. # Run tests
  53. - name: Run tests
  54. run: cargo test
  55. # Run tests enabling the serde feature
  56. - name: Run tests with the serde feature
  57. run: cargo test --features "url/serde,url/expose_internals"
  58. # The #[debugger_visualizer] attribute is currently gated behind a feature flag until #[debugger_visualizer]
  59. # is available in all rustc versions past our MSRV. As such, we only run the tests on newer rustc versions.
  60. - name: Run debugger_visualizer tests
  61. if: |
  62. matrix.os == 'windows-latest' &&
  63. matrix.rust != '1.63.0' &&
  64. matrix.rust != '1.67.0'
  65. run: cargo test --test debugger_visualizer --features "url/debugger_visualizer,url_debug_tests/debugger_visualizer" -- --test-threads=1 || echo "debugger test failed"
  66. continue-on-error: true # Fails on GH actions, but not locally.
  67. - name: Test `no_std` support
  68. run: cargo test --no-default-features --features=alloc
  69. - name: Build `url` crate for `aarch64-unknown-none` with `no_std`
  70. if: |
  71. matrix.os == 'ubuntu-latest' &&
  72. matrix.rust == 'nightly'
  73. run: >
  74. cd url
  75. && cargo check --target aarch64-unknown-none -v --no-default-features
  76. - name: Run tests with sanitizers
  77. if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') && matrix.rust == 'nightly'
  78. env:
  79. ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1
  80. run: |
  81. if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
  82. sudo apt-get install -y --no-install-recommends llvm
  83. TARGET="x86_64-unknown-linux-gnu"
  84. SANITIZERS="address thread leak memory"
  85. elif [ "${{ matrix.os }}" = "macos-latest" ]; then
  86. TARGET="aarch64-apple-darwin"
  87. # no memory and leak sanitizer support yet
  88. SANITIZERS="address thread"
  89. # Suppress non-crate leaks on macOS. TODO: Check occasionally if these are still needed.
  90. {
  91. echo "leak:dyld4::RuntimeState"
  92. echo "leak:fetchInitializingClassList"
  93. echo "leak:std::sys::pal::unix::stack_overflow::imp::init"
  94. } > suppressions.txt
  95. export LSAN_OPTIONS="suppressions=$(pwd)/suppressions.txt"
  96. fi
  97. for sanitizer in $SANITIZERS; do
  98. echo "Running tests with $sanitizer sanitizer..."
  99. export RUSTFLAGS="-Z sanitizer=$sanitizer"
  100. export RUSTDOCFLAGS="$RUSTFLAGS"
  101. cargo +nightly test -Z build-std --target "$TARGET"
  102. done
  103. WASM:
  104. runs-on: ubuntu-latest
  105. steps:
  106. - uses: actions/checkout@v4
  107. - uses: dtolnay/rust-toolchain@stable
  108. with:
  109. targets: wasm32-unknown-unknown
  110. - name: Install wasm-pack
  111. run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
  112. - run: cargo build --target wasm32-unknown-unknown
  113. - run: cd url && wasm-pack test --headless --chrome
  114. - run: cd url && wasm-pack test --headless --firefox
  115. Lint:
  116. runs-on: ubuntu-latest
  117. steps:
  118. - uses: actions/checkout@v4
  119. - uses: dtolnay/rust-toolchain@stable
  120. with:
  121. components: rustfmt, clippy
  122. - run: cargo fmt --all --check
  123. - run: cargo clippy --workspace --all-targets -- -D warnings
  124. if: always()
  125. Audit:
  126. runs-on: ubuntu-latest
  127. steps:
  128. - uses: actions/checkout@v4
  129. - uses: EmbarkStudios/cargo-deny-action@v1
  130. Result:
  131. name: Result
  132. runs-on: ubuntu-latest
  133. needs:
  134. - "Test"
  135. - "WASM"
  136. - "Lint"
  137. - "Audit"
  138. steps:
  139. - name: Mark the job as successful
  140. run: exit 0
  141. if: success()
  142. - name: Mark the job as unsuccessful
  143. run: exit 1
  144. if: "!success()"