cypress.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. PUPPETEER_SKIP_DOWNLOAD: true
  26. steps:
  27. - name: Disabled on forks
  28. if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
  29. run: |
  30. echo 'Can not run cypress on forks'
  31. exit 1
  32. - name: Checkout server
  33. uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  34. with:
  35. # We need to checkout submodules for 3rdparty
  36. submodules: true
  37. - name: Check composer.json
  38. id: check_composer
  39. uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
  40. with:
  41. files: "composer.json"
  42. - name: Install composer dependencies
  43. if: steps.check_composer.outputs.files_exists == 'true'
  44. run: composer install --no-dev
  45. - name: Read package.json node and npm engines version
  46. uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
  47. id: versions
  48. with:
  49. fallbackNode: "^20"
  50. fallbackNpm: "^10"
  51. - name: Set up node ${{ steps.versions.outputs.nodeVersion }}
  52. uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
  53. with:
  54. node-version: ${{ steps.versions.outputs.nodeVersion }}
  55. - name: Set up npm ${{ steps.versions.outputs.npmVersion }}
  56. run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'
  57. - name: Install node dependencies & build app
  58. run: |
  59. npm ci
  60. TESTING=true npm run build --if-present
  61. - name: Show cypress version
  62. run: npm run cypress:version
  63. - name: Save context
  64. uses: buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
  65. with:
  66. key: cypress-context-${{ github.run_id }}
  67. path: ./
  68. cypress:
  69. runs-on: ubuntu-latest
  70. needs: init
  71. strategy:
  72. fail-fast: false
  73. matrix:
  74. # Run multiple copies of the current job in parallel
  75. # Please increase the number or runners as your tests suite grows (0 based index for e2e tests)
  76. containers: ["component", '0', '1', '2', '3', '4', '5']
  77. # Hack as strategy.job-total includes the component and GitHub does not allow math expressions
  78. # Always align this number with the total of e2e runners (max. index + 1)
  79. total-containers: [6]
  80. name: runner ${{ matrix.containers }}
  81. steps:
  82. - name: Restore context
  83. uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
  84. with:
  85. fail-on-cache-miss: true
  86. key: cypress-context-${{ github.run_id }}
  87. path: ./
  88. - name: Set up node ${{ needs.init.outputs.nodeVersion }}
  89. uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
  90. with:
  91. node-version: ${{ needs.init.outputs.nodeVersion }}
  92. - name: Set up npm ${{ needs.init.outputs.npmVersion }}
  93. run: npm i -g 'npm@${{ needs.init.outputs.npmVersion }}'
  94. - name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
  95. uses: cypress-io/github-action@8d3918616d8ac34caa2b49afc8b408b6a872a6f5 # v6.7.1
  96. with:
  97. component: ${{ matrix.containers == 'component' }}
  98. group: ${{ matrix.use-cypress-cloud && matrix.containers == 'component' && 'Run component' || matrix.use-cypress-cloud && 'Run E2E' || '' }}
  99. # cypress env
  100. ci-build-id: ${{ matrix.use-cypress-cloud && format('{0}-{1}', github.sha, github.run_number) || '' }}
  101. tag: ${{ matrix.use-cypress-cloud && github.event_name || '' }}
  102. env:
  103. # Needs to be prefixed with CYPRESS_
  104. CYPRESS_BRANCH: ${{ env.BRANCH }}
  105. # https://github.com/cypress-io/github-action/issues/124
  106. COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
  107. # Needed for some specific code workarounds
  108. TESTING: true
  109. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  110. CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
  111. SPLIT: ${{ matrix.total-containers }}
  112. SPLIT_INDEX: ${{ matrix.containers == 'component' && 0 || matrix.containers }}
  113. - name: Upload snapshots
  114. uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  115. if: always()
  116. with:
  117. name: snapshots_${{ matrix.containers }}
  118. path: cypress/snapshots
  119. - name: Extract NC logs
  120. if: failure() && matrix.containers != 'component'
  121. run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log
  122. - name: Upload NC logs
  123. uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  124. if: failure() && matrix.containers != 'component'
  125. with:
  126. name: nc_logs_${{ matrix.containers }}
  127. path: nextcloud.log
  128. - name: Create data dir archive
  129. if: failure() && matrix.containers != 'component'
  130. run: docker exec nextcloud-cypress-tests-server tar -cvjf - data > data.tar
  131. - name: Upload data dir archive
  132. uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
  133. if: failure() && matrix.containers != 'component'
  134. with:
  135. name: nc_data_${{ matrix.containers }}
  136. path: data.tar
  137. summary:
  138. runs-on: ubuntu-latest-low
  139. needs: [init, cypress]
  140. if: always()
  141. name: cypress-summary
  142. steps:
  143. - name: Summary status
  144. run: if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi