_build-rust.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. # We do not have a Cargo.lock here, so I hash Cargo.toml
  53. key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml') }}
  54. restore-keys: ${{ runner.os }}-cargo-${{ inputs.rust-version }}
  55. - run: cargo version
  56. - name: Code Formatting
  57. if: ${{ inputs.do-style-check }}
  58. run: cargo fmt --all -- --check
  59. - name: Build (library)
  60. run: cargo build --target ${{ inputs.rust-target }}
  61. - name: Build (all targets)
  62. run: cargo build --all-targets
  63. - name: Code Style and Doc Style
  64. if: ${{ inputs.do-style-check }}
  65. run: |
  66. cargo doc --document-private-items
  67. cargo clippy --all-targets
  68. - name: Unit Test
  69. if: ${{ inputs.do-test }}
  70. run: |
  71. curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
  72. chmod u+x cargo-nextest
  73. ./cargo-nextest nextest run