I’d like to implement a conditional E2E test that needs to pass before a release is executed in production.
Currently our workflow is as follows:
- A user commits a change to a branch
- A PR is created, tested, merged to master.
- A release is queued to staging automatically
- A Cypress E2E test is executed, to test the results in staging.
- The user manually releases to production.
Between steps 4 and 5, I’d like a quality gate established where if 4 fails, the user cannot run 5.
How can I achieve this?
Heres the current pipeline with a few remitted lines of cicd.
name: CI
on:
pull_request:
types:
- opened
- reopened
- synchronize
push:
branches:
- master
permissions:
checks: write
pull-requests: write
contents: write
actions: write
env:
NODE_AUTH_TOKEN: ${{secrets.remitted}}
defaults:
run:
working-directory: ./vendor
jobs:
install:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: remitted@master
build:
needs: [install]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: remitted/pnpm@master
- name: Build and then install necessary packages
run: npm run build:uikit:production
- name: Build webpack
run: NODE_ENV=development npm run build:webpack
unit_test:
needs: [install]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create env file
run: |
- uses: remitted/pnpm@master
- name: Test Unit
run: npm run test:ci:coverage
lint:
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
needs: [install]
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: remitted/pnpm@master
- name: Lint
run: npm run lint
deploy_ecs:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
needs: [build, unit_test, lint]
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Trigger Deploy ECS
run: gh workflow run deploy_ecs.yml --ref master
Inside deploy_ecs.yml, the deployment occurs, and the E2E is triggered like so:
trigger_e2e:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Trigger E2E
run: gh workflow run cypress.yml --ref master
Below is the workflow that allows a user to manually release.
name: Release ECS
on:
workflow_dispatch:
jobs:
2
Answers
Supposing a "release to production" means merging the staging branch into the production branch, you can make that workflow automatically open a PR (e.g. with the existienter link description here) and then set a branch protection rule on the production branch that requires the E2E tests to pass before it can be merged. Then can even enable automerge on the PR, so that if the tests pass it is automatically merged (see here)
To still allow manual triggering of the workflow but also automatically run your
Release ECS
workflow againstmaster
when thetrigger_e2e
workflow has been reported successful, you could use a solution like this:The above code assumes that you want to automically do a release when someone is running the cypress e2e test through the
trigger_e2e
.If you want to always enforce the e2e tests to run, or all the other workflows, you should be able to remove the check for
github.event_name == 'workflow_dispatch'
.There is another way to read your question. At least from the question in the title, it sounds like you want to ensure the e2e tests run successfully when someone triggers the Release workflow manually. In this case, you could try something like this:
Relevant docs:
Please let me know if this helps 🙂