main.yml 5.1 KB

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