Check production data #146
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check production data | |
on: deployment_status | |
jobs: | |
CheckProdData: | |
# only runs this job on successful deploy and only for master | |
if: ${{ github.event.deployment_status.state == 'success' && github.event.deployment_status.environment == 'Production' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set commit in progress status | |
run: | | |
curl --request POST \ | |
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \ | |
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | |
--header 'content-type: application/json' \ | |
--data '{ | |
"context": "CheckProdData", | |
"state": "pending", | |
"description": "Testing in progress…", | |
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
}' | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Run Cypress | |
id: cypress | |
uses: cypress-io/github-action@v4 | |
with: | |
spec: cypress/e2e/prod.cy.js | |
env: | |
CYPRESS_BASE_URL: ${{ github.event.deployment_status.target_url }} | |
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#job-status-check-functions | |
- name: Set commit final status | |
if: always() | |
# set the merge commit status check using GitHub REST API see https://docs.github.com/en/rest/reference/repos#create-a-commit-status | |
run: | | |
curl --request POST \ | |
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \ | |
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | |
--header 'content-type: application/json' \ | |
--data '{ | |
"context": "CheckProdData", | |
"state": "${{ steps.cypress.outcome }}", | |
"description": "Tests finished: ${{ steps.cypress.outcome }}", | |
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
}' |