run-playwright-tests #323
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: Run Playwright Tests | |
on: | |
repository_dispatch: | |
types: [run-playwright-tests] | |
jobs: | |
run-playwright-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run Playwright Tests | |
id: trigger-tests | |
env: | |
REPO_OWNER: ${{ github.repository_owner }} | |
REPO_NAME: ${{ github.event.client_payload.repository_name }} | |
run: | | |
response=$(curl -s -w "\n%{http_code}" -X POST "https://webhook.ranger.net/api/v1/tests/run" \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer ${{ secrets.RANGER_API_TOKEN }}" \ | |
-d '{ | |
"targetUrl": "https://front-qa.dust.tt/", | |
"ghOwner": "'$REPO_OWNER'", | |
"ghRepo": "'$REPO_NAME'", | |
"ghCommitSha": "${{ github.event.client_payload.sha }}" | |
}') | |
echo "$response" | |
http_code=$(echo "$response" | tail -n1) | |
body=$(echo "$response" | sed '$d') | |
if [ "$http_code" != "202" ]; then | |
error=$(echo "$body" | jq -r '.error // "Unknown error"') | |
echo "Error: $error" | |
exit 1 | |
fi | |
check_id=$(echo "$body" | jq -r '.data.checkId') | |
echo "Check ID: $check_id" | |
echo "CHECK_ID=$check_id" >> $GITHUB_ENV | |
- name: Wait for Playwright Tests To Complete | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
end_time=$((SECONDS + 2700)) # 45 minutes = 2700 seconds | |
while [ $SECONDS -lt $end_time ]; do | |
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/repos/${{ github.repository }}/check-runs/${CHECK_ID}") | |
status=$(echo "$response" | jq -r .status) | |
if [ "$status" = "completed" ]; then | |
conclusion=$(echo "$response" | jq -r .conclusion) | |
echo "Playwright tests completed with conclusion: $conclusion" | |
output=$(echo "$response" | jq -r .output) | |
title=$(echo "$output" | jq -r .title) | |
summary=$(echo "$output" | jq -r .summary) | |
echo "Title: $title" | |
echo "Summary: $summary" | |
if [ "$conclusion" != "success" ]; then | |
exit 1 | |
fi | |
exit 0 | |
fi | |
echo "Tests still running. Waiting 30 seconds before next check..." | |
sleep 30 | |
done | |
echo "Timeout: Playwright tests did not complete within 45 minutes" | |
exit 1 | |
- name: Post Failure Message to Slack | |
id: slack-notification | |
if: failure() | |
uses: slackapi/[email protected] | |
with: | |
payload: | | |
{ | |
"text": "⚠️ Playwright tests failed! Commit: ${{ github.event.client_payload.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "plain_text", | |
"text": "⚠️ Playwright tests failed! Commit: ${{ github.event.client_payload.sha }} | PR merged by @${{ github.event.pull_request.user.login }} into main. Title: ${{ github.event.pull_request.title }} | Check ID: ${{ env.CHECK_ID }}", | |
"emoji": true | |
}, | |
"accessory": { | |
"type": "button", | |
"text": { | |
"type": "plain_text", | |
"text": "View Report" | |
}, | |
"url": "$PLAYWRIGHT_REPORT_URL" | |
} | |
} | |
] | |
} | |
env: | |
PLAYWRIGHT_REPORT_URL: ${{ secrets.PLAYWRIGHT_REPORT_BASE_URL }}/${{ env.CHECK_ID }}/playwright-report/index.html | |
SLACK_WEBHOOK_URL: ${{ secrets.PLAYWRIGHT_TESTS_SLACK_WEBHOOK_URL }} |