Skip to content

Commit

Permalink
Merge branch 'main' into remove-plugins-legacy-message
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch committed Apr 10, 2024
2 parents f4cb34b + e2e5c71 commit 6391db3
Show file tree
Hide file tree
Showing 83 changed files with 2,089 additions and 520 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
5 changes: 5 additions & 0 deletions .changeset/neat-shoes-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Add playwright tests for edit and remove product types
5 changes: 5 additions & 0 deletions .changeset/nice-pets-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Introduce view for manual refund transaction
5 changes: 5 additions & 0 deletions .changeset/olive-games-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Fixing assertions in flaky Playwright tests
5 changes: 5 additions & 0 deletions .changeset/shy-jars-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Show all transaction in manual refund view, disabled those that are not refundable
11 changes: 11 additions & 0 deletions .changeset/sixty-colts-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"saleor-dashboard": minor
---

# Optimizing playwright setup and playwright.config.ts files

-Adding a conditioning to auth.setup.ts file to use existing auth json file if it's applicable
-Added some optimizations to playwright config file
-Cleaned up gh action for playwright tests (removed Cypress references)
-Updating gh workflow for PR automation with extra test sharding
-General cleanup of redundant code
14 changes: 13 additions & 1 deletion .github/actions/run-pw-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ 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
PW_WORKERS:
description: "Playwright workers"
required: true
PW_RETRIES:
description: "Playwright retries"
required: true

runs:
using: "composite"
Expand All @@ -47,7 +56,10 @@ runs:
E2E_USER_PASSWORD: ${{ inputs.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ inputs.E2E_PERMISSIONS_USERS_PASSWORD }}
SHARD_NUMBER: ${{ inputs.SHARD }}
MAILPITURL: ${{ inputs.MAILPITURL }}
MAILPITURL: ${{ inputs.MAILPITURL }}
URL_TO_RUN: ${{ inputs.URL_TO_RUN }}
WORKERS: ${{ inputs.PW_WORKERS }}
RETRIES: ${{ inputs.PW_RETRIES }}
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" },
});
}
13 changes: 8 additions & 5 deletions .github/workflows/pr-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ jobs:
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env: ${{ needs.initialize-cloud.outputs.POOL_NAME }}


run-tests:
runs-on: ubuntu-22.04
needs: [initialize-cloud, deploy-dashboard]
strategy:
fail-fast: false
matrix:
shard: [1/2, 2/2]
shard: [1/4, 2/4, 3/4, 4/4]
steps:
- uses: actions/checkout@v4

Expand All @@ -134,10 +135,12 @@ jobs:
SHARD: ${{ matrix.shard }}
BASE_URL: ${{ needs.initialize-cloud.outputs.BASE_URL }}
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.CYPRESS_MAILPITURL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.MAILPITURL }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
PW_RETRIES: ${{ vars.PW_RETRIES }}

merge-reports:
if: "!cancelled()"
Expand Down
67 changes: 60 additions & 7 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 @@ -60,17 +74,56 @@ jobs:
SHARD: ${{ matrix.shard }}
BASE_URL: ${{ needs.initialize-cloud.outputs.BASE_URL }}
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.CYPRESS_MAILPITURL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.MAILPITURL }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
PW_RETRIES: ${{ vars.PW_RETRIES }}
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 6391db3

Please sign in to comment.