Advertisement
Guest User

Cypress Parallel tests Github Actions without Dashboard

a guest
Jan 5th, 2021
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. # This is a basic workflow to help you get started with Actions
  2. name: Project
  3.  
  4. # Controls when the action will run. Triggers the workflow on push or pull request
  5. # events but only for the master branch
  6. on:
  7. push:
  8. branches: [master, preprod, staging]
  9. pull_request:
  10. branches: [master, preprod, staging]
  11.  
  12. jobs:
  13. setup:
  14. runs-on: ubuntu-latest
  15. outputs:
  16. # will contain a json string with an array of n elements, each being a string of spec files delimited by ,
  17. test-chunks: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
  18. # json string with ids to use in the next job matrix depending on how many elements are in the above array, eg: [0,1]
  19. test-chunk-ids: ${{ steps['set-test-chunk-ids'].outputs['test-chunk-ids'] }}
  20. steps:
  21. - uses: actions/checkout@v2
  22. - id: set-test-chunks
  23. name: Set Chunks
  24. # get all spec files from the integration directory, group them to be at most 15 at a time and transform them to json
  25. run: echo "::set-output name=test-chunks::$(find cypress/integration -type f -name "*.spec.js" | xargs -n15 | tr ' ' ',' | jq -R . | jq -s -cM .)"
  26. - id: set-test-chunk-ids
  27. name: Set Chunk IDs
  28. # get the number of elements from the above array as an array of indexes
  29. run: echo "::set-output name=test-chunk-ids::$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')"
  30. env:
  31. CHUNKS: ${{ steps['set-test-chunks'].outputs['test-chunks'] }}
  32.  
  33. tests:
  34. needs:
  35. - setup
  36. runs-on: ubuntu-latest
  37. container:
  38. # use cypress image, since just using node 12 doesn't work currently for some reason, gives node-sass error
  39. image: cypress/browsers:node12.13.0-chrome78-ff70
  40. options: "--ipc=host" # fix for a cypress bug
  41. name: test (chunk ${{ matrix.chunk }})
  42. strategy:
  43. matrix:
  44. # will be for eg chunk: [0,1]
  45. chunk: ${{ fromJson(needs.setup.outputs['test-chunk-ids']) }}
  46. steps:
  47. - name: Checkout
  48. uses: actions/checkout@v2
  49.  
  50. - name: Add domain to hosts file
  51. run: echo "127.0.0.1 your.domain" | tee -a /etc/hosts
  52.  
  53. # cache cypress and node_modules for faster operation
  54. - uses: actions/cache@v2
  55. with:
  56. path: '~/.cache/Cypress'
  57. key: ${{ runner.os }}-cypress-${{ hashFiles('**/yarn.lock') }}
  58.  
  59. - uses: actions/cache@v2
  60. with:
  61. path: '**/node_modules'
  62. key: ${{ runner.os }}-modules-docker-${{ hashFiles('**/yarn.lock') }}
  63.  
  64. # in case cache is not valid, install the dependencies
  65. - run: yarn --frozen-lockfile
  66. - run: yarn run cypress install
  67.  
  68. # run the frontend server in background and wait for it to be available
  69. - run: PORT=443 HTTPS=true yarn ci-start &
  70. - run: npx wait-on https://your.domain --timeout 180000
  71.  
  72. # the cypress docker doesn't contain jq, and we need it for easier parsing of json array string.
  73. # This could be improved in the future, but only adds ~2s to the build time
  74. - run: apt-get install jq -y
  75.  
  76. - name: Run Cypress
  77. run: SPECS=$(echo $CHUNKS | jq -cMr '.[${{ matrix.chunk }}] | @text') && yarn cypress:ci --spec $SPECS
  78. env:
  79. NODE_TLS_REJECT_UNAUTHORIZED: 0
  80. CHUNKS: ${{ needs.setup.outputs['test-chunks'] }}
  81.  
  82. testsall:
  83. if: ${{ always() }}
  84. runs-on: ubuntu-latest
  85. name: Tests All
  86. needs: tests
  87. steps:
  88. - name: Check tests matrix status
  89. if: ${{ needs.tests.result != 'success' }}
  90. run: exit 1
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement