cypress.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # This workflow is provided via the organization template repository
  2. #
  3. # https://github.com/nextcloud/.github
  4. # https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
  5. #
  6. # SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
  7. # SPDX-License-Identifier: MIT
  8. name: Cypress
  9. on: pull_request
  10. concurrency:
  11. group: cypress-${{ github.head_ref || github.run_id }}
  12. cancel-in-progress: true
  13. env:
  14. # Adjust APP_NAME if your repository name is different
  15. APP_NAME: ${{ github.event.repository.name }}
  16. # Server requires head_ref instead of base_ref, as we want to test the PR branch
  17. BRANCH: ${{ github.head_ref || github.ref_name }}
  18. jobs:
  19. init:
  20. runs-on: ubuntu-latest
  21. outputs:
  22. nodeVersion: ${{ steps.versions.outputs.nodeVersion }}
  23. npmVersion: ${{ steps.versions.outputs.npmVersion }}
  24. env:
  25. # We'll install cypress in the cypress job
  26. CYPRESS_INSTALL_BINARY: 0
  27. PUPPETEER_SKIP_DOWNLOAD: true
  28. steps:
  29. - name: Disabled on forks
  30. if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
  31. run: |
  32. echo 'Can not run cypress on forks'
  33. exit 1
  34. - name: Checkout server
  35. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  36. with:
  37. # We need to checkout submodules for 3rdparty
  38. submodules: true
  39. - name: Check composer.json
  40. id: check_composer
  41. uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
  42. with:
  43. files: "composer.json"
  44. - name: Install composer dependencies
  45. if: steps.check_composer.outputs.files_exists == 'true'
  46. run: composer install --no-dev
  47. - name: Read package.json node and npm engines version
  48. uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
  49. id: versions
  50. with:
  51. fallbackNode: "^20"
  52. fallbackNpm: "^10"
  53. - name: Set up node ${{ steps.versions.outputs.nodeVersion }}
  54. uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
  55. with:
  56. node-version: ${{ steps.versions.outputs.nodeVersion }}
  57. - name: Set up npm ${{ steps.versions.outputs.npmVersion }}
  58. run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'
  59. - name: Install node dependencies & build app
  60. run: |
  61. npm ci
  62. TESTING=true npm run build --if-present
  63. - name: Show cypress version
  64. run: npm run cypress:version
  65. - name: Save context
  66. uses: buildjet/cache/save@v4
  67. with:
  68. key: cypress-context-${{ github.run_id }}
  69. path: ./
  70. cypress:
  71. runs-on: ubuntu-latest
  72. needs: init
  73. strategy:
  74. fail-fast: false
  75. matrix:
  76. # Run multiple copies of the current job in parallel
  77. # Please increase the number or runners as your tests suite grows (0 based index for e2e tests)
  78. containers: ["component", '0', '1', '2', '3', '4', '5', '6', '7']
  79. # Hack as strategy.job-total includes the component and GitHub does not allow math expressions
  80. # Always align this number with the total of e2e runners (max. index + 1)
  81. total-containers: [8]
  82. name: runner ${{ matrix.containers }}
  83. steps:
  84. - name: Restore context
  85. uses: buildjet/cache/restore@v4
  86. with:
  87. fail-on-cache-miss: true
  88. key: cypress-context-${{ github.run_id }}
  89. path: ./
  90. - name: Set up node ${{ needs.init.outputs.nodeVersion }}
  91. uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
  92. with:
  93. node-version: ${{ needs.init.outputs.nodeVersion }}
  94. - name: Set up npm ${{ needs.init.outputs.npmVersion }}
  95. run: npm i -g 'npm@${{ needs.init.outputs.npmVersion }}'
  96. - name: Install cypress
  97. run: ./node_modules/cypress/bin/cypress install
  98. - name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
  99. uses: cypress-io/github-action@0da3c06ed8217b912deea9d8ee69630baed1737e # v6.7.6
  100. with:
  101. # We already installed the dependencies in the init job
  102. install: false
  103. component: ${{ matrix.containers == 'component' }}
  104. group: ${{ matrix.use-cypress-cloud && matrix.containers == 'component' && 'Run component' || matrix.use-cypress-cloud && 'Run E2E' || '' }}
  105. # cypress env
  106. ci-build-id: ${{ matrix.use-cypress-cloud && format('{0}-{1}', github.sha, github.run_number) || '' }}
  107. tag: ${{ matrix.use-cypress-cloud && github.event_name || '' }}
  108. env:
  109. # Needs to be prefixed with CYPRESS_
  110. CYPRESS_BRANCH: ${{ env.BRANCH }}
  111. # https://github.com/cypress-io/github-action/issues/124
  112. COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
  113. # Needed for some specific code workarounds
  114. TESTING: true
  115. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  116. CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
  117. SPLIT: ${{ matrix.total-containers }}
  118. SPLIT_INDEX: ${{ matrix.containers == 'component' && 0 || matrix.containers }}
  119. - name: Upload snapshots
  120. uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
  121. if: always()
  122. with:
  123. name: snapshots_${{ matrix.containers }}
  124. path: cypress/snapshots
  125. - name: Extract NC logs
  126. if: failure() && matrix.containers != 'component'
  127. run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log
  128. - name: Upload NC logs
  129. uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
  130. if: failure() && matrix.containers != 'component'
  131. with:
  132. name: nc_logs_${{ matrix.containers }}
  133. path: nextcloud.log
  134. - name: Create data dir archive
  135. if: failure() && matrix.containers != 'component'
  136. run: docker exec nextcloud-cypress-tests_server tar -cvjf - data > data.tar
  137. - name: Upload data dir archive
  138. uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
  139. if: failure() && matrix.containers != 'component'
  140. with:
  141. name: nc_data_${{ matrix.containers }}
  142. path: data.tar
  143. summary:
  144. runs-on: ubuntu-latest-low
  145. needs: [init, cypress]
  146. if: always()
  147. name: cypress-summary
  148. steps:
  149. - name: Summary status
  150. run: if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi