anchor.yml 7.5 KB

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