k3nsei/ng-in-viewport

View on GitHub
.github/workflows/main.yml

Summary

Maintainability
Test Coverage
name: main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  pull_request:
    branches: [develop]
  push:
    branches: [stable, develop]
  workflow_dispatch:
    inputs:
      reason:
        description: Why was the workflow triggered manually?
        required: true
        type: string

permissions:
  contents: read

jobs:
  build:
    name: Run build and unit tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Setup Node.js and install NPM dependencies
        uses: ./.github/actions/install-npm-deps

      - name: Check code format
        run: npm run format

      - name: Lint
        run: |
          npm run lint

      - name: Build
        run: |
          npm run build:lib
          npm run build:demo -- --progress=false
          npm run build:example -- --progress=false

      - name: Test
        run: |
          npm run test:lib
          npm run test:demo
          npm run test:example

      - name: Upload library build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: artifacts-ng-in-viewport
          path: dist/ng-in-viewport

      - name: Upload demo application build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: artifacts-demo
          path: dist/demo

      - name: Upload example application build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: artifacts-example
          path: dist/example

      - name: Upload code coverage report to Codecov
        if: ${{ github.event_name != 'pull_request' }}
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: coverage/ng-in-viewport/lcov.info
          flags: unittests

  e2e:
    name: Run E2E tests
    needs: build
    strategy:
      matrix:
        project: ['demo', 'example']
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Setup Node.js and install NPM dependencies
        uses: ./.github/actions/install-npm-deps

      - name: Download build artifacts
        uses: actions/download-artifact@v4
        with:
          name: artifacts-${{ matrix.project }}
          path: dist/${{ matrix.project }}

      - name: Run cypress
        uses: cypress-io/github-action@v5
        with:
          project: projects/${{ matrix.project }}-e2e
          browser: chrome
          headless: true

      - name: Upload failed screenshots
        uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: failed-e2e-${{ matrix.project }}-screenshots
          path: projects/${{ matrix.project }}-e2e/artifacts/screenshots

      - name: Upload failed videos
        uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: failed-e2e-${{ matrix.project }}-videos
          path: projects/${{ matrix.project }}-e2e/artifacts/videos