Skip to content

Commit

Permalink
Refactor workflows to use reusable Cypress workflow (#1070)
Browse files Browse the repository at this point in the history
* Refactor workflows to use reusable Cypress workflow

* Update cypress.yml
  • Loading branch information
cshnimble authored May 31, 2024
1 parent 3428b6a commit c3fdb9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 57 deletions.
60 changes: 5 additions & 55 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,58 +89,8 @@ jobs:
name: Run Cypress Tests
if: needs.set-env.outputs.environment == 'staging' || needs.set-env.outputs.environment == 'dev'
needs: [ deploy-image, set-env ]
runs-on: ubuntu-22.04
environment: ${{ needs.set-env.outputs.environment }}
defaults:
run:
working-directory: Dfe.PrepareConversions/Dfe.PrepareConversions.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 (staging)
if: needs.set-env.outputs.environment == 'staging'
run: npm run cy:run -- --env url='${{ secrets.AZURE_ENDPOINT }}',grep='-dao',cypressTestSecret='${{ secrets.CYPRESS_TEST_SECRET }}, academisationApiUrl=${{secrets.CYPRESS_ACADEMISATION_API_URL}}, academisationApiKey=${{ secrets.CYPRESS_ACADEMISATION_API_KEY}}'
env:
db: ${{ secrets.DB_CONNECTION_STRING }}

- name: Run cypress (dev)
if: needs.set-env.outputs.environment == 'dev'
run: npm run cy:run -- --env url='${{ secrets.AZURE_ENDPOINT }}',cypressTestSecret='${{ secrets.CYPRESS_TEST_SECRET }}, academisationApiUrl=${{secrets.CYPRESS_ACADEMISATION_API_URL}}, academisationApiKey=${{ secrets.CYPRESS_ACADEMISATION_API_KEY}}'
env:
db: ${{ secrets.DB_CONNECTION_STRING }}

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

- name: Generate report
if: always()
run: |
mkdir mochareports
npm run generate:html:report
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: reports-${{ needs.set-env.outputs.environment }}
path: Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/mochareports

- name: Report results
if: always()
run: npm run cy:notify -- --custom-text="Environment ${{ needs.set-env.outputs.environment }}, See more information https://github.com/DFE-Digital/prepare-academy-conversions/actions/runs/${{github.run_id}}"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
runs-on: ubuntu-latest
uses: ./.github/workflows/cypress.yml
with:
environment: ${{ needs.set-env.outputs.environment }}
secrets: inherit
34 changes: 32 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
name: Run Cypress Accessibility checks
name: Run Cypress tests

on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
AZURE_ENDPOINT:
required: true
CYPRESS_TEST_SECRET:
required: true
CYPRESS_ACADEMISATION_API_URL:
required: true
CYPRESS_ACADEMISATION_API_KEY:
required: true
DB_CONNECTION_STRING:
required: true
SLACK_WEBHOOK_URL:
required: true
workflow_dispatch:
inputs:
environment:
description: 'Environment to run tests against'
required: true
type: environment

concurrency:
group: ${{ github.workflow }}
Expand All @@ -13,7 +36,7 @@ jobs:
cypress-tests:
name: Run Cypress Tests
runs-on: ubuntu-latest
environment: dev
environment: ${{ inputs.environment }}
defaults:
run:
working-directory: Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests
Expand All @@ -31,10 +54,17 @@ jobs:
run: npm install

- name: Run cypress (dev)
if: inputs.environment == 'dev'
run: npm run cy:run -- --env url='${{ secrets.AZURE_ENDPOINT }}',cypressTestSecret='${{ secrets.CYPRESS_TEST_SECRET }}, academisationApiUrl=${{secrets.CYPRESS_ACADEMISATION_API_URL}}, academisationApiKey=${{ secrets.CYPRESS_ACADEMISATION_API_KEY}}'
env:
db: ${{ secrets.DB_CONNECTION_STRING }}

- name: Run cypress (staging)
if: inputs.environment == 'staging'
run: npm run cy:run -- --env url='${{ secrets.AZURE_ENDPOINT }}',grep='-dao',cypressTestSecret='${{ secrets.CYPRESS_TEST_SECRET }}, academisationApiUrl=${{secrets.CYPRESS_ACADEMISATION_API_URL}}, academisationApiKey=${{ secrets.CYPRESS_ACADEMISATION_API_KEY}}'
env:
db: ${{ secrets.DB_CONNECTION_STRING }}

- name: Upload screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v4
Expand Down

0 comments on commit c3fdb9c

Please sign in to comment.