name: build

on:
  workflow_dispatch:
  push:
    paths:
      - 'examples/**'
  pull_request:
    branches: [ master ]
  release:
    types: [ published, edited ]

jobs:
  build:
    if: ${{ github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true) }}
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16]

    steps:
      - uses: actions/checkout@v3

      - name: Use Node ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Use cached node_modules
        id: cache-build
        uses: actions/cache@v3
        with:
          path: node_modules
          key: nodeModules-${{ hashFiles('**/package-lock.json') }}-${{ matrix.node-version }}-build
          restore-keys: |
            nodeModules-
      - name: Install dependencies
        if: steps.cache-build.outputs.cache-hit != 'true'
        run: npm install
        env:
          CI: true

      - name: Building Examples
        run: npm run build
      - name: Clean CSS styles of the Examples are building
        run: npm run build:clean
