juuust_a_bit_outside
juuust_a_bit_outside

Reputation: 11

Cypress test runs before Vercel deployment in Github Actions

I have successfully created a script to test Vercel test deployments using Cypress integrated with Github Actions. Although the test works and the desired result is achieved, there is a slightly annoying issue-- the Cypress test runs (and is skipped) before the Vercel deployment attempt. I am employing a conditional in the GA workflow yml so that the Cypress tests run after successful test deployment, so it ends up running after the deployment. I would like to be able to omit the first skipped attempt at the Cypress test. I have tried incorporating other Github Actions to fix this, but they block the test from being run at all if the deployment is not finished. I have also tried playing with the settings of the repo, to no avail. Below is my GA yml:

name: Cypress Testing
on: [deployment_status]
jobs:
  e2e:
    if: github.event.deployment_status.state == 'success'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup npmrc
        run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_AUTH_TOKEN}}" > .npmrc
      - name: Setup npm package
        run: npm init -y && npm install
      - name: Setup node 12
        uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - name: Run Cypress
        uses: cypress-io/github-action@v2
        env:
          CYPRESS_BASE_URL: ${{ github.event.deployment_status.target_url }}

Our Vercel project is integrated with Git, so it deploys automatically with every push. Has anyone ever had this issue, where Cypress tries to run first before Vercel deployment?

Upvotes: 1

Views: 2219

Answers (1)

Tobi
Tobi

Reputation: 884

What happens in your deploy:

  1. you push changes to your repo
  2. vercel watches your repo, see there is a new commit
  3. it sends the status pending to your repo and builds the stuff on vercel servers. So now your repo knows vercel is doing something and you can see that e.g. in your PR in the ckecks. => with this "Status update" your workflow is automaticaly triggered (but skipped because the condition is false), because the status changed from nothing to "pending"
  4. vercel has finished the deployment and sends another status update to GitHub. => your workflow is triggered again. But this time the if condition in the workflow is true and the rest will be executed.

So it is not possible to avoid the skipped workflow with the deployment_status as a trigger for the workflow.

Upvotes: 1

Related Questions