FRSOURCE/cypress-plugin-visual-regression-diff

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
name: CI
on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

jobs:
  cache:
    name: CI cache
    runs-on: ubuntu-latest
    outputs:
      pnpm-cache: ${{ steps.vars.outputs.pnpm-cache }}
      key: ${{ steps.vars.outputs.key }}
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2.2.4
      - uses: actions/setup-node@v3
        with:
          node-version: "18.x"
      - id: vars
        run: |
          echo "pnpm-cache=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
          echo "key=${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT
      - name: Cache NPM and Cypress 📦
        uses: actions/cache@v3
        id: cache
        with:
          path: |
            ${{ steps.vars.outputs.pnpm-cache }}
            ~/.cache/Cypress
          key: ${{ steps.vars.outputs.key }}
          restore-keys: |
            ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
            ${{ runner.os }}-pnpm-
      - run: pnpm install --frozen-lockfile --prefer-offline
        env:
          HUSKY: '0' # By default do not run HUSKY install

  lint:
    name: lint
    runs-on: ubuntu-latest
    needs: cache
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2.2.4
      - uses: actions/setup-node@v3
        with:
          node-version: "18.x"
      - name: Cache NPM and Cypress 📦
        uses: actions/cache@v3
        id: cache
        with:
          path: |
            ${{ needs.cache.outputs.pnpm-cache }}
            ~/.cache/Cypress
          key: ${{ needs.cache.outputs.key }}
          restore-keys: |
            ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
            ${{ runner.os }}-pnpm-
      - run: pnpm install --frozen-lockfile --prefer-offline
        env:
          HUSKY: '0' # By default do not run HUSKY install
      - run: pnpm lint:ci
      - run: pnpm format:ci

  test:
    name: test
    runs-on: ubuntu-latest
    needs: cache
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2.2.4
      - uses: actions/setup-node@v3
        with:
          node-version: "18.x"
      - name: Cache NPM and Cypress 📦
        uses: actions/cache@v3
        id: cache
        with:
          path: |
            ${{ needs.cache.outputs.pnpm-cache }}
            ~/.cache/Cypress
          key: ${{ needs.cache.outputs.key }}
          restore-keys: |
            ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
            ${{ runner.os }}-pnpm-
      - run: pnpm install --frozen-lockfile --prefer-offline
        env:
          HUSKY: '0' # By default do not run HUSKY install
      - run: pnpm --filter cypress-plugin-visual-regression-diff -r build
      - name: Test e2e
        run: pnpm test:e2e:ci
      - name: Test component-testing
        run: pnpm test:ct:ci
      - uses: actions/upload-artifact@v3
        with:
          name: test
          path: |
            examples/next/**/*.png
            examples/next/**/*.jpg
            examples/next/**/*.jpeg

  test-integration-coverage:
    name: test-integration-coverage
    runs-on: ubuntu-latest
    needs: cache
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2.2.4
      - uses: actions/setup-node@v3
        with:
          node-version: "18.x"
      - name: Cache NPM and Cypress 📦
        uses: actions/cache@v3
        id: cache
        with:
          path: |
            ${{ needs.cache.outputs.pnpm-cache }}
            ~/.cache/Cypress
          key: ${{ needs.cache.outputs.key }}
          restore-keys: |
            ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
            ${{ runner.os }}-pnpm-
      - run: pnpm install --frozen-lockfile --prefer-offline
        env:
          HUSKY: '0' # By default do not run HUSKY install
      - name: Test integration (with coverage) and upload to CodeClimate
        if: ${{ github.ref == 'refs/heads/main' }}
        uses: paambaati/codeclimate-action@v4.0.0
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
        with:
          debug: true
          coverageCommand: pnpm test:integration:ci
          coverageLocations: |
            ${{github.workspace}}/packages/*/coverage/lcov.info:lcov
      - name: Test integration (with coverage)
        if: ${{ github.ref != 'refs/heads/main' }}
        run: pnpm test:integration:ci

  prepare-release:
    name: detect changes, bump package versions, generate changelog and commit it to main branch
    runs-on: ubuntu-latest
    needs: [cache, lint, test, test-integration-coverage]
    if: ${{ github.actor != 'dependabot[bot]' && github.ref == 'refs/heads/main' && github.event_name == 'push' }}
    permissions:
      contents: write
      pull-requests: write
    outputs:
      releases_created: ${{ steps.release.outputs.releases_created }}
    steps:
      - uses: google-github-actions/release-please-action@v3.7.12
        id: release
        with:
          command: manifest
          default-branch: main
          monorepo-tags: true
      
  build-and-release:
    name: build and release
    runs-on: ubuntu-latest
    needs: [cache, prepare-release]
    if: needs.prepare-release.outputs.releases_created
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2.2.4
      - uses: actions/setup-node@v3
        with:
          node-version: "18.x"
          registry-url: 'https://registry.npmjs.org'
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: Cache NPM and Cypress 📦
        uses: actions/cache@v3
        id: cache
        with:
          path: |
            ${{ needs.cache.outputs.pnpm-cache }}
            ~/.cache/Cypress
          key: ${{ needs.cache.outputs.key }}
          restore-keys: |
            ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
            ${{ runner.os }}-pnpm-
      - run: pnpm install --frozen-lockfile --prefer-offline
        env:
          HUSKY: '0' # By default do not run HUSKY install
      - name: Build packages to get cross-references working 🔧
        run: pnpm build
      - name: Release package
        run: pnpm publish -r
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}