anchor.yml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. name: Anchor
  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. jobs:
  13. build:
  14. runs-on: ubuntu-latest
  15. permissions:
  16. pull-requests: read
  17. strategy:
  18. matrix:
  19. node-version: [20.x]
  20. solana-version: [1.18.17, stable]
  21. anchor-version: [0.30.1]
  22. steps:
  23. - uses: actions/checkout@v4
  24. - uses: dorny/paths-filter@v3
  25. if: github.event_name == 'pull_request'
  26. id: changes
  27. with:
  28. list-files: shell
  29. filters: |
  30. anchor:
  31. - added|modified: '**/anchor/**'
  32. anchor_action:
  33. - added|modified: '**/workflows/anchor.yml'
  34. - name: Setup Anchor
  35. if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule' || github.event_name == 'push'
  36. uses: heyAyushh/setup-anchor@v3.12
  37. with:
  38. anchor-version: ${{ matrix.anchor-version }}
  39. solana-cli-version: ${{ matrix.solana-version }}
  40. node-version: ${{ matrix.node-version }}
  41. - name: Display versions and Install pnpm
  42. if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule'
  43. run: |
  44. solana -V
  45. solana-keygen new --no-bip39-passphrase
  46. rustc -V
  47. anchor -V
  48. npm i -g pnpm
  49. # Run only if it's triggered by PR to main,
  50. # Build the changed programs
  51. - name: Build Changed Anchor programs
  52. if: steps.changes.outputs.anchor == 'true' && steps.changes.outputs.anchor_action != 'true'
  53. run: |
  54. changed_files=(${{ steps.changes.outputs.anchor_files }})
  55. # Read ignored projects from .github/.ghaignore, ignoring empty lines and comments
  56. ignored_projects=($(grep . .github/.ghaignore | grep -v '^$'))
  57. # Find anchor projects and remove ignored projects
  58. ProjectDirs=($(for file in "${changed_files[@]}"; do
  59. anchor_path=$(dirname "${file}" | grep anchor | sed 's#/anchor/.*#/anchor#g')
  60. if [[ ! " ${ignored_projects[*]} " =~ " ${anchor_path} " ]]; then
  61. echo "$anchor_path"
  62. fi
  63. done | sort -u))
  64. # Build anchor projects
  65. echo "Projects to Build:"
  66. printf "%s\n" "${ProjectDirs[@]}"
  67. for projectDir in "${ProjectDirs[@]}"; do
  68. echo "
  69. ********
  70. Building $projectDir
  71. ********"
  72. cd $projectDir
  73. if anchor build; then
  74. echo "Build succeeded for $projectDir."
  75. rm -rf target
  76. else
  77. failed=true
  78. failed_builds+=($projectDir)
  79. echo "Build failed for $projectDir. Continuing with the next program."
  80. fi
  81. cd - > /dev/null
  82. done
  83. if [ "$failed" = true ]; then
  84. echo "Programs that failed building:"
  85. printf "%s\n" "${failed_builds[@]}"
  86. exit 1
  87. else
  88. echo "All programs built successfully."
  89. fi
  90. shell: bash
  91. # Skip Building all Programs if it's a PR to main branch
  92. - name: Build All Anchor programs
  93. if: github.event_name == 'schedule' || github.event_name == 'push' || steps.changes.outputs.anchor_action == 'true'
  94. run: |
  95. # Find all anchor projects and remove ignored projects
  96. declare -a ProjectDirs=($(find . -type d -name 'anchor' | sed 's|^\./||'| grep -v -f <(grep . .github/.ghaignore | grep -v '^$')))
  97. echo "Projects to Build:"
  98. printf "%s\n" "${ProjectDirs[@]}"
  99. # Build anchor projects
  100. for projectDir in "${ProjectDirs[@]}"; do
  101. echo "
  102. ********
  103. Building $projectDir
  104. ********"
  105. cd $projectDir
  106. if anchor build; then
  107. echo "Build succeeded for $projectDir."
  108. rm -rf target
  109. else
  110. failed=true
  111. failed_builds+=($projectDir)
  112. echo "Build failed for $projectDir. Continuing with the next program."
  113. fi
  114. cd - > /dev/null
  115. done
  116. if [ "$failed" = true ]; then
  117. echo "Programs that failed building:"
  118. printf "%s\n" "${failed_builds[@]}"
  119. exit 1
  120. else
  121. echo "All programs built successfully."
  122. fi
  123. shell: bash
  124. test:
  125. runs-on: ubuntu-latest
  126. permissions:
  127. pull-requests: read
  128. strategy:
  129. matrix:
  130. node-version: [20.x]
  131. solana-version: [1.18.17, stable]
  132. anchor-version: [0.30.1]
  133. steps:
  134. - uses: actions/checkout@v4
  135. - uses: dorny/paths-filter@v3
  136. if: github.event_name == 'pull_request'
  137. id: changes
  138. with:
  139. list-files: shell
  140. filters: |
  141. anchor:
  142. - added|modified: '**/anchor/**'
  143. anchor_action:
  144. - added|modified: '**/workflows/anchor.yml'
  145. # Skip Installing and Displaying versions if theres no change in anchor programs or anchor action workflow file or isn't a schedule event
  146. - name: Setup Anchor
  147. if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule' || github.event_name == 'push'
  148. uses: heyAyushh/setup-anchor@v3.12
  149. with:
  150. anchor-version: ${{ matrix.anchor-version }}
  151. solana-cli-version: ${{ matrix.solana-version }}
  152. node-version: ${{ matrix.node-version }}
  153. - name: Display versions and Install pnpm
  154. if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule'
  155. run: |
  156. solana -V
  157. solana-keygen new --no-bip39-passphrase
  158. rustc -V
  159. anchor -V
  160. npm i -g pnpm
  161. - name: Test Changed Anchor Programs
  162. if: steps.changes.outputs.anchor == 'true' && steps.changes.outputs.anchor_action != 'true'
  163. run: |
  164. changed_files=(${{ steps.changes.outputs.anchor_files }})
  165. ProjectDirs=($(for file in "${changed_files[@]}"; do dirname "${file}" | grep anchor | sed 's#/anchor/.*#/anchor#g'; done | grep -v -f <(grep . .github/.ghaignore | grep -v '^$') | sort -u))
  166. echo "Projects to Test:"
  167. printf "%s\n" "${ProjectDirs[@]}"
  168. for projectDir in "${ProjectDirs[@]}"; do
  169. echo "
  170. ********
  171. Testing $projectDir
  172. ********"
  173. cd $projectDir
  174. if pnpm install --frozen-lockfile && anchor test; then
  175. echo "Tests succeeded for $projectDir."
  176. rm -rf target node_modules
  177. else
  178. failed=true
  179. failed_tests+=($projectDir)
  180. echo "Tests failed for $val. Continuing with the next program."
  181. fi
  182. cd - > /dev/null
  183. done
  184. if [ "$failed" = true ]; then
  185. echo "*****************************"
  186. echo "Programs that failed testing:"
  187. printf "%s\n" "${failed_tests[@]}"
  188. exit 1
  189. else
  190. echo "All tests passed."
  191. fi
  192. shell: bash
  193. # Skip Testing all Programs if it's a CRON job or a change in the workflow file
  194. - name: Test All Anchor Programs
  195. if: github.event_name == 'schedule' || steps.changes.outputs.anchor_action == 'true'
  196. run: |
  197. declare -a ProjectDirs=($(find . -type d -name "anchor"| grep -v -f <(grep . .github/.ghaignore | grep -v '^$')))
  198. echo "Projects to Test:"
  199. printf "%s\n" "${ProjectDirs[@]}"
  200. for projectDir in "${ProjectDirs[@]}"; do
  201. echo "
  202. ********
  203. Testing $projectDir
  204. ********"
  205. cd $projectDir
  206. pnpm install --frozen-lockfile
  207. if anchor test; then
  208. echo "Tests succeeded for $projectDir."
  209. rm -rf target node_modules
  210. else
  211. failed=true
  212. failed_tests+=($projectDir)
  213. echo "Tests failed for $val. Continuing with the next program."
  214. fi
  215. cd - > /dev/null
  216. done
  217. if [ "$failed" = true ]; then
  218. echo "*****************************"
  219. echo "Programs that failed testing:"
  220. printf "%s\n" "${failed_tests[@]}"
  221. exit 1
  222. else
  223. echo "All tests passed."
  224. fi
  225. shell: bash