From 1f9166922c0957354e4be08c8f9384bd04cb995f Mon Sep 17 00:00:00 2001 From: Sem Bauke <46919888+Sembauke@users.noreply.github.com> Date: Fri, 9 Apr 2021 05:14:45 +0100 Subject: [PATCH] feat(Cypress): enabling parallelization Cypress (#41782) Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> --- .../workflows/{cypress.yml => cypress-pr.yml} | 4 +- .github/workflows/cypress-push.yml | 78 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) rename .github/workflows/{cypress.yml => cypress-pr.yml} (97%) create mode 100644 .github/workflows/cypress-push.yml diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress-pr.yml similarity index 97% rename from .github/workflows/cypress.yml rename to .github/workflows/cypress-pr.yml index 7a7f8d39d5..82285561a3 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress-pr.yml @@ -1,5 +1,5 @@ -name: Cypress -on: [push, pull_request] +name: Cypress - Pull Request +on: [pull_request] jobs: cypress-run: diff --git a/.github/workflows/cypress-push.yml b/.github/workflows/cypress-push.yml new file mode 100644 index 0000000000..70fdb064aa --- /dev/null +++ b/.github/workflows/cypress-push.yml @@ -0,0 +1,78 @@ +name: Cypress - Push +on: [push] + +jobs: + cypress-run: + name: Test + runs-on: ubuntu-18.04 + strategy: + fail-fast: false + matrix: + containers: [1, 2, 3] + browsers: [chrome, firefox] + node-version: [14.x] + services: + mongodb: + image: mongo:3.6.19 + ports: + - 27017:27017 + + steps: + # We use .npmrc to set the default version to 0, and prevents download during development. + # This installs it specifically in the CI runs. + - name: Set Action Environment Variables + run: | + echo "CYPRESS_RECORD_KEY=${{ secrets.CYPRESS_RECORD_KEY }}" >> $GITHUB_ENV + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + echo "CYPRESS_INSTALL_BINARY=6.0.0" >> $GITHUB_ENV + + - name: Checkout Source Files + uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Set freeCodeCamp Environment Variables + run: cp sample.env .env + + - name: Install Dependencies + run: | + npm ci + npm run ensure-env + npm run build:curriculum + + - name: Seed Database + run: npm run seed + + - name: Cypress run + uses: cypress-io/github-action@v2 + with: + parallel: ${{ env.CYPRESS_RECORD_KEY != 0 }} + group: ${{ matrix.browsers }} + record: ${{ env.CYPRESS_RECORD_KEY != 0 }} + build: npm run build + # this should mirror the production build, but for now we're using gatsby + # serve instead (the npm script serve:client needs updating!) + start: npm run start-ci + wait-on: http://localhost:8000 + # the site builds in about 8 minutes, so there is currently 12 minutes of time + # left for testing. + wait-on-timeout: 1200 + config: baseUrl=http://localhost:8000 + browser: ${{ matrix.browsers }} + headless: true