Cypress Tests #56
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: Cypress Tests | |
'on': | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: '0 0 * * 3' | |
workflow_dispatch: # | |
jobs: | |
setup-and-run-tests: | |
name: Setup the environment and run the tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install dependencies | |
run: npm install | |
- name: Run Cypress tests | |
run: npx cypress run --record --key ${{ secrets.CYPRESS_RECORD_KEY }} | |
- name: Generate test report | |
run: npm run after-test | |
- name: Read report.json and set test results into env variables | |
run: | | |
totalTests=$(jq -r '.stats.tests' ./cypress/reports/report.json) | |
failedTests=$(jq -r '.stats.failures' ./cypress/reports/report.json) | |
passedTests=$(jq -r '.stats.passes' ./cypress/reports/report.json) | |
echo "TOTAL_TESTS=$totalTests" >> $GITHUB_ENV | |
echo "FAILED_TESTS=$failedTests" >> $GITHUB_ENV | |
echo "PASSED_TESTS=$passedTests" >> $GITHUB_ENV | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: Reports | |
path: ./cypress/reports | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: '${{ secrets.GITHUB_TOKEN }}' | |
publish_dir: ./cypress/reports | |
publish_branch: gh-pages | |
commit_message: Update the test report | |
- name: Send Slack Notification with Test Results | |
env: | |
SLACK_WEBHOOK_URL: '${{ secrets.SLACK_WEBHOOK_URL }}' | |
SLACK_CHANNEL: '${{ secrets.SLACK_CHANNEL }}' | |
run: | | |
if [[ ${{ env.FAILED_TESTS }} -gt 0 ]]; then | |
color="#FF0000" | |
else | |
color="#00FF00" | |
fi | |
curl -X POST -H 'Content-type: application/json' --data '{ | |
"channel": "'"${SLACK_CHANNEL}"'", | |
"attachments": [ | |
{ | |
"title": "Test Results", | |
"text": ":page_with_curl: *Total Tests:* ${{ env.TOTAL_TESTS }}\n:white_check_mark: *Passed Tests:* ${{ env.PASSED_TESTS }}\n:x: *Failed Tests:* ${{ env.FAILED_TESTS }}\n\n<https://${{ github.actor }}.github.io/cypress-serverest-demo/report.html|Click here to see the last test run in details>", | |
"color": "'"${color}"'" | |
} | |
] | |
}' "${SLACK_WEBHOOK_URL}" |