steel.yml 13 KB

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