Skip to content

Commit

Permalink
Merge branch 'main' into merx-57-manual-transaction-refund
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch authored Apr 5, 2024
2 parents b092462 + 5f1ac2a commit 0d1899d
Show file tree
Hide file tree
Showing 14 changed files with 386 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-mirrors-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Add results to testmo, add notification on slack after tests run
4 changes: 4 additions & 0 deletions .github/actions/run-pw-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ inputs:
MAILPITURL:
description: "mailpit uri"
required: true
URL_TO_RUN:
description: "Url which will be passed to testmo where can be found artifacts of the run"
required: false

runs:
using: "composite"
Expand All @@ -48,6 +51,7 @@ runs:
E2E_PERMISSIONS_USERS_PASSWORD: ${{ inputs.E2E_PERMISSIONS_USERS_PASSWORD }}
SHARD_NUMBER: ${{ inputs.SHARD }}
MAILPITURL: ${{ inputs.MAILPITURL }}
URL_TO_RUN: ${{ inputs.URL_TO_RUN }}
run: npm run qa:pw-e2e -- --shard "$SHARD_NUMBER"

- name: Upload blob report to GitHub Actions Artifacts
Expand Down
7 changes: 6 additions & 1 deletion .github/actions/testmo/testmo-init/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
testmoToken:
description: "Testmo token"
required: true
testmoRunName:
description: "Displayed name in testmo"
required: true

outputs:
testmo-run-id:
description: "Testmo run id"
Expand All @@ -29,10 +33,11 @@ runs:
ID=$(npx testmo automation:run:create \
--instance "$TESTMO_URL" \
--project-id 1 \
--name "Deployment tests" \
--name "$RUN_NAME" \
--source frontend-e2e-tests)
echo "TESTMO_RUN_ID=$ID" >> $GITHUB_OUTPUT
env:
TESTMO_URL: ${{ inputs.testmoUrl }}
TESTMO_TOKEN: ${{ inputs.testmoToken }}
RUN_NAME: ${{inputs.testmoRunName}}
id: run-tests
57 changes: 57 additions & 0 deletions .github/actions/testmo/testmo-threads-submit-playwright/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: submit-run-results-to-testmo
description: "Sends tests results from run to testmo"
inputs:
testmoUrl:
description: "Testmo project URL"
required: true
testmoToken:
description: "Testmo token"
required: true
testmoRunId:
description: "Parallelized job Testmo run id"
required: true
runs:
using: composite
steps:
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: npm
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-qa-${{ env.cache-name }}-
${{ runner.os }}-qa-
${{ runner.os }}-
- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
shell: bash
run: NODE_OPTIONS=--max_old_space_size=4096 npm install

- name: Install dependencies
if: ${{ ! cancelled() }}
working-directory: .github/workflows
shell: bash
run: npm ci

- name: Submit results
working-directory: .github/workflows
shell: bash
run: |
npx testmo automation:run:submit-thread \
--instance "$TESTMO_URL" \
--run-id "$TESTMO_RUN_ID" \
--results ../../testmo/testmo.xml
env:
TESTMO_URL: ${{ inputs.testmoUrl }}
TESTMO_TOKEN: ${{ inputs.testmoToken }}
TESTMO_RUN_ID: ${{ inputs.testmoRunId}}



118 changes: 118 additions & 0 deletions .github/workflows/postTestsResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const { Command } = require("commander");
const program = new Command();
const { Octokit } = require("@octokit/core");

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}`;
const threads = results.result.threads;

if (Array.isArray(threads)) {
const failureCount = threads
.map(thread => thread.failure_count)
.reduce((accumulator, currentValue) => accumulator + currentValue, 0);

const successCount = threads
.map(thread => thread.success_count)
.reduce((accumulator, currentValue) => accumulator + currentValue, 0);

const skippedCount = threads
.map(thread => thread.total_count - thread.completed_count)
.reduce((accumulator, currentValue) => accumulator + currentValue, 0);

if (failureCount > 0) {
message += `${failureCount} tests failed. `;
}
if (successCount > 0) {
message += `${successCount} tests passed. `;
}
if (skippedCount > 0) {
message += `${skippedCount} tests skipped. `;
}
} else {
status = "FAILURE";
message = "Empty test run. ";
}

message += `See results at ${linkToResults}`;

return {
status,
message,
title: `Playwright 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" },
});
}
2 changes: 1 addition & 1 deletion .github/workflows/pr-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ jobs:
- uses: actions/checkout@v4

- name: Merge playwright reports
uses: ./.github/actions/merge-pw-reports
uses: ./.github/actions/merge-pw-reports
57 changes: 54 additions & 3 deletions .github/workflows/run-test-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,23 @@ jobs:
POOL_INSTANCE: ${{ steps.cloud_variables.outputs.POOL_INSTANCE }}
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}

run-tests:
create-run-on-testmo:
runs-on: ubuntu-22.04
needs: initialize-cloud
outputs:
testmo-run-id: ${{ steps.init-testmo.outputs.testmo-run-id }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/testmo/testmo-init
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunName: "Playwright nightly run"
id: init-testmo

run-tests:
runs-on: ubuntu-22.04
needs: ["initialize-cloud", "create-run-on-testmo"]
strategy:
fail-fast: false
matrix:
Expand All @@ -64,13 +78,50 @@ jobs:
E2E_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.CYPRESS_MAILPITURL }}
URL_TO_RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

- name: submit-results-to-testmo
if: always()
uses: ./.github/actions/testmo/testmo-threads-submit-playwright
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunId: ${{ needs.create-run-on-testmo.outputs.testmo-run-id }}

merge-reports:
tests-complete:
if: '!cancelled()'
needs: run-tests
needs: ["initialize-cloud", "run-tests", "create-run-on-testmo"]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Merge playwright reports
uses: ./.github/actions/merge-pw-reports

- name: complete testmo report
uses: ./.github/actions/testmo/testmo-finish
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunId: ${{ needs.create-run-on-testmo.outputs.testmo-run-id }}

- name: send message on slack
working-directory: ".github"
env:
run_id: ${{ needs.create-run-on-testmo.outputs.testmo-run-id }}
url_to_action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
testmo_token: ${{ secrets.TESTMO_TOKEN }}
environment: ${{ needs.initialize-cloud.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"
55 changes: 52 additions & 3 deletions .github/workflows/run-test-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,23 @@ jobs:
POOL_INSTANCE: ${{ steps.cloud_variables.outputs.POOL_INSTANCE }}
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}

run-tests:
create-run-on-testmo:
runs-on: ubuntu-22.04
needs: initialize-cloud
outputs:
testmo-run-id: ${{ steps.init-testmo.outputs.testmo-run-id }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/testmo/testmo-init
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunName: "Playwright run ${{github.ref_name}}"
id: init-testmo

run-tests:
runs-on: ubuntu-22.04
needs: ["initialize-cloud", "create-run-on-testmo"]
strategy:
fail-fast: false
matrix:
Expand All @@ -71,13 +85,48 @@ jobs:
E2E_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.CYPRESS_MAILPITURL }}
URL_TO_RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

merge-reports:
- name: submit-results-to-testmo
if: always()
uses: ./.github/actions/testmo/testmo-threads-submit-playwright
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunId: ${{ needs.create-run-on-testmo.outputs.testmo-run-id }}

tests-complete:
if: '!cancelled()'
needs: run-tests
needs: ["initialize-cloud", "run-tests", "create-run-on-testmo"]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Merge playwright reports
uses: ./.github/actions/merge-pw-reports

- name: complete testmo report
uses: ./.github/actions/testmo/testmo-finish
with:
testmoUrl: ${{ secrets.TESTMO_URL }}
testmoToken: ${{ secrets.TESTMO_TOKEN }}
testmoRunId: ${{ needs.create-run-on-testmo.outputs.testmo-run-id }}

- name: send message on slack
working-directory: ".github"
env:
run_id: ${{ needs.create-run-on-testmo.outputs.testmo-run-id }}
url_to_action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
testmo_token: ${{ secrets.TESTMO_TOKEN }}
environment: ${{ needs.initialize-cloud.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"
Loading

0 comments on commit 0d1899d

Please sign in to comment.