-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Run cypress manual with testmo and slack * Run cypress manual with testmo and slack * Run cypress manual with testmo and slack * Run cypress manual with testmo and slack * post tests results even if some tests fail * Add cypress tests manual * Add changeset * Remove on push trigger * Fix workflow name * Remove info about number of failed/passed tests
- Loading branch information
Showing
5 changed files
with
248 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
Add manual workflow for cypress tests |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const { Command } = require("commander"); | ||
const program = new Command(); | ||
|
||
program | ||
.name("Send tests results") | ||
.description( | ||
"Get tests results from testmo and post message to slack or on release PR", | ||
) | ||
.option("--run_id <run_id>", "Testmo run id") | ||
.option( | ||
"--testmo_token <testmo_token>", | ||
"Bearer token for authorization in testmo", | ||
) | ||
.option( | ||
"--slack_webhook_url <slack_webhook_url>", | ||
"Should send notification on slack", | ||
) | ||
.option("--environment <environment>", "Environment") | ||
.option("--url_to_action <url_to_action>", "Url to enter github action") | ||
.option("--ref_name <ref_name>", "Ref to point where tests where run") | ||
.action(async options => { | ||
const runId = options.run_id; | ||
const testmoAuthToken = options.testmo_token; | ||
const testsResults = await getTestsStatus(runId, testmoAuthToken); | ||
const testsStatus = convertResults( | ||
testsResults, | ||
options.environment, | ||
options.ref_name, | ||
); | ||
|
||
await sendMessageOnSlack( | ||
testsStatus, | ||
options.slack_webhook_url, | ||
options.url_to_action, | ||
); | ||
}) | ||
.parse(); | ||
|
||
async function getTestsStatus(runId, testmoToken) { | ||
const runResult = await fetch( | ||
`https://saleor.testmo.net/api/v1/automation/runs/${runId}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${testmoToken}`, | ||
}, | ||
}, | ||
); | ||
return await runResult.json(); | ||
} | ||
|
||
function convertResults(results, environment, refName) { | ||
let status = results?.result?.status === 2 ? "SUCCESS" : "FAILURE"; | ||
let message = `Tests run on environment: \n${environment}\n`; | ||
const linkToResults = `https:\/\/saleor.testmo.net\/automation\/runs\/view\/${results.result.id}`; | ||
|
||
message += `See results at ${linkToResults}`; | ||
|
||
return { | ||
status, | ||
message, | ||
title: `Tests run on ${refName}`, | ||
linkToResults, | ||
}; | ||
} | ||
|
||
async function sendMessageOnSlack(testsStatus, webhookUrl, urlToAction) { | ||
const JOB_STATUS_COLOR_MAP = { | ||
SUCCESS: "#5DC292", | ||
FAILURE: "#FE6E76", | ||
}; | ||
|
||
const messageData = { | ||
attachments: [ | ||
{ | ||
fallback: testsStatus.message, | ||
pretext: testsStatus.status, | ||
title: testsStatus.title, | ||
title_link: urlToAction, | ||
text: testsStatus.message, | ||
color: JOB_STATUS_COLOR_MAP[testsStatus.status], | ||
}, | ||
], | ||
}; | ||
await fetch(webhookUrl, { | ||
body: JSON.stringify(messageData), | ||
method: "post", | ||
headers: { "content-type": "application/json" }, | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
name: Run test manually | ||
run-name: Run cypress tests | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tags: | ||
required: true | ||
description: "Select tests to run" | ||
default: "@allEnv" | ||
type: choice | ||
options: | ||
- "@allEnv" | ||
- "@critical" | ||
- "@stable" | ||
- "@oldRelease" | ||
browser: | ||
required: true | ||
description: "Browser" | ||
default: "electron" | ||
type: choice | ||
options: | ||
- electron | ||
- firefox | ||
- all | ||
jobs: | ||
|
||
testmo-report-preparation: | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
TESTMO_RUN_ID: ${{ steps.init-testmo.outputs.testmo-run-id }} | ||
BASE_URL: ${{ steps.set_variables.outputs.BASE_URL }} | ||
API_URL: ${{ steps.set_variables.outputs.API_URL }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set variables | ||
id: set_variables | ||
run: | | ||
CURRENT_BRANCH=$(echo "${GITHUB_REF}" | sed "s/refs\/heads\///") | ||
VERSION_SLUG=$(echo "${CURRENT_BRANCH}" | sed "s/\.//") | ||
echo "BASE_URL=https://v${VERSION_SLUG}.staging.saleor.cloud/dashboard/" >> $GITHUB_OUTPUT | ||
echo "API_URL=https://v${VERSION_SLUG}.staging.saleor.cloud/graphql/" >> $GITHUB_OUTPUT | ||
- uses: ./.github/actions/testmo/testmo-init | ||
with: | ||
testmoUrl: ${{ secrets.TESTMO_URL }} | ||
testmoToken: ${{ secrets.TESTMO_TOKEN }} | ||
testmoRunName: "Cypress run ${{ github.ref_name }}" | ||
id: init-testmo | ||
|
||
run-tests-in-parallel: | ||
needs: testmo-report-preparation | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: cypress/browsers:node18.12.0-chrome106-ff106 | ||
options: --user 1001 | ||
env: | ||
GREP_TAGS: ${{ github.event.inputs.tags || '@critical'}} | ||
BROWSER: ${{ inputs.browser || 'electron' }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
containers: [1, 2, 3, 4, 5, 6] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
|
||
- name: Cypress run | ||
id: cypress-run | ||
uses: ./.github/actions/e2e | ||
continue-on-error: true | ||
with: | ||
apiUrl: ${{ needs.testmo-report-preparation.outputs.API_URL}} | ||
appMountUri: ${{ secrets.APP_MOUNT_URI }} | ||
baseUrl: ${{ needs.testmo-report-preparation.outputs.BASE_URL}} | ||
userName: ${{ secrets.CYPRESS_USER_NAME }} | ||
secondUserName: ${{ secrets.CYPRESS_SECOND_USER_NAME }} | ||
userPassword: ${{ secrets.CYPRESS_USER_PASSWORD }} | ||
permissionsUserPassword: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }} | ||
mailpitUrl: ${{ secrets.CYPRESS_MAILPITURL }} | ||
stripeSecretKey: ${{ secrets.STRIPE_SECRET_KEY }} | ||
stripePublicKey: ${{ secrets.STRIPE_PUBLIC_KEY }} | ||
cypressGrepTags: ${{ env.GREP_TAGS }} | ||
split: ${{ strategy.job-total }} | ||
splitIndex: ${{ strategy.job-index }} | ||
commitInfoMessage: All tests triggered via ${{ github.event_name}} on ${{ steps.get-env-uri.outputs.ENV_URI }} | ||
install: false | ||
browser: ${{ env.BROWSER }} | ||
|
||
- name: Testmo threads submit | ||
uses: ./.github/actions/testmo/testmo-threads-submit | ||
with: | ||
testmoUrl: ${{ secrets.TESTMO_URL }} | ||
testmoToken: ${{ secrets.TESTMO_TOKEN }} | ||
testmoRunId: ${{ needs.testmo-report-preparation.outputs.TESTMO_RUN_ID }} | ||
|
||
|
||
post-tests-results: | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: .github/workflows | ||
runs-on: ubuntu-22.04 | ||
needs: [run-tests-in-parallel, testmo-report-preparation] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: ".nvmrc" | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- uses: ./.github/actions/combineReportsFromE2E | ||
|
||
- name: complete testmo report | ||
uses: ./.github/actions/testmo/testmo-finish | ||
with: | ||
testmoUrl: ${{ secrets.TESTMO_URL }} | ||
testmoToken: ${{ secrets.TESTMO_TOKEN }} | ||
testmoRunId: ${{ needs.testmo-report-preparation.outputs.TESTMO_RUN_ID }} | ||
|
||
- name: send message on slack | ||
working-directory: ".github" | ||
env: | ||
run_id: ${{ needs.testmo-report-preparation.outputs.TESTMO_RUN_ID }} | ||
url_to_action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
testmo_token: ${{ secrets.TESTMO_TOKEN }} | ||
environment: ${{ needs.testmo-report-preparation.outputs.BASE_URL }} | ||
slack_webhook_url: ${{ secrets.SLACK_QA_STATUSES_WEBHOOK_URL }} | ||
ref_name: ${{github.ref_name}} | ||
|
||
run: | | ||
node workflows/postTestsResults.js \ | ||
--run_id "$run_id" \ | ||
--testmo_token "$testmo_token" \ | ||
--slack_webhook_url "$slack_webhook_url" \ | ||
--environment "$environment" \ | ||
--url_to_action "$url_to_action" \ | ||
--ref_name "$ref_name" |