soccerway
soccerway

Reputation: 11981

How can we run e2e tests from different repos

We have mainly three repos in our project.Currently the automation test runs automatically when a pull request created against the e2e-automation repo. How can I run the same automation tests from front-end-main & api-gateway-main repos while a pull request is being created using github actions work flow ? Can someone please advise ?

//Project Github Repos:

e2e-automation repo // cypress automation tests

front-end-main repo  // react js front end 

api-gateway-main repo // api services

// .github\workflows\main.yml

name: Cypress Automation Tests
on:
  pull_request:
    types: [opened, synchronize, reopened]
  push:
    branches: [main]
env:
  CYPRESS_CARGO_BOOKING_PASSWORD: ${{ secrets.CYPRESS_CARGO_BOOKING_PASSWORD }}
  CYPRESS_CARGO_SIGNUP_PASSWORD: ${{ secrets.CYPRESS_CARGO_SIGNUP_PASSWORD }}
jobs:
  install:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install dependencies
        uses: cypress-io/github-action@v2
        with:
          # perform the installation
          runTests: false
  tests:
    runs-on: ubuntu-22.04
    needs: install
    steps:
      - name: Check out code
        uses: actions/checkout@v2
        # we re-install the dependencies
      - name: Install dependencies
        uses: cypress-io/github-action@v2
        with:
          # perform the installation
          runTests: false
      - name: Run e2e automation regression tests
        run: npm run cy:run -- --env grepTags="@Regression+-@Failing",ENV="staging" --browser chrome
      - name: Upload Results
        uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
      - uses: actions/upload-artifact@v2
        if: always()
        with:
          name: cypress-videos
          path: cypress/videos

This is just a draft try out as per advised in the below answer:

This is the existing automation repo e2e-automation repo, which run cypress automation tests, which has the main.yml file with below contents only

name: Cypress Automation Tests
on:
  pull_request:
    types: [opened, synchronize, reopened]
  push:
    branches: [main]
jobs:
  tests:
    runs-on: ubuntu-22.04
    steps:
      - name: Cypress run
        uses: my-github-account/cypress-test-action
    

So in the below front end repo, i need to create a new action.yml file with contents copied from the original mail.yml file:

front-end-main repo // react js front end

name: Cypress Automation Tests
on:
  pull_request:
    types: [opened, synchronize, reopened]
  push:
    branches: [main]
env:
  CYPRESS_CARGO_BOOKING_PASSWORD: ${{ secrets.CYPRESS_CARGO_BOOKING_PASSWORD }}
  CYPRESS_CARGO_SIGNUP_PASSWORD: ${{ secrets.CYPRESS_CARGO_SIGNUP_PASSWORD }}
jobs:
  install:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install dependencies
        uses: cypress-io/github-action@v2
        with:
          # perform the installation
          runTests: false
  tests:
    runs-on: ubuntu-22.04
    needs: install
    steps:
      - name: Check out code
        uses: actions/checkout@v2
        # we re-install the dependencies
      - name: Install dependencies
        uses: cypress-io/github-action@v2
        with:
          # perform the installation
          runTests: false
      - name: Run e2e automation regression tests
        run: npm run cy:run -- --env grepTags="@Regression+-@Failing",ENV="staging" --browser chrome
      - name: Upload Results
        uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
      - uses: actions/upload-artifact@v2
        if: always()
        with:
          name: cypress-videos
          path: cypress/videos

Upvotes: 1

Views: 1039

Answers (1)

Paolo
Paolo

Reputation: 5451

Take a look at the step uses: cypress-io/github-action@v2.

This links to the Cypress repo at cypress-io/github-action.

Explicit version

- name: Cypress run
  uses: cypress-io/github-action@v5

When using cypress-io/github-action@v5 from your workflow file, you automatically will be using the latest tagged version from this repository.

Ignore for the moment you are calling a quite old version of Cypress' action.

Create your common action

You can do a similar thing on your domain - set up a repo on your Github account just for the common action, say my-github-account/cypress-test-action.

In that repo create action.yml file and put inside the code you currently have in main.yml (shown in the question).

The only thing that you should change from above main.yml is to remove the on: section since you will only ever call it directly from the other repos, never on pull_request or push in the new repo.

Calling common action

Then in each of the three repos listed above, the main.yml will have just one job and step that calls cypress-test-action.

These repos will have the on: section as per old main.yml, and only one job and one step to kick-off the common action.

// main.yml

name: Cypress Automation Tests
on:
  pull_request:
    types: [opened, synchronize, reopened]
  push:
    branches: [main]
jobs:
  tests:
    runs-on: ubuntu-22.04
    steps:
      - name: Cypress run
        uses: my-github-account/cypress-test-action

Upvotes: 1

Related Questions