hedgedoc/.github/workflows/frontend-e2e-tests.yml
renovate[bot] 50e3452574 chore(deps): update actions/cache action to v3.2.3
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2023-01-14 21:55:58 +01:00

174 lines
5.7 KiB
YAML

# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
#
# SPDX-License-Identifier: AGPL-3.0-only
name: Frontend / Run E2E Tests
on:
push:
branches: [ develop ]
pull_request_target:
branches: [ develop ]
pull_request:
branches: [ develop ]
permissions:
contents: read
env:
NODE_VERSION: 18
HEAD_COMMIT_HASH: "${{ !!github.event.pull_request && github.event.pull_request.head.sha || github.sha }}"
defaults:
run:
working-directory: frontend
concurrency:
group: ${{ github.workflow }}-${{ !!github.event.pull_request && github.event.pull_request.head.label || github.ref }}-${{ github.event_name }}-${{ github.job }}
cancel-in-progress: true
jobs:
changes:
name: Check for frontend changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
if: github.event_name != 'push'
- name: Check for frontend file changes
if: github.event_name != 'push'
uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
id: changed
with:
filters: |
files:
- 'commons/**'
- 'frontend/**'
- '.github/**'
- '.yarn/**'
build-frontend:
needs: changes
if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork"
runs-on: ubuntu-latest
name: Build test build of frontend
steps:
- name: Check out repo
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
ref: ${{ env.HEAD_COMMIT_HASH }}
- name: Cache build
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12 # v3.2.3
id: build-cache
with:
path: frontend/.next
key: ${{ env.HEAD_COMMIT_HASH }}
- name: Setup node
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
uses: ./.github/actions/setup-node
with:
NODE_VERSION: ${{ env.NODE_VERSION }}
- name: Build test production build
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
run: yarn build:test
- uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05 # master
if: needs.changes.outputs.changed == 'true'
with:
retention-days: 1
name: e2e-build
path: |
frontend/.next
!frontend/.next/cache
!frontend/.next/standalone
end2end:
name: Perform E2E Test in ${{ matrix.browser }}
needs:
- build-frontend
- changes
runs-on: ubuntu-latest
container:
image: cypress/browsers:node18.12.0-chrome106-ff106
options: --user 1001 --shm-size=2g
strategy:
fail-fast: false
matrix:
browser: [ 'chrome' ]
containers: [ 1, 2, 3, 4, 5 ]
steps:
- name: Check out repo
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- name: Cache build
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12 # v3.2.3
id: build-cache
with:
path: frontend/.next
key: ${{ env.HEAD_COMMIT_HASH }}
- name: Get yarn cache directory path
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@58c146cc91c5b9e778e71775dfe9bf1442ad9a12 # v3.2.3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS
if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true'
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable
- name: Download built frontend
if: needs.changes.outputs.changed == 'true'
uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b # master
with:
name: e2e-build
path: frontend/.next
- name: Run server
if: needs.changes.outputs.changed == 'true'
run: yarn start:ci &
env:
NODE_ENV: test
- name: Wait for server
if: needs.changes.outputs.changed == 'true'
run: "sleep 3 && curl --max-time 120 http://127.0.0.1:3001/"
- name: Run cypress
if: needs.changes.outputs.changed == 'true'
run: "yarn cy:run:${{ matrix.browser }} --record true --parallel --group \"UI - ${{ matrix.browser }}\""
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05 # master
if: needs.changes.outputs.changed == 'true'
with:
name: screenshots
path: cypress/screenshots