steel.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. name: Steel
  2. on:
  3. schedule:
  4. - cron: "0 0 * * *"
  5. push:
  6. branches:
  7. - main
  8. pull_request:
  9. types: [opened, synchronize, reopened]
  10. branches:
  11. - main
  12. env:
  13. MAX_JOBS: 64
  14. MIN_PROJECTS_PER_JOB: 4
  15. MIN_PROJECTS_FOR_MATRIX: 4
  16. jobs:
  17. changes:
  18. runs-on: ubuntu-latest
  19. permissions:
  20. pull-requests: read
  21. outputs:
  22. changed_projects: ${{ steps.analyze.outputs.changed_projects }}
  23. total_projects: ${{ steps.analyze.outputs.total_projects }}
  24. matrix: ${{ steps.matrix.outputs.matrix }}
  25. steps:
  26. - uses: actions/checkout@v4
  27. - uses: dorny/paths-filter@v3
  28. id: changes
  29. if: github.event_name == 'pull_request'
  30. with:
  31. list-files: shell
  32. filters: |
  33. steel:
  34. - added|modified: '**/steel/**'
  35. workflow:
  36. - added|modified: '.github/workflows/steel.yml'
  37. - name: Analyze Changes
  38. id: analyze
  39. run: |
  40. # Generate ignore pattern, excluding comments
  41. ignore_pattern=$(grep -v '^#' .github/.ghaignore | grep -v '^$' | tr '\n' '|' | sed 's/|$//')
  42. echo "Ignore pattern: $ignore_pattern"
  43. function get_projects() {
  44. find . -type d -name "steel" | grep -vE "$ignore_pattern" | sort
  45. }
  46. # Determine which projects to build and test
  47. if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
  48. projects=$(get_projects)
  49. elif [[ "${{ steps.changes.outputs.steel }}" == "true" ]]; then
  50. changed_files=(${{ steps.changes.outputs.steel_files }})
  51. projects=$(for file in "${changed_files[@]}"; do dirname "${file}" | grep steel | sed 's#/steel/.*#/steel#g'; done | grep -vE "$ignore_pattern" | sort -u)
  52. else
  53. projects=""
  54. fi
  55. # Output project information
  56. if [[ -n "$projects" ]]; then
  57. echo "Projects to build and test"
  58. echo "$projects"
  59. total_projects=$(echo "$projects" | wc -l)
  60. echo "Total projects: $total_projects"
  61. echo "total_projects=$total_projects" >> $GITHUB_OUTPUT
  62. echo "changed_projects=$(echo "$projects" | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
  63. else
  64. echo "No projects to build and test."
  65. echo "total_projects=0" >> $GITHUB_OUTPUT
  66. echo "changed_projects=[]" >> $GITHUB_OUTPUT
  67. fi
  68. - name: Generate matrix
  69. id: matrix
  70. run: |
  71. total_projects=${{ steps.analyze.outputs.total_projects }}
  72. max_jobs=${{ env.MAX_JOBS }}
  73. min_projects_per_job=${{ env.MIN_PROJECTS_PER_JOB }}
  74. min_projects_for_matrix=${{ env.MIN_PROJECTS_FOR_MATRIX }}
  75. if [ "$total_projects" -lt "$min_projects_for_matrix" ]; then
  76. echo "matrix=[0]" >> $GITHUB_OUTPUT
  77. else
  78. projects_per_job=$(( (total_projects + max_jobs - 1) / max_jobs ))
  79. projects_per_job=$(( projects_per_job > min_projects_per_job ? projects_per_job : min_projects_per_job ))
  80. num_jobs=$(( (total_projects + projects_per_job - 1) / projects_per_job ))
  81. indices=$(seq 0 $(( num_jobs - 1 )))
  82. echo "matrix=[$(echo $indices | tr ' ' ',')]" >> $GITHUB_OUTPUT
  83. fi
  84. fmt:
  85. needs: changes
  86. if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.total_projects != '0' }}
  87. name: Rustfmt
  88. runs-on: ubuntu-latest
  89. steps:
  90. - uses: actions/checkout@v4
  91. - uses: dtolnay/rust-toolchain@stable
  92. with:
  93. components: rustfmt
  94. - uses: mozilla-actions/sccache-action@v0.0.4
  95. - name: Run fmt
  96. run: |
  97. readarray -t projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]')
  98. for project in "${projects[@]}"; do
  99. if [ -f "$project/Cargo.toml" ]; then
  100. cd "$project"
  101. cargo fmt --check
  102. cd - > /dev/null
  103. fi
  104. done
  105. clippy:
  106. needs: changes
  107. if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.total_projects != '0' }}
  108. name: Clippy
  109. runs-on: ubuntu-latest
  110. steps:
  111. - uses: actions/checkout@v4
  112. - uses: dtolnay/rust-toolchain@stable
  113. with:
  114. components: clippy
  115. - uses: mozilla-actions/sccache-action@v0.0.4
  116. - name: Run clippy
  117. run: |
  118. readarray -t projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]')
  119. for project in "${projects[@]}"; do
  120. if [ -f "$project/Cargo.toml" ]; then
  121. cd "$project"
  122. cargo clippy -- -D warnings
  123. cd - > /dev/null
  124. fi
  125. done
  126. build-and-test:
  127. needs: changes
  128. if: needs.changes.outputs.total_projects != '0'
  129. runs-on: ubuntu-latest
  130. strategy:
  131. fail-fast: false
  132. matrix:
  133. index: ${{ fromJson(needs.changes.outputs.matrix) }}
  134. name: build-and-test-group-${{ matrix.index }}
  135. outputs:
  136. failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
  137. steps:
  138. - uses: actions/checkout@v4
  139. - name: Use Node.js
  140. uses: actions/setup-node@v4
  141. with:
  142. node-version: 20.x
  143. check-latest: true
  144. - name: Setup build environment
  145. id: setup
  146. run: |
  147. # Create the build and test function
  148. cat << 'EOF' > build_and_test.sh
  149. function build_and_test() {
  150. local project=$1
  151. local solana_version=$2
  152. echo "Building and Testing $project with Solana $solana_version"
  153. cd "$project" || return 1
  154. # Install dependencies
  155. if [ -f "package.json" ]; then
  156. if ! pnpm install --frozen-lockfile; then
  157. echo "::error::pnpm install failed for $project"
  158. echo "$project: pnpm install failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  159. cd - > /dev/null
  160. return 1
  161. fi
  162. # Build
  163. if ! pnpm build; then
  164. echo "::error::build failed for $project"
  165. echo "$project: build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  166. cd - > /dev/null
  167. return 1
  168. fi
  169. # Test
  170. if ! pnpm build-and-test; then
  171. echo "::error::tests failed for $project"
  172. echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  173. cd - > /dev/null
  174. return 1
  175. fi
  176. else
  177. # Use Steel CLI
  178. if ! cargo install steel-cli; then
  179. echo "::error::steel-cli installation failed for $project"
  180. echo "$project: steel-cli installation failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  181. cd - > /dev/null
  182. return 1
  183. fi
  184. # Build
  185. if ! steel build; then
  186. echo "::error::steel build failed for $project"
  187. echo "$project: steel build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  188. cd - > /dev/null
  189. return 1
  190. fi
  191. # Test
  192. if ! steel test; then
  193. echo "::error::steel test failed for $project"
  194. echo "$project: steel test failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  195. cd - > /dev/null
  196. return 1
  197. fi
  198. fi
  199. echo "Build and tests succeeded for $project with $solana_version version."
  200. cd - > /dev/null
  201. return 0
  202. }
  203. function process_projects() {
  204. local solana_version=$1
  205. readarray -t all_projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]?')
  206. start_index=$(( ${{ matrix.index }} * ${{ env.MIN_PROJECTS_PER_JOB }} ))
  207. end_index=$(( start_index + ${{ env.MIN_PROJECTS_PER_JOB }} ))
  208. end_index=$(( end_index > ${{ needs.changes.outputs.total_projects }} ? ${{ needs.changes.outputs.total_projects }} : end_index ))
  209. echo "Projects to build and test in this job"
  210. for i in $(seq $start_index $(( end_index - 1 ))); do
  211. echo "${all_projects[$i]}"
  212. done
  213. failed=false
  214. for i in $(seq $start_index $(( end_index - 1 ))); do
  215. echo "::group::Building and testing ${all_projects[$i]}"
  216. if ! build_and_test "${all_projects[$i]}" "$solana_version"; then
  217. failed=true
  218. fi
  219. echo "::endgroup::"
  220. done
  221. return $([ "$failed" = true ] && echo 1 || echo 0)
  222. }
  223. EOF
  224. # Make the script executable
  225. chmod +x build_and_test.sh
  226. # Install pnpm
  227. npm install --global pnpm
  228. - name: Setup Solana stable
  229. uses: heyAyushh/setup-solana@v5.4
  230. with:
  231. solana-cli-version: stable
  232. - name: Build and Test with Stable
  233. env:
  234. SCCACHE_GHA_ENABLED: "true"
  235. RUSTC_WRAPPER: "sccache"
  236. run: |
  237. source build_and_test.sh
  238. solana -V
  239. rustc -V
  240. process_projects "stable"
  241. sccache --show-stats
  242. - name: Setup Solana 1.18.17
  243. uses: heyAyushh/setup-solana@v5.4
  244. with:
  245. solana-cli-version: 1.18.17
  246. - name: Build and Test with 1.18.17
  247. env:
  248. SCCACHE_GHA_ENABLED: "true"
  249. RUSTC_WRAPPER: "sccache"
  250. run: |
  251. source build_and_test.sh
  252. solana -V
  253. rustc -V
  254. process_projects "1.18.17"
  255. sccache --show-stats
  256. - name: Set failed projects output
  257. id: set-failed
  258. if: failure()
  259. run: |
  260. if [ -f "$GITHUB_WORKSPACE/failed_projects.txt" ]; then
  261. failed_projects=$(cat $GITHUB_WORKSPACE/failed_projects.txt | jq -R -s -c 'split("\n")[:-1]')
  262. echo "failed_projects=$failed_projects" >> $GITHUB_OUTPUT
  263. else
  264. echo "failed_projects=[]" >> $GITHUB_OUTPUT
  265. fi
  266. summary:
  267. needs: [changes, build-and-test]
  268. if: always()
  269. runs-on: ubuntu-latest
  270. steps:
  271. - uses: actions/checkout@v4
  272. - name: Create job summary
  273. run: |
  274. echo "## Steel Workflow Summary" >> $GITHUB_STEP_SUMMARY
  275. echo "- Total projects: ${{ needs.changes.outputs.total_projects }}" >> $GITHUB_STEP_SUMMARY
  276. # List all processed projects
  277. echo "<details>" >> $GITHUB_STEP_SUMMARY
  278. echo "<summary>Projects processed (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY
  279. echo "" >> $GITHUB_STEP_SUMMARY
  280. echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]' | while read project; do
  281. echo "- $project" >> $GITHUB_STEP_SUMMARY
  282. done
  283. echo "" >> $GITHUB_STEP_SUMMARY
  284. echo "</details>" >> $GITHUB_STEP_SUMMARY
  285. # Report build and test results
  286. if [[ "${{ needs.build-and-test.result }}" == "failure" ]]; then
  287. echo "## :x: Build or tests failed" >> $GITHUB_STEP_SUMMARY
  288. echo "<details>" >> $GITHUB_STEP_SUMMARY
  289. echo "<summary>Failed projects (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY
  290. echo "" >> $GITHUB_STEP_SUMMARY
  291. failed_projects='${{ needs.build-and-test.outputs.failed_projects }}'
  292. if [[ -n "$failed_projects" ]]; then
  293. echo "$failed_projects" | jq -r '.[]' | while IFS=: read -r project failure_reason; do
  294. echo "- **$project**" >> $GITHUB_STEP_SUMMARY
  295. echo " - Failure reason: $failure_reason" >> $GITHUB_STEP_SUMMARY
  296. done
  297. else
  298. echo "No failed projects reported. This might indicate an unexpected error in the workflow." >> $GITHUB_STEP_SUMMARY
  299. fi
  300. echo "" >> $GITHUB_STEP_SUMMARY
  301. echo "</details>" >> $GITHUB_STEP_SUMMARY
  302. elif [[ "${{ needs.build-and-test.result }}" == "success" ]]; then
  303. echo "## :white_check_mark: All builds and tests passed" >> $GITHUB_STEP_SUMMARY
  304. else
  305. echo "## :warning: Build and test job was skipped or canceled" >> $GITHUB_STEP_SUMMARY
  306. fi