cypress.yml 6.2 KB

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