steel.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. rust-checks:
  85. needs: changes
  86. if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.total_projects != '0' }}
  87. name: Rust Checks
  88. runs-on: ubuntu-latest
  89. steps:
  90. - uses: actions/checkout@v4
  91. - uses: dtolnay/rust-toolchain@stable
  92. with:
  93. components: rustfmt, clippy
  94. - name: Run fmt and clippy
  95. run: |
  96. readarray -t all_projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]?')
  97. for project in "${all_projects[@]}"; do
  98. echo "::group::Checking ${project}"
  99. if [ ! -f "${project}/Cargo.toml" ]; then
  100. echo "::error::No Cargo.toml found in ${project}"
  101. exit 1
  102. fi
  103. cd "${project}"
  104. cargo fmt --check
  105. cargo clippy --all-features -- -D warnings
  106. cd - > /dev/null
  107. echo "::endgroup::"
  108. done
  109. build-and-test:
  110. needs: changes
  111. if: needs.changes.outputs.total_projects != '0'
  112. runs-on: ubuntu-latest
  113. strategy:
  114. fail-fast: false
  115. matrix:
  116. index: ${{ fromJson(needs.changes.outputs.matrix) }}
  117. name: build-and-test-group-${{ matrix.index }}
  118. outputs:
  119. failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
  120. steps:
  121. - uses: actions/checkout@v4
  122. - uses: dtolnay/rust-toolchain@stable
  123. - uses: actions/cache@v4
  124. with:
  125. path: ~/.cargo/bin/steel
  126. key: ${{ runner.os }}-steel-cli
  127. - name: Use Node.js
  128. uses: actions/setup-node@v4
  129. with:
  130. node-version: 'lts/*'
  131. check-latest: true
  132. - name: Setup build environment
  133. id: setup
  134. run: |
  135. npm install --global pnpm
  136. # Create the build and test function
  137. cat << 'EOF' > build_and_test.sh
  138. function build_and_test() {
  139. local project=$1
  140. local solana_version=$2
  141. echo "Building and Testing $project with Solana $solana_version"
  142. cd "$project" || return 1
  143. # Install dependencies
  144. if [ -f "package.json" ]; then
  145. if ! pnpm install --frozen-lockfile; then
  146. echo "::error::pnpm install failed for $project"
  147. echo "$project: pnpm install failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  148. cd - > /dev/null
  149. return 1
  150. fi
  151. # Build
  152. if ! pnpm build; then
  153. echo "::error::build failed for $project"
  154. echo "$project: build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  155. cd - > /dev/null
  156. return 1
  157. fi
  158. # Test
  159. if ! pnpm build-and-test; then
  160. echo "::error::tests failed for $project"
  161. echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  162. cd - > /dev/null
  163. return 1
  164. fi
  165. else
  166. # Use Steel CLI
  167. if ! cargo install --quiet steel-cli; then
  168. echo "::error::steel-cli installation failed for $project"
  169. echo "$project: steel-cli installation failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  170. cd - > /dev/null
  171. return 1
  172. fi
  173. # Build
  174. if ! steel build; then
  175. echo "::error::steel build failed for $project"
  176. echo "$project: steel build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  177. cd - > /dev/null
  178. return 1
  179. fi
  180. # Test
  181. if ! steel test; then
  182. echo "::error::steel test failed for $project"
  183. echo "$project: steel test failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
  184. cd - > /dev/null
  185. return 1
  186. fi
  187. fi
  188. echo "Build and tests succeeded for $project with $solana_version version."
  189. cd - > /dev/null
  190. return 0
  191. }
  192. function process_projects() {
  193. local solana_version=$1
  194. readarray -t all_projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]?')
  195. start_index=$(( ${{ matrix.index }} * ${{ env.MIN_PROJECTS_PER_JOB }} ))
  196. end_index=$(( start_index + ${{ env.MIN_PROJECTS_PER_JOB }} ))
  197. end_index=$(( end_index > ${{ needs.changes.outputs.total_projects }} ? ${{ needs.changes.outputs.total_projects }} : end_index ))
  198. echo "Projects to build and test in this job"
  199. for i in $(seq $start_index $(( end_index - 1 ))); do
  200. echo "${all_projects[$i]}"
  201. done
  202. failed=false
  203. for i in $(seq $start_index $(( end_index - 1 ))); do
  204. echo "::group::Building and testing ${all_projects[$i]}"
  205. if ! build_and_test "${all_projects[$i]}" "$solana_version"; then
  206. failed=true
  207. fi
  208. echo "::endgroup::"
  209. done
  210. return $([ "$failed" = true ] && echo 1 || echo 0)
  211. }
  212. EOF
  213. # Make the script executable
  214. chmod +x build_and_test.sh
  215. - name: Setup Solana Beta
  216. uses: heyAyushh/setup-solana@v2
  217. with:
  218. solana-cli-version: beta
  219. - name: Build and Test with Beta
  220. run: |
  221. source build_and_test.sh
  222. solana -V
  223. rustc -V
  224. solana-keygen new --no-bip39-passphrase --force
  225. process_projects "beta"
  226. - name: Setup Solana Stable
  227. uses: heyAyushh/setup-solana@v2
  228. with:
  229. solana-cli-version: stable
  230. - name: Build and Test with Stable
  231. run: |
  232. source build_and_test.sh
  233. solana -V
  234. rustc -V
  235. solana-keygen new --no-bip39-passphrase --force
  236. process_projects "stable"
  237. - name: Set failed projects output
  238. id: set-failed
  239. if: failure()
  240. run: |
  241. if [ -f "$GITHUB_WORKSPACE/failed_projects.txt" ]; then
  242. failed_projects=$(cat $GITHUB_WORKSPACE/failed_projects.txt | jq -R -s -c 'split("\n")[:-1]')
  243. echo "failed_projects=$failed_projects" >> $GITHUB_OUTPUT
  244. else
  245. echo "failed_projects=[]" >> $GITHUB_OUTPUT
  246. fi
  247. summary:
  248. needs: [changes, build-and-test]
  249. if: always()
  250. runs-on: ubuntu-latest
  251. steps:
  252. - uses: actions/checkout@v4
  253. - name: Create job summary
  254. run: |
  255. echo "## Steel Workflow Summary" >> $GITHUB_STEP_SUMMARY
  256. echo "- Total projects: ${{ needs.changes.outputs.total_projects }}" >> $GITHUB_STEP_SUMMARY
  257. # List all processed projects
  258. echo "<details>" >> $GITHUB_STEP_SUMMARY
  259. echo "<summary>Projects processed (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY
  260. echo "" >> $GITHUB_STEP_SUMMARY
  261. echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]' | while read project; do
  262. echo "- $project" >> $GITHUB_STEP_SUMMARY
  263. done
  264. echo "" >> $GITHUB_STEP_SUMMARY
  265. echo "</details>" >> $GITHUB_STEP_SUMMARY
  266. # Report build and test results
  267. if [[ "${{ needs.build-and-test.result }}" == "failure" ]]; then
  268. echo "## :x: Build or tests failed" >> $GITHUB_STEP_SUMMARY
  269. echo "<details>" >> $GITHUB_STEP_SUMMARY
  270. echo "<summary>Failed projects (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY
  271. echo "" >> $GITHUB_STEP_SUMMARY
  272. failed_projects='${{ needs.build-and-test.outputs.failed_projects }}'
  273. if [[ -n "$failed_projects" ]]; then
  274. echo "$failed_projects" | jq -r '.[]' | while IFS=: read -r project failure_reason; do
  275. echo "- **$project**" >> $GITHUB_STEP_SUMMARY
  276. echo " - Failure reason: $failure_reason" >> $GITHUB_STEP_SUMMARY
  277. done
  278. else
  279. echo "No failed projects reported. This might indicate an unexpected error in the workflow." >> $GITHUB_STEP_SUMMARY
  280. fi
  281. echo "" >> $GITHUB_STEP_SUMMARY
  282. echo "</details>" >> $GITHUB_STEP_SUMMARY
  283. elif [[ "${{ needs.build-and-test.result }}" == "success" ]]; then
  284. echo "## :white_check_mark: All builds and tests passed" >> $GITHUB_STEP_SUMMARY
  285. else
  286. echo "## :warning: Build and test job was skipped or canceled" >> $GITHUB_STEP_SUMMARY
  287. fi