main.yml 5.3 KB

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