_build-rust.yml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. features:
  19. type: string
  20. required: false
  21. # Make sure we always an empty string to "--features <FEATURES>"
  22. default: '""'
  23. description: Comma-separated String with additional Rust features relevant for a certain job.
  24. do-style-check:
  25. type: boolean
  26. required: false
  27. default: true
  28. description: Perform code and doc style checks.
  29. do-test:
  30. type: boolean
  31. required: false
  32. default: true
  33. description: Execute tests.
  34. jobs:
  35. check_rust:
  36. runs-on: ubuntu-latest
  37. steps:
  38. - name: Check out
  39. uses: actions/checkout@v3
  40. - name: Install Rust toolchain
  41. uses: actions-rs/toolchain@v1
  42. with:
  43. profile: minimal
  44. toolchain: ${{ inputs.rust-version }}
  45. override: true
  46. components: clippy, rustfmt
  47. target: ${{ inputs.rust-target }}
  48. - name: Set up cargo cache
  49. uses: actions/cache@v3
  50. continue-on-error: false
  51. with:
  52. path: |
  53. ~/.cargo/bin/
  54. ~/.cargo/registry/index/
  55. ~/.cargo/registry/cache/
  56. ~/.cargo/git/db/
  57. target/
  58. # We do not have a Cargo.lock here, so I hash Cargo.toml
  59. key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml') }}
  60. restore-keys: ${{ runner.os }}-cargo-${{ inputs.rust-version }}
  61. - run: cargo version
  62. - name: Build (library)
  63. run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }}
  64. - name: Build (all targets)
  65. run: cargo build --all-targets --features ${{ inputs.features }}
  66. - name: Code Formatting
  67. if: ${{ inputs.do-style-check }}
  68. run: cargo fmt --all -- --check
  69. - name: Code Style and Doc Style
  70. if: ${{ inputs.do-style-check }}
  71. run: |
  72. cargo doc --document-private-items --features ${{ inputs.features }}
  73. cargo clippy --all-targets --features ${{ inputs.features }}
  74. - name: Unit Test
  75. if: ${{ inputs.do-test }}
  76. run: |
  77. curl -LsSf https://get.nexte.st/latest/linux | tar zxf -
  78. chmod u+x cargo-nextest
  79. ./cargo-nextest nextest run --features ${{ inputs.features }}