name: Lint

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/setup-node@v3
        with:
          node-version: '14'

      - uses: actions/checkout@v2

      - name: Lint changelog file
        uses: avto-dev/markdown-lint@v1
        with:
          # Commenting due to
          # https://github.com/avto-dev/markdown-lint/blob/aab9be9823fcd706f6da3e6ad6c64874c23fbd4c/lint/rules/changelog.js#L51-L71
          # TODO: adhere to, or overwrite above rule and uncomment rules
          # rules: "/lint/rules/changelog.js"
          config: "/lint/config/changelog.yml"
          args: "./CHANGELOG.md"

      - name: Lint markdown files
        uses: avto-dev/markdown-lint@v1
        with:
          args: "./**/*.md"
          ignore: './CHANGELOG.md ./experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/protos ./experimental/packages/opentelemetry-exporter-metrics-otlp-proto/protos ./packages/exporter-trace-otlp-grpc/protos ./packages/exporter-trace-otlp-proto/protos'

      - name: restore lerna
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            node_modules
            package-lock.json
            packages/*/node_modules
            packages/*/package-lock.json
            experimental/packages/*/node_modules
            experimental/packages/*/package-lock.json
          key: lint-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04142022

      # On a cache miss, install dependencies
      - name: Bootstrap
        run: |
          npm install --ignore-scripts
          npx lerna bootstrap --no-ci --hoist --nohoist='zone.js'

      - name: Lint
        run: |
          npm run lint
          npm run lint:examples

      - name: Lint doc files
        run: |
          npm run compile
          NODE_OPTIONS=--max-old-space-size=4096 npm run docs
          npm run docs:test
