_build-rust.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Reusable GitHub CI workflow:
  2. # More info: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses
  3. # Common Rust CI setup that checkout the repo, installs the common toolchain
  4. # and set's up the cargo cache. It builds, tests, and lints the code.
  5. on:
  6. workflow_call:
  7. inputs:
  8. rust-version:
  9. type: string
  10. required: false
  11. default: stable
  12. description: Rust version
  13. rust-target:
  14. type: string
  15. required: false
  16. default: x86_64-unknown-linux-gnu
  17. description: Rust target for the build step. Clippy and tests are still executed with the default target.
  18. do-style-check:
  19. type: boolean
  20. required: false
  21. default: true
  22. description: Whether style checks should be done.
  23. do-test:
  24. type: boolean
  25. required: false
  26. default: true
  27. description: Whether tests should be executed.
  28. jobs:
  29. build:
  30. runs-on: ubuntu-latest
  31. steps:
  32. - name: Check out
  33. uses: actions/checkout@v3
  34. - name: Install Rust
  35. uses: actions-rs/toolchain@v1
  36. with:
  37. profile: minimal
  38. toolchain: ${{ inputs.rust-version }}
  39. override: true
  40. components: clippy, rustfmt
  41. target: ${{ inputs.rust-target }}
  42. - name: Set up cargo cache
  43. uses: actions/cache@v3
  44. continue-on-error: false
  45. with:
  46. path: |
  47. ~/.cargo/bin/
  48. ~/.cargo/registry/index/
  49. ~/.cargo/registry/cache/
  50. ~/.cargo/git/db/
  51. target/
  52. key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
  53. restore-keys: ${{ runner.os }}-cargo-
  54. - run: cargo version
  55. - name: Code Formatting
  56. if: ${{ inputs.do-style-check }}
  57. run: cargo fmt --all -- --check
  58. - name: Build (library)
  59. run: cargo build --target ${{ inputs.rust-target }}
  60. - name: Build (all targets)
  61. run: cargo build --all-targets
  62. - name: Code Style and Doc Style
  63. if: ${{ inputs.do-style-check }}
  64. run: |
  65. cargo doc --document-private-items
  66. cargo clippy --all-targets
  67. - name: Unit Test
  68. if: ${{ inputs.do-test }}
  69. run: |
  70. curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
  71. chmod u+x cargo-nextest
  72. ./cargo-nextest nextest run