cypress.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. name: Cypress
  2. on:
  3. pull_request:
  4. push:
  5. branches:
  6. - main
  7. - master
  8. - stable*
  9. env:
  10. # Adjust APP_NAME if your repository name is different
  11. APP_NAME: ${{ github.event.repository.name }}
  12. # Server requires head_ref instead of base_ref, as we want to test the PR branch
  13. BRANCH: ${{ github.head_ref || github.ref_name }}
  14. jobs:
  15. init:
  16. runs-on: ubuntu-latest
  17. outputs:
  18. nodeVersion: ${{ steps.versions.outputs.nodeVersion }}
  19. npmVersion: ${{ steps.versions.outputs.npmVersion }}
  20. steps:
  21. - name: Checkout app
  22. uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3.5.2
  23. - name: Check composer.json
  24. id: check_composer
  25. uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
  26. with:
  27. files: "composer.json"
  28. - name: Install composer dependencies
  29. if: steps.check_composer.outputs.files_exists == 'true'
  30. run: composer install --no-dev
  31. - name: Read package.json node and npm engines version
  32. uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2
  33. id: versions
  34. with:
  35. fallbackNode: "^14"
  36. fallbackNpm: "^7"
  37. - name: Set up node ${{ steps.versions.outputs.nodeVersion }}
  38. uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
  39. with:
  40. node-version: ${{ steps.versions.outputs.nodeVersion }}
  41. - name: Set up npm ${{ steps.versions.outputs.npmVersion }}
  42. run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
  43. - name: Install node dependencies & build app
  44. run: |
  45. npm ci
  46. TESTING=true npm run build --if-present
  47. - name: Show cypress version
  48. run: npm run cypress:version
  49. - name: Save context
  50. uses: buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
  51. with:
  52. key: cypress-context-${{ github.run_id }}
  53. path: ./
  54. cypress:
  55. runs-on: ubuntu-latest
  56. needs: init
  57. strategy:
  58. fail-fast: false
  59. matrix:
  60. # Run multiple copies of the current job in parallel
  61. # Please increase the number or runners as your tests suite grows (0 based index for e2e tests)
  62. containers: ["component", 0, 1, 2]
  63. # Hack as strategy.job-total includes the component and GitHub does not allow math expressions
  64. # Always aling this number with the total of e2e runners (max. index + 1)
  65. total-containers: [3]
  66. name: runner ${{ matrix.containers }}
  67. steps:
  68. - name: Restore context
  69. uses: buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
  70. with:
  71. fail-on-cache-miss: true
  72. key: cypress-context-${{ github.run_id }}
  73. path: ./
  74. - name: Set up node ${{ needs.init.outputs.nodeVersion }}
  75. uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
  76. with:
  77. node-version: ${{ needs.init.outputs.nodeVersion }}
  78. - name: Set up npm ${{ needs.init.outputs.npmVersion }}
  79. run: npm i -g npm@"${{ needs.init.outputs.npmVersion }}"
  80. - name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
  81. uses: cypress-io/github-action@59810ebfa5a5ac6fcfdcfdf036d1cd4d083a88f2 # v6.5.0
  82. with:
  83. component: ${{ matrix.containers == 'component' }}
  84. group: ${{ matrix.use-cypress-cloud && matrix.containers == 'component' && 'Run component' || matrix.use-cypress-cloud && 'Run E2E' || '' }}
  85. # cypress env
  86. ci-build-id: ${{ matrix.use-cypress-cloud && format('{0}-{1}', github.sha, github.run_number) || '' }}
  87. tag: ${{ matrix.use-cypress-cloud && github.event_name || '' }}
  88. env:
  89. # Needs to be prefixed with CYPRESS_
  90. CYPRESS_BRANCH: ${{ env.BRANCH }}
  91. # https://github.com/cypress-io/github-action/issues/124
  92. COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
  93. # Needed for some specific code workarounds
  94. TESTING: true
  95. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  96. CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
  97. SPLIT: ${{ matrix.total-containers }}
  98. SPLIT_INDEX: ${{ matrix.containers == 'component' && 0 || matrix.containers }}
  99. - name: Upload snapshots
  100. uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
  101. if: always()
  102. with:
  103. name: snapshots_${{ matrix.containers }}
  104. path: cypress/snapshots
  105. - name: Extract NC logs
  106. if: failure() && matrix.containers != 'component'
  107. run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log
  108. - name: Upload NC logs
  109. uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
  110. if: failure() && matrix.containers != 'component'
  111. with:
  112. name: nc_logs_${{ matrix.containers }}
  113. path: nextcloud.log
  114. - name: Create data dir archive
  115. if: failure() && matrix.containers != 'component'
  116. run: docker exec nextcloud-cypress-tests-server tar -cvjf - data > data.tar
  117. - name: Upload data dir archive
  118. uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
  119. if: failure() && matrix.containers != 'component'
  120. with:
  121. name: nc_data_${{ matrix.containers }}
  122. path: data.tar
  123. summary:
  124. runs-on: ubuntu-latest
  125. needs: [init, cypress]
  126. if: always()
  127. name: cypress-summary
  128. steps:
  129. - name: Summary status
  130. run: if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi