main.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.82.0, stable, beta, nightly]
  16. exclude:
  17. - os: macos-latest
  18. rust: 1.82.0
  19. - os: windows-latest
  20. rust: 1.82.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. # cargo update -p getopts --precise 0.2.22
  40. # cargo update -p unicode-width --precise 0.1.12
  41. # cargo update syn@2 --precise 2.0.100
  42. # Unfortunately `syn@2` syntax doesn't work on 1.63, and we don't know the precise
  43. # version beforehand. So we copy the lockfile we have already prepared.
  44. cp ci-lockfiles/1.63.Cargo.lock Cargo.lock
  45. # Older Unicode versions have a different test file
  46. cp idna/tests/IdnaTestV2-Unicode16.txt idna/tests/IdnaTestV2.txt
  47. - name: Downgrade deps on Rust 1.82.0
  48. if: |
  49. matrix.rust == '1.82.0'
  50. run: |
  51. cargo update -p icu_normalizer --precise 2.0.1
  52. cargo update -p icu_provider --precise 2.0.0
  53. cargo update -p icu_locale_core --precise 2.0.1
  54. # Older Unicode versions have a different test file
  55. cp idna/tests/IdnaTestV2-Unicode16.txt idna/tests/IdnaTestV2.txt
  56. - name: Add `aarch64-unknown-none` toolchain for `no_std` tests
  57. if: |
  58. matrix.os == 'ubuntu-latest' &&
  59. matrix.rust == 'nightly'
  60. run: rustup target add aarch64-unknown-none && rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
  61. - run: cargo build --all-targets
  62. # Run tests
  63. - name: Run tests
  64. run: cargo test
  65. # Run tests enabling the serde feature
  66. - name: Run tests with the serde feature
  67. run: cargo test --features "url/serde,url/expose_internals"
  68. # The #[debugger_visualizer] attribute is currently gated behind a feature flag until #[debugger_visualizer]
  69. # is available in all rustc versions past our MSRV. As such, we only run the tests on newer rustc versions.
  70. - name: Run debugger_visualizer tests
  71. if: |
  72. matrix.os == 'windows-latest' &&
  73. matrix.rust != '1.63.0' &&
  74. matrix.rust != '1.82.0'
  75. run: cargo test --test debugger_visualizer --features "url/debugger_visualizer,url_debug_tests/debugger_visualizer" -- --test-threads=1 || echo "debugger test failed"
  76. continue-on-error: true # Fails on GH actions, but not locally.
  77. - name: Test `no_std` support
  78. run: cargo test --no-default-features --features=alloc
  79. - name: Build `url` crate for `aarch64-unknown-none` with `no_std`
  80. if: |
  81. matrix.os == 'ubuntu-latest' &&
  82. matrix.rust == 'nightly'
  83. run: >
  84. cd url
  85. && cargo check --target aarch64-unknown-none -v --no-default-features
  86. - name: Run tests with sanitizers
  87. if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') && matrix.rust == 'nightly'
  88. env:
  89. ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1
  90. run: |
  91. if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
  92. sudo apt-get install -y --no-install-recommends llvm
  93. TARGET="x86_64-unknown-linux-gnu"
  94. SANITIZERS="address thread leak memory"
  95. elif [ "${{ matrix.os }}" = "macos-latest" ]; then
  96. TARGET="aarch64-apple-darwin"
  97. # no memory and leak sanitizer support yet
  98. SANITIZERS="address thread"
  99. # Suppress non-crate leaks on macOS. TODO: Check occasionally if these are still needed.
  100. {
  101. echo "leak:dyld4::RuntimeState"
  102. echo "leak:fetchInitializingClassList"
  103. echo "leak:std::sys::pal::unix::stack_overflow::imp::init"
  104. echo "leak:dyld::ThreadLocalVariables::instantiateVariable"
  105. echo "leak:_tlv_get_addr"
  106. } > suppressions.txt
  107. export LSAN_OPTIONS="suppressions=$(pwd)/suppressions.txt"
  108. fi
  109. for sanitizer in $SANITIZERS; do
  110. echo "Running tests with $sanitizer sanitizer..."
  111. export RUSTFLAGS="-Z sanitizer=$sanitizer"
  112. export RUSTDOCFLAGS="$RUSTFLAGS"
  113. cargo +nightly test -Z build-std --target "$TARGET" --lib --tests
  114. done
  115. WASM:
  116. runs-on: ubuntu-latest
  117. steps:
  118. - uses: actions/checkout@v4
  119. - uses: dtolnay/rust-toolchain@stable
  120. with:
  121. targets: wasm32-unknown-unknown
  122. - name: Install wasm-pack
  123. run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
  124. - run: cargo build --target wasm32-unknown-unknown
  125. - run: cd url && wasm-pack test --headless --chrome
  126. - run: cd url && wasm-pack test --headless --firefox
  127. Lint:
  128. runs-on: ubuntu-latest
  129. steps:
  130. - uses: actions/checkout@v4
  131. - uses: dtolnay/rust-toolchain@stable
  132. with:
  133. components: rustfmt, clippy
  134. - run: cargo fmt --all --check
  135. - run: cargo clippy --workspace --all-targets -- -D warnings
  136. if: always()
  137. Audit:
  138. runs-on: ubuntu-latest
  139. steps:
  140. - uses: actions/checkout@v4
  141. - uses: EmbarkStudios/cargo-deny-action@v2
  142. Result:
  143. name: Result
  144. runs-on: ubuntu-latest
  145. needs:
  146. - "Test"
  147. - "WASM"
  148. - "Lint"
  149. - "Audit"
  150. steps:
  151. - name: Mark the job as successful
  152. run: exit 0
  153. if: success()
  154. - name: Mark the job as unsuccessful
  155. run: exit 1
  156. if: "!success()"