build_and_test.yml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. name: Build & Test
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - master
  7. - minor
  8. - major
  9. paths:
  10. - 'packages/**'
  11. - 'package.json'
  12. - 'package-lock.json'
  13. pull_request:
  14. branches:
  15. - master
  16. - major
  17. - minor
  18. paths:
  19. - 'packages/**'
  20. - 'package.json'
  21. - 'package-lock.json'
  22. env:
  23. CI: true
  24. concurrency:
  25. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  26. cancel-in-progress: true
  27. jobs:
  28. codegen:
  29. uses: ./.github/workflows/codegen.yml
  30. build:
  31. name: build
  32. runs-on: ubuntu-latest
  33. permissions:
  34. contents: read
  35. strategy:
  36. matrix:
  37. node: [20.x, 22.x, 24.x]
  38. steps:
  39. - uses: actions/checkout@v4
  40. - name: Use Node.js ${{ matrix.node }}
  41. uses: actions/setup-node@v4
  42. with:
  43. node-version: ${{ matrix.node }}
  44. - name: Cache node_modules
  45. uses: actions/cache@v4
  46. with:
  47. path: node_modules
  48. key: npm-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
  49. restore-keys: |
  50. npm-${{ runner.os }}-${{ matrix.node }}-
  51. - name: npm install
  52. run: |
  53. npm install
  54. npm install --os=linux --cpu=x64 sharp
  55. - name: Cache Nx
  56. uses: actions/cache@v4
  57. with:
  58. path: node_modules/.cache/nx
  59. key: nx-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}-${{ github.sha }}
  60. restore-keys: |
  61. nx-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}-
  62. nx-${{ runner.os }}-${{ matrix.node }}-
  63. - name: Build
  64. run: npm run build
  65. unit-tests:
  66. name: unit tests
  67. runs-on: ubuntu-latest
  68. permissions:
  69. contents: read
  70. strategy:
  71. matrix:
  72. node: [20.x, 22.x, 24.x]
  73. steps:
  74. - uses: actions/checkout@v4
  75. - name: Use Node.js ${{ matrix.node }}
  76. uses: actions/setup-node@v4
  77. with:
  78. node-version: ${{ matrix.node }}
  79. - name: Cache node_modules
  80. uses: actions/cache@v4
  81. with:
  82. path: node_modules
  83. key: npm-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
  84. restore-keys: |
  85. npm-${{ runner.os }}-${{ matrix.node }}-
  86. - name: npm install
  87. run: |
  88. npm install
  89. npm install --os=linux --cpu=x64 sharp
  90. - name: Cache Nx
  91. uses: actions/cache@v4
  92. with:
  93. path: node_modules/.cache/nx
  94. key: nx-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}-${{ github.sha }}
  95. restore-keys: |
  96. nx-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}-
  97. nx-${{ runner.os }}-${{ matrix.node }}-
  98. - name: Build
  99. run: npx lerna run ci
  100. - name: Unit tests
  101. run: npm run test
  102. e2e-tests:
  103. name: e2e tests
  104. runs-on: ubuntu-latest
  105. permissions:
  106. contents: read
  107. services:
  108. mariadb:
  109. # With v11.6.2+, a default was changed, (https://mariadb.com/kb/en/innodb-system-variables/#innodb_snapshot_isolation)
  110. # which causes e2e test failures currently
  111. image: mariadb:11.5
  112. env:
  113. MARIADB_ROOT_PASSWORD: password
  114. ports:
  115. - 3306
  116. options: --health-cmd="mariadb-admin ping -h localhost -u vendure -ppassword" --health-interval=10s --health-timeout=5s --health-retries=3
  117. mysql:
  118. image: vendure/mysql-8-native-auth:latest
  119. env:
  120. MYSQL_ROOT_PASSWORD: password
  121. ports:
  122. - 3306
  123. options: --health-cmd="mysqladmin ping --silent" --health-interval=10s --health-timeout=20s --health-retries=10
  124. postgres:
  125. image: postgres:16
  126. env:
  127. POSTGRES_USER: vendure
  128. POSTGRES_PASSWORD: password
  129. ports:
  130. - 5432
  131. options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
  132. elastic:
  133. image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
  134. env:
  135. discovery.type: single-node
  136. bootstrap.memory_lock: true
  137. ES_JAVA_OPTS: -Xms512m -Xmx512m
  138. # Elasticsearch will force read-only mode when total available disk space is less than 5%. Since we will
  139. # be running on a shared Azure instance with 84GB SSD, we easily go below 5% available even when there are still
  140. # > 3GB free. So we set this value to an absolute one rather than a percentage to prevent all the Elasticsearch
  141. # e2e tests from failing.
  142. cluster.routing.allocation.disk.watermark.low: 500mb
  143. cluster.routing.allocation.disk.watermark.high: 200mb
  144. cluster.routing.allocation.disk.watermark.flood_stage: 100mb
  145. ports:
  146. - 9200
  147. options: --health-cmd="curl --silent --fail localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=3
  148. redis:
  149. image: redis:7.4.1
  150. ports:
  151. - 6379
  152. strategy:
  153. fail-fast: false
  154. matrix:
  155. node: [20.x, 22.x, 24.x]
  156. db: [sqljs, mariadb, mysql, postgres]
  157. steps:
  158. - uses: actions/checkout@v4
  159. - name: Use Node.js ${{ matrix.node }}
  160. uses: actions/setup-node@v4
  161. with:
  162. node-version: ${{ matrix.node }}
  163. - name: Cache node_modules
  164. uses: actions/cache@v4
  165. with:
  166. path: node_modules
  167. key: npm-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
  168. restore-keys: |
  169. npm-${{ runner.os }}-${{ matrix.node }}-
  170. - name: npm install
  171. run: |
  172. npm install
  173. npm install --os=linux --cpu=x64 sharp
  174. - name: Cache Nx
  175. uses: actions/cache@v4
  176. with:
  177. path: node_modules/.cache/nx
  178. key: nx-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}-${{ github.sha }}
  179. restore-keys: |
  180. nx-${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}-
  181. nx-${{ runner.os }}-${{ matrix.node }}-
  182. - name: Build
  183. run: npx lerna run ci
  184. - name: e2e tests
  185. env:
  186. E2E_MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
  187. E2E_MARIADB_PORT: ${{ job.services.mariadb.ports['3306'] }}
  188. E2E_POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }}
  189. E2E_ELASTIC_PORT: ${{ job.services.elastic.ports['9200'] }}
  190. E2E_REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
  191. DB: ${{ matrix.db }}
  192. run: npm run e2e