Skip to content

Test Workflow

Test Workflow #112

Workflow file for this run

name: Test Workflow
on:
# Triggers the workflow on push events
push:
branches:
- development
# Triggers the workflow on pull request events
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
GITHUB_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
IS_DEV: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/development' }}
REPOSITORY: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}
jobs:
test-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Format
run: npx nx format:check --verbose
test-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Lint
uses: ./.github/actions/run-optimal
with:
cmd: npx nx run-many --target=lint --all --parallel=2
affectedCmd: npx nx affected:lint
isDev: ${{ env.IS_DEV }}
test-stylelint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Style Lint All
uses: ./.github/actions/run-optimal
with:
cmd: npx nx run-many --target=stylelint --all --parallel=2
affectedCmd: npx nx affected --target=stylelint
isDev: ${{ env.IS_DEV }}
test-tsconfig:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: TsConfig Paths
uses: ./.github/actions/run-optimal
with:
cmd: npx nx run-many --target=paths --all --parallel=2
affectedCmd: npx nx affected --target=paths
isDev: ${{ env.IS_DEV }}
test-unit:
runs-on: ubuntu-latest
needs: [test-format, test-lint, test-stylelint, test-tsconfig]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Unit Tests
uses: ./.github/actions/run-optimal
with:
cmd: |
npx nx run-many --target=test --all --parallel=2
node tools/coverage-reports/create-merged-layer-coverage-report.js libs/base
node tools/coverage-reports/create-merged-layer-coverage-report.js libs/domain
node tools/coverage-reports/create-merged-layer-coverage-report.js libs/platform
affectedCmd: npx nx affected:test
isDev: ${{ env.IS_DEV }}
# Job for checking if we should run other jobs with specific conditions.
# This is usefull for forked repos where secrets are not available.
# Checking if specific secret is available to determine if we should run and also a type of event.
set-env:
runs-on: ubuntu-latest
outputs:
should-run-pr: ${{ steps.set-env.outputs.should-run-pr }}
should-run-push: ${{ steps.set-env.outputs.should-run-push }}
should-run-regression: ${{ steps.set-env.outputs.should-run-regression }}
steps:
- name: Set should-run for PR
id: set-env
run: |
echo "CHROMATIC_PROJECT_TOKEN=${{ secrets.CHROMATIC_PROJECT_TOKEN }}"
echo "SCOS_BASE_URL=${{ secrets.SCOS_BASE_URL }}"
if [ -n "${{ secrets.SCOS_BASE_URL }}" ]; then
echo "::set-output name=should-run-regression::true"
else
echo "::set-output name=should-run-regression::false"
fi
if [ "${{ github.event_name }}" = "pull_request" ] && [ -n "${{ secrets.CHROMATIC_PROJECT_TOKEN }}" ]; then
echo "::set-output name=should-run-pr::true"
else
echo "::set-output name=should-run-pr::false"
fi
if [ "${{ github.event_name }}" = "push" ] && [ -n "${{ secrets.CHROMATIC_PROJECT_TOKEN }}" ]; then
echo "::set-output name=should-run-push::true"
else
echo "::set-output name=should-run-push::false"
fi
test-visual-pr:
runs-on: ubuntu-latest
needs: [test-format, test-lint, test-stylelint, test-tsconfig, set-env]
if: needs.set-env.outputs.should-run-pr == 'true'
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Visual Regression Tests
env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
CHROMATIC_SHA: ${{ github.event.pull_request.head.sha }}
CHROMATIC_BRANCH: ${{ github.event.pull_request.head.ref }}
run: npx nx run storybook:visual-regression-pr
test-visual-dev:
runs-on: ubuntu-latest
needs: [test-format, test-lint, test-stylelint, test-tsconfig, set-env]
if: needs.set-env.outputs.should-run-push == 'true'
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Visual Regression Tests
env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
CHROMATIC_SHA: ${{ github.event.after }}
CHROMATIC_BRANCH: development
run: npx nx run storybook:visual-regression-branch
test-e2e-storefront:
runs-on: ubuntu-latest
needs: [test-format, test-lint, test-stylelint, test-tsconfig]
# # Commented out while we are still having long unit test runs
# strategy:
# matrix:
# os: [ubuntu-latest]
# parallelism: [1, 2, 3]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Storefront E2E Tests
uses: ./.github/actions/run-optimal
env:
SCOS_BASE_URL: ${{ secrets.SCOS_BASE_URL }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
STORE: DE
ORYX_FEATURE_VERSION: latest
with:
cmd: npm run sf:e2e:headless:ci
affectedCmd: npm run sf:e2e:headless:ci:affected
isDev: ${{ env.IS_DEV }}
test-storefront-visual-regression:
runs-on: ubuntu-latest
needs: [test-format, test-lint, test-stylelint, test-tsconfig, set-env]
if: needs.set-env.outputs.should-run-regression == 'true'
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Storefront B2C visual regression tests
uses: ./.github/actions/run-optimal
env:
SCOS_BASE_URL: ${{ secrets.SCOS_BASE_URL }}
STORE: DE
ORYX_FEATURE_VERSION: latest
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
PERCY_BRANCH: ${{ github.head_ref || github.ref_name }}
with:
cmd: npm run sf:e2e:headless:ci:visual-regression
affectedCmd: npm run sf:e2e:headless:ci:visual-regression
isDev: ${{ env.IS_DEV }}
test-build:
runs-on: ubuntu-latest
needs: [test-format, test-lint, test-stylelint, test-tsconfig]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
repository: ${{ env.REPOSITORY }}
fetch-depth: 0
- uses: ./.github/actions/init
- name: Build
uses: ./.github/actions/run-optimal
with:
cmd: npx nx run-many --target=build --all --parallel=2
affectedCmd: npx nx affected:build
isDev: ${{ env.IS_DEV }}