Skip to content

Commit

Permalink
Move Cypress tests into reusable workflow (#489)
Browse files Browse the repository at this point in the history
* Move Cypress tests into reusable workflow

* Pass vars to Cypress workflow
  • Loading branch information
cshnimble authored May 30, 2024
1 parent 44a2f83 commit ea08048
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 29 deletions.
36 changes: 7 additions & 29 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,11 @@ jobs:
cypress-tests:
name: Run Cypress Tests
if: needs.set-env.outputs.environment == 'test' || needs.set-env.outputs.environment == 'development'
needs: [ deploy-image, set-env ]
runs-on: ubuntu-latest
environment: ${{ needs.set-env.outputs.environment }}
defaults:
run:
working-directory: CypressTests
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Npm install
run: npm install

- name: Run cypress
run: npm run cy:run -- --env apiKey="${{ secrets.TRAMS_API_KEY }}",url="${{ secrets.TRAMS_API_BASE_URL }}"

- name: Upload screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ needs.set-env.outputs.environment }}
path: screenshots
if: needs.set-env.outputs.environment == 'test' || needs.set-env.outputs.environment == 'development'
uses: ./.github/workflows/cypress-tests.yml
with:
environment: ${{ needs.set-env.outputs.environment }}
secrets:
TRAMS_API_KEY: ${{ secrets.TRAMS_API_KEY }}
TRAMS_API_BASE_URL: ${{ secrets.TRAMS_API_BASE_URL }}
57 changes: 57 additions & 0 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Run Cypress tests

on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
TRAMS_API_KEY:
required: true
TRAMS_API_BASE_URL:
required: true
workflow_dispatch:
inputs:
environment:
description: 'Environment to run tests against'
required: true
type: environment

concurrency:
group: ${{ github.workflow }}

env:
NODE_VERSION: 18.x

jobs:
cypress-tests:
name: Run Cypress Tests
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
defaults:
run:
working-directory: CypressTests/
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Npm install
run: npm install

- name: Run Cypress (${{ inputs.environment }})
if: inputs.environment == 'test' || inputs.environment == 'development'
run: npm run cy:run -- --env apiKey="${{ secrets.TRAMS_API_KEY }}",url="${{ secrets.TRAMS_API_BASE_URL }}"

- name: Upload screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ needs.set-env.outputs.environment }}
path: screenshots

0 comments on commit ea08048

Please sign in to comment.