ci.yml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. name: CI
  2. on:
  3. push:
  4. branches: [ "main" ]
  5. pull_request:
  6. branches: [ "main" ]
  7. workflow_dispatch:
  8. env:
  9. CARGO_UNSTABLE_SPARSE_REGISTRY: true
  10. CARGO_TERM_COLOR: always
  11. jobs:
  12. fmt:
  13. name: Rustfmt all packages
  14. runs-on: ubuntu-latest
  15. steps:
  16. - uses: actions/checkout@v4
  17. - uses: actions-rust-lang/setup-rust-toolchain@v1
  18. with:
  19. components: rustfmt
  20. - name: Cache Dependencies
  21. uses: Swatinem/rust-cache@v2
  22. - name: Rustfmt Check
  23. uses: actions-rust-lang/rustfmt@v1
  24. build-rustsbi:
  25. name: Build rustsbi
  26. runs-on: ubuntu-latest
  27. needs: fmt
  28. strategy:
  29. matrix:
  30. TARGET: [riscv64imac-unknown-none-elf, riscv32imac-unknown-none-elf]
  31. TOOLCHAIN: [stable, nightly]
  32. steps:
  33. - uses: actions/checkout@v4
  34. - uses: actions-rust-lang/setup-rust-toolchain@v1
  35. with:
  36. target: ${{ matrix.TARGET }}
  37. toolchain: ${{ matrix.TOOLCHAIN }}
  38. - uses: Swatinem/rust-cache@v2
  39. with:
  40. key: ${{ matrix.TARGET }}
  41. - name: Build (no default features)
  42. run: |
  43. cargo build --target ${{ matrix.TARGET }} --verbose
  44. - name: Build (machine)
  45. run: |
  46. cargo build --target ${{ matrix.TARGET }} --verbose --features "machine"
  47. - name: Build (forward)
  48. run: |
  49. cargo build --target ${{ matrix.TARGET }} --verbose --features "forward"
  50. - name: Build (machine + forward)
  51. run: |
  52. cargo build --target ${{ matrix.TARGET }} --verbose --features "machine, forward"
  53. test-rustsbi:
  54. name: Test rustsbi
  55. needs: fmt
  56. runs-on: ubuntu-latest
  57. steps:
  58. - uses: actions/checkout@v4
  59. - uses: actions-rust-lang/setup-rust-toolchain@v1
  60. with:
  61. toolchain: stable
  62. - uses: Swatinem/rust-cache@v2
  63. - name: Run tests (no default features)
  64. run: |
  65. cargo test -p rustsbi --verbose
  66. - name: Run tests (machine)
  67. run: |
  68. cargo test -p rustsbi --verbose --features "machine"
  69. # Don't run tests with rustsbi `forward` features on here: it requires RISC-V targets to build.
  70. test-sbi-spec:
  71. name: Test sbi-spec
  72. needs: fmt
  73. runs-on: ubuntu-latest
  74. steps:
  75. - uses: actions/checkout@v4
  76. - uses: actions-rust-lang/setup-rust-toolchain@v1
  77. with:
  78. toolchain: stable
  79. - uses: Swatinem/rust-cache@v2
  80. # - name: Check clippy
  81. # run: cargo clippy -- -D warnings
  82. - name: Run tests
  83. run: cargo test -p sbi-spec --verbose
  84. build-sbi-rt:
  85. name: Build sbi-rt
  86. needs: fmt
  87. runs-on: ubuntu-latest
  88. strategy:
  89. matrix:
  90. TARGET: [riscv64imac-unknown-none-elf, riscv32imac-unknown-none-elf]
  91. steps:
  92. - uses: actions/checkout@v4
  93. - uses: actions-rust-lang/setup-rust-toolchain@v1
  94. with:
  95. target: ${{ matrix.TARGET }}
  96. toolchain: stable
  97. - uses: Swatinem/rust-cache@v2
  98. - name: Build
  99. run: |
  100. cargo build --target ${{ matrix.TARGET }} --verbose -p sbi-rt
  101. build-sbi-testing:
  102. name: Build sbi-testing
  103. needs: fmt
  104. runs-on: ubuntu-latest
  105. strategy:
  106. matrix:
  107. TARGET: [riscv64imac-unknown-none-elf] #, riscv32imac-unknown-none-elf]
  108. steps:
  109. - uses: actions/checkout@v4
  110. - uses: actions-rust-lang/setup-rust-toolchain@v1
  111. with:
  112. target: ${{ matrix.TARGET }}
  113. toolchain: nightly
  114. - uses: Swatinem/rust-cache@v2
  115. - name: Build (no default features)
  116. run: |
  117. cargo build --target ${{ matrix.TARGET }} --verbose -p sbi-testing
  118. - name: Build (log)
  119. run: |
  120. cargo build --target ${{ matrix.TARGET }} --verbose -p sbi-testing --features "log"
  121. check-changelog:
  122. name: Check if `CHANGELOG.md` is updated
  123. runs-on: ubuntu-latest
  124. steps:
  125. - uses: actions/checkout@v4
  126. - name: Get latest updated files
  127. run: |
  128. updated_files=$(git show --name-only --pretty=format: HEAD)
  129. - name: Check if changlog is updated
  130. run: |
  131. if git show --name-only --pretty=format: HEAD | grep -q "CHANGELOG.md"; then
  132. echo "Main CHANGELOG.md changed in the latest commit."
  133. else
  134. echo "Main CHANGELOG.md is not changed in the latest commit."
  135. exit 1
  136. fi
  137. for file in $updated_files; do
  138. first_path=$(dirname "$file")
  139. if [[ "$first_path" == *"sbi-rt"* ]]; then
  140. file_path = "./sbi-rt"
  141. elif [[ "$first_path" == *"sbi-spec"* ]]; then
  142. file_path = "./sbi-spec"
  143. elif [[ "$first_path" == *"sbi-testing"* ]]; then
  144. file_path = "./sbi-testing"
  145. else
  146. file_path = "./"
  147. fi
  148. changelog_path="$file_path/CHANGELOG.md"
  149. # Check if changelog is updated
  150. if git diff --name-only "$file_path" | grep -q "CHANGELOG.md"; then
  151. echo "File $changelog_path changed in the latest commit."
  152. else
  153. echo "File $changelog_path is not changed in the latest commit."
  154. exit 1
  155. fi
  156. done
  157. check-commit-signatures:
  158. name: Check commit signatures
  159. runs-on: ubuntu-latest
  160. steps:
  161. - uses: actions/checkout@v4
  162. - name: Check if commit is signed
  163. run: |
  164. COMMIT=$(git log -1)
  165. if echo "$COMMIT" | grep -q "Author: "; then
  166. echo "Commit is signed."
  167. else
  168. echo "Commit is NOT signed."
  169. exit 1
  170. fi
  171. - name: Print author's information
  172. run: |
  173. AUTHOR_NAME=$(git log -1 --format='%an')
  174. AUTHOR_EMAIL=$(git log -1 --format='%ae')
  175. echo "Author's name: $AUTHOR_NAME"
  176. echo "Author's email: $AUTHOR_EMAIL"
  177. # sbi-testing:
  178. # name: Run rust-clippy analyzing
  179. # runs-on: ubuntu-latest
  180. # permissions:
  181. # security-events: write
  182. # steps:
  183. # - name: Checkout code
  184. # uses: actions/checkout@v4
  185. # - name: Check format
  186. # run: cargo fmt --check
  187. # - name: Install clippy-sarif
  188. # uses: actions-rs/install@v0.1
  189. # with:
  190. # crate: clippy-sarif
  191. # version: latest
  192. # - name: Install sarif-fmt
  193. # uses: actions-rs/install@v0.1
  194. # with:
  195. # crate: sarif-fmt
  196. # version: latest
  197. # - name: Run rust-clippy
  198. # run:
  199. # cargo clippy
  200. # --all-featuers
  201. # --package fast-trap
  202. # --message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
  203. # continue-on-error: true
  204. # - name: Upload analysis results to GitHub
  205. # uses: github/codeql-action/upload-sarif@v2
  206. # with:
  207. # sarif_file: rust-clippy-results.sarif
  208. # wait-for-processing: true