Skip to content

Commit

Permalink
Login before tests (#5196)
Browse files Browse the repository at this point in the history
* Login before tests

* Changeset

* Composite actions

* Composite actions

* Apply in other workflows

* Apply in other workflows

* Don't run export tests on PRs (#5206)

* Revert Don't run export tests on PRs (#5206) (#5208)

This reverts commit 3ec3cf3.

* Apply in other workflows

* Apply in other workflows

* Apply in other workflows

* Apply in other workflows

* Apply in other workflows

* Apply in other workflows

---------

Co-authored-by: Wojciech Mista <wojciech.mista@hotmail.com>
  • Loading branch information
andrzejewsky and Cloud11PL committed Oct 15, 2024
1 parent 9e5b54a commit 182ba9e
Show file tree
Hide file tree
Showing 49 changed files with 562 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-impalas-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Now we login accounts before playwright jobs are being started. This means playwright shards only consume account files, skipping the authentication part, it avoids account suspending by the API due to multiple attempnts in the same time
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off"
},
"ignorePatterns": ["node_modules/", "**/types/**/*", "type-policies.ts"]
"ignorePatterns": ["node_modules/", "**/types/**/*", "type-policies.ts", "playwright/auth.js"]
}
48 changes: 48 additions & 0 deletions .github/actions/prepare-accounts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Prepare accounts
description: Prepare accounts that are used by Playwright
inputs:
BASE_URL:
description: "Dashboard base url"
required: true
API_URL:
description: "API url"
required: true
E2E_USER_NAME:
description: "Username for e2e tests"
required: true
E2E_USER_PASSWORD:
description: "Password for e2e tests"
required: true
E2E_PERMISSIONS_USERS_PASSWORD:
description: "Permissions user password for e2e tests"
required: true
E2E_ENCODE_PASS:
description: "Password for encoding credentials"
required: true

outputs:
ACCOUNTS:
description: "Encrypted accounts"
value: ${{ steps.accounts.outputs.ACCOUNTS }}


runs:
using: "composite"
steps:
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"

- name: Prepare accounts
shell: bash
id: accounts
env:
BASE_URL: ${{ inputs.BASE_URL }}
API_URL: ${{ inputs.API_URL }}
E2E_USER_NAME: ${{ inputs.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ inputs.E2E_USER_PASSWORD }}
E2E_ENCODE_PASS: ${{ inputs.E2E_ENCODE_PASS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ inputs.E2E_PERMISSIONS_USERS_PASSWORD }}
run: |
ACCOUNTS=$(node playwright/auth.js login)
echo "ACCOUNTS=${ACCOUNTS}" >> "$GITHUB_OUTPUT"
32 changes: 32 additions & 0 deletions .github/actions/restore-accounts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Restore accounts
description: Restore accounts to be consumed by Playwright
inputs:
ACCOUNTS:
description: "Accounts encrypted string"
required: true
E2E_ENCODE_PASS:
description: "Password for encoding credentials"
required: true
BASE_URL:
description: "Dashboard base url"
required: true
API_URL:
description: "API url"
required: true

runs:
using: "composite"
steps:
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"

- name: Restore accounts
shell: bash
env:
E2E_ENCODE_PASS: ${{ inputs.E2E_ENCODE_PASS }}
ACCOUNTS: ${{ inputs.ACCOUNTS }}
API_URL: ${{ inputs.API_URL }}
BASE_URL: ${{ inputs.BASE_URL }}
run: |
node playwright/auth.js restore "$ACCOUNTS"
18 changes: 16 additions & 2 deletions .github/actions/run-pw-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ inputs:
description: "Playwright retries"
required: true
PROJECT:
description: "Project name form playwright config"
description: "Project name from playwright config"
required: false
default: "e2e"
ACCOUNTS:
description: "Accounts hash"
required: true
E2E_ENCODE_PASS:
description: "Password for encoding credentials"
required: true

runs:
using: "composite"
Expand All @@ -47,6 +53,14 @@ runs:
shell: bash
run: npm ci

- name: Restore accounts
uses: ./.github/actions/restore-accounts
with:
BASE_URL: ${{ inputs.BASE_URL }}
API_URL: ${{ inputs.API_URL }}
ACCOUNTS: ${{ inputs.ACCOUNTS }}
E2E_ENCODE_PASS: ${{ inputs.E2E_ENCODE_PASS }}

- name: Install Playwright Browsers
shell: bash
run: npx playwright install --with-deps
Expand Down Expand Up @@ -82,4 +96,4 @@ runs:
with:
name: all-blob-reports
path: blob-report
retention-days: 1
retention-days: 1
18 changes: 17 additions & 1 deletion .github/workflows/pr-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ jobs:
deploy-dashboard:
if: github.event.pull_request.head.repo.full_name == 'saleor/saleor-dashboard'
outputs:
ACCOUNTS: ${{ steps.accounts.outputs.ACCOUNTS }}
runs-on: ubuntu-22.04
needs: initialize-cloud
permissions:
Expand Down Expand Up @@ -151,6 +153,17 @@ jobs:
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env: ${{ needs.initialize-cloud.outputs.POOL_NAME }}

- name: Prepare accounts
id: accounts
uses: ./.github/actions/prepare-accounts
with:
BASE_URL: ${{ needs.initialize-cloud.outputs.BASE_URL }}
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}

run-tests:
if: ${{ contains(github.event.pull_request.labels.*.name, 'run pw-e2e') }}
runs-on: ubuntu-22.04
Expand All @@ -159,6 +172,7 @@ jobs:
fail-fast: false
matrix:
shard: ${{ fromJson(needs.initialize-cloud.outputs.SHARD_MATRIX) }}

steps:
- uses: actions/checkout@v4

Expand All @@ -174,6 +188,8 @@ jobs:
MAILPITURL: ${{ secrets.MAILPITURL }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
PW_RETRIES: ${{ vars.PW_RETRIES }}
ACCOUNTS: ${{ needs.deploy-dashboard.outputs.ACCOUNTS }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}

merge-reports:
if: "!cancelled() && contains(github.event.pull_request.labels.*.name, 'run pw-e2e')"
Expand All @@ -184,4 +200,4 @@ jobs:
- uses: actions/checkout@v4

- name: Merge playwright reports
uses: ./.github/actions/merge-pw-reports
uses: ./.github/actions/merge-pw-reports
13 changes: 13 additions & 0 deletions .github/workflows/run-test-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}
BACKUP_VER: ${{ steps.cloud_variables.outputs.BACKUP_VER }}
BACKUP_NAME: ${{ steps.cloud_variables.outputs.BACKUP_NAME }}
ACCOUNTS: ${{ steps.accounts.outputs.ACCOUNTS }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -44,6 +45,17 @@ jobs:
POOL_INSTANCE: ${{ steps.cloud_variables.outputs.POOL_INSTANCE }}
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}

- name: Prepare accounts
id: accounts
uses: ./.github/actions/prepare-accounts
with:
BASE_URL: ${{ needs.cloud_variables.outputs.BASE_URL }}
API_URL: ${{ needs.cloud_variables.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}

create-run-on-testmo:
runs-on: ubuntu-22.04
needs: initialize-cloud
Expand Down Expand Up @@ -76,6 +88,7 @@ jobs:
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
ACCOUNTS: ${{ needs.initialize-cloud.outputs.ACCOUNTS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
MAILPITURL: ${{ secrets.MAILPITURL }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/run-test-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}
BACKUP_VER: ${{ steps.cloud_variables.outputs.BACKUP_VER }}
BACKUP_NAME: ${{ steps.cloud_variables.outputs.BACKUP_NAME }}
ACCOUNTS: ${{ steps.accounts.outputs.ACCOUNTS }}
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -51,6 +52,18 @@ jobs:
POOL_INSTANCE: ${{ steps.cloud_variables.outputs.POOL_INSTANCE }}
BACKUP_ID: ${{ steps.cloud_variables.outputs.BACKUP_ID }}

- name: Prepare accounts
id: accounts
uses: ./.github/actions/prepare-accounts
with:
BASE_URL: ${{ steps.cloud_variables.outputs.BASE_URL }}
API_URL: ${{ steps.cloud_variables.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}


create-run-on-testmo:
runs-on: ubuntu-22.04
needs: initialize-cloud
Expand Down Expand Up @@ -84,6 +97,7 @@ jobs:
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
ACCOUNTS: ${{ needs.initialize-cloud.outputs.ACCOUNTS }}
MAILPITURL: ${{ secrets.MAILPITURL }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
PW_RETRIES: ${{ vars.PW_RETRIES }}
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/run-tests-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
CHECK_ID: ${{ steps.create-check.outputs.CHECK_ID }}
FRAMEWORK: ${{ steps.check-framework.outputs.result }}
IS_OLD_VERSION: ${{ steps.get-environment-variables.outputs.IS_OLD_VERSION }}
ACCOUNTS: ${{ steps.accounts.outputs.ACCOUNTS }}
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -127,6 +128,17 @@ jobs:
--repo_token "$REPO_TOKEN" \
--project "$PROJECT"
- name: Prepare accounts
id: accounts
uses: ./.github/actions/prepare-accounts
with:
BASE_URL: ${{ steps.cloud_variables.outputs.BASE_URL }}
API_URL: ${{ steps.cloud_variables.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}

run-cy-tests:
if: needs.add-check-and-prepare-instance.outputs.FRAMEWORK == '"cypress"'
needs: add-check-and-prepare-instance
Expand Down Expand Up @@ -211,6 +223,7 @@ jobs:
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
ACCOUNTS: ${{ needs.add-check-and-prepare-instance.outputs.ACCOUNTS }}
MAILPITURL: ${{ secrets.MAILPITURL }}
URL_TO_RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
Expand Down
Loading

0 comments on commit 182ba9e

Please sign in to comment.