Skip to content

E2e instance assign and create #65

E2e instance assign and create

E2e instance assign and create #65

Workflow file for this run

name: Testing
on: [pull_request]
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
prepare_variables:
runs-on: ubuntu-22.04
outputs:
POOL_NAME: ${{ steps.generate.outputs.POOL_NAME }}
POOL_INSTANCE: ${{ steps.generate.outputs.POOL_INSTANCE }}
BASE_URL: ${{ steps.generate.outputs.BASE_URL }}
API_URI: ${{ steps.generate.outputs.API_URI }}
BACKUP_ID: ${{ steps.backup.outputs.BACKUP_ID }}
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Generate
id: generate
run: |
echo "BASE_URL=${{ env.GITHUB_HEAD_REF_SLUG_URL }}.dashboard.saleor.rocks" >> $GITHUB_OUTPUT
echo "API_URI=https://${{ env.GITHUB_HEAD_REF_SLUG_URL }}.staging.saleor.cloud/graphql/" >> $GITHUB_OUTPUT
echo "POOL_NAME=${{ env.GITHUB_HEAD_REF_SLUG_URL }}" >> $GITHUB_OUTPUT
echo "POOL_INSTANCE=https://${{ env.GITHUB_HEAD_REF_SLUG_URL }}.staging.saleor.cloud" >> $GITHUB_OUTPUT
- name: Saleor login
uses: ./.github/actions/cli-login
with:
token: ${{ secrets.STAGING_TOKEN }}
- name: Obtain backup id
id: backup
env:
SALEOR_CLI_ENV: staging
BACKUP_NAME: snapshot-automation-tests
run: |
BACKUP_ID=$(npx saleor@1.40.0-rc.1 backup list --name=snapshot-automation-tests --latest --json | jq -r '.[0].key')
echo "BACKUP_ID=$BACKUP_ID" >> $GITHUB_OUTPUT
- name: Print annotations
run: |
echo "::notice title=BASE_URL::${{ steps.generate.outputs.BASE_URL }}"
echo "::notice title=API_URI::${{ steps.generate.outputs.API_URI }}"
echo "::notice title=POOL_NAME::${{ steps.generate.outputs.POOL_NAME }}"
echo "::notice title=POOL_INSTANCE::${{ steps.generate.outputs.POOL_INSTANCE }}"
echo "::notice title=BACKUP_ID::${{ steps.backup.outputs.BACKUP_ID }}"
prepare_instance:
runs-on: ubuntu-22.04
needs: prepare_variables
steps:
- uses: actions/checkout@v4
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Saleor login
uses: ./.github/actions/cli-login
with:
token: ${{ secrets.STAGING_TOKEN }}
- name: Reload snapshot
if: ${{ github.event_name == 'pull_request' && github.event.action != 'opened' && github.event.action != 'closed' }}
env:
SALEOR_CLI_ENV: staging
BACKUP_ID: ${{ needs.prepare_variables.outputs.BACKUP_ID }}
INSTANCE_NAME: ${{ needs.prepare_variables.outputs.POOL_NAME }}
run: |
npx saleor backup restore "${{ env.BACKUP_ID }}" \
--environment="${{ env.INSTANCE_NAME }}" \
--skip-webhooks-update
- name: Create new instance
if: ${{ github.event_name == 'pull_request' && github.event.action == 'opened' }}
env:
SALEOR_CLI_ENV: staging
BACKUP_ID: ${{ needs.prepare_variables.outputs.BACKUP_ID }}
INSTANCE_NAME: ${{ needs.prepare_variables.outputs.POOL_NAME }}
run: |
npx saleor env create "${{ env.INSTANCE_NAME }}" \
--project=project-for-pr-testing \
--database=snapshot \
--restore-from=${{ env.BACKUP_ID }} \
--saleor=saleor-master-staging \
--domain="${{ env.INSTANCE_NAME }}" \
--skip-restrict \
--skip-webhooks-update
deploy_dashboard:
if: github.event.pull_request.head.repo.full_name == 'saleor/saleor-dashboard'
runs-on: ubuntu-22.04
needs: prepare_variables
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- name: Start deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ needs.prepare_variables.outputs.POOL_NAME }}
ref: ${{ github.head_ref }}
- 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 deps
run: npm ci
- name: Build dashbaord
env:
API_URI: ${{ needs.prepare_variables.outputs.API_URI }}
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
APP_MOUNT_URI: /
STATIC_URL: /
IS_CLOUD_INSTANCE: true
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Deploy to S3
run: aws s3 sync ./build/dashboard s3://${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}/${{ needs.prepare_variables.outputs.BASE_URL }}
- name: Invalidate cache
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_TEST_CF_DIST_ID }} --paths "/${{ needs.prepare_variables.outputs.BASE_URL }}/*"
- name: Update deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env_url: https://${{ needs.prepare_variables.outputs.BASE_URL }}/
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env: ${{ needs.prepare_variables.outputs.POOL_NAME }}
deploy_storybook:
if: github.event.pull_request.head.repo.full_name == 'saleor/saleor-dashboard'
runs-on: ubuntu-22.04
needs: prepare_variables
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- name: Start storybook deployment
uses: bobheadxi/deployments@v1
id: storybook-deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: storybook ${{ needs.prepare_variables.outputs.POOL_NAME }}
ref: ${{ github.head_ref }}
- 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 deps
run: npm ci
- name: Build storybook
run: npm run build-storybook
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Deploy to S3
run: aws s3 sync ./build/storybook s3://${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}/${{ needs.prepare_variables.outputs.BASE_URL }}/storybook
- name: Invalidate cache
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_TEST_CF_DIST_ID }} --paths "/${{ needs.prepare_variables.outputs.BASE_URL }}/*"
- name: Update storybook deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env_url: https://${{ needs.prepare_variables.outputs.BASE_URL }}/storybook/index.html
deployment_id: ${{ steps.storybook-deployment.outputs.deployment_id }}
env: storybook ${{ needs.prepare_variables.outputs.POOL_NAME }}
run-tests:
runs-on: ubuntu-latest
needs: [prepare_variables, deploy_dashboard, prepare_instance]
strategy:
fail-fast: false
matrix:
shard: [1/2, 2/2]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run tests
env:
API_URI: ${{ needs.prepare_variables.outputs.API_URI }}
BASE_URL: https://${{ needs.prepare_variables.outputs.BASE_URL }}/
E2E_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
run: |
echo "Running tests on: $API_URI"
echo "Base url $BASE_URL"
npx playwright test --shard ${{ matrix.shard }}
- name: Upload blob report to GitHub Actions Artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: all-blob-reports
path: blob-report
retention-days: 1
merge-reports:
if: always()
needs: [run-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v3
with:
name: all-blob-reports
path: all-blob-reports
- name: Merge into HTML Report
run: npx playwright merge-reports --reporter html ./all-blob-reports
- name: Upload HTML report
uses: actions/upload-artifact@v3
with:
name: html-report--attempt-${{ github.run_attempt }}
path: playwright-report
retention-days: 14