name: Pull Request

on:
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Cache build
      id: cache-build
      uses: actions/cache@v3
      with:
        path: |
          packages/**/dist
        key: ${{ runner.os }}-build-${{ github.sha }}

    - name: Set up Node
      uses: actions/setup-node@v3
      with:
        registry-url: 'https://registry.npmjs.org'
        node-version-file: '.nvmrc'

    - name: Build
      run: yarn build

  lint:
    runs-on: ubuntu-latest

    needs: build

    steps:
    - uses: actions/checkout@v3

    - name: Cache build
      id: cache-build
      uses: actions/cache@v3
      with:
        path: |
          packages/**/dist
        key: ${{ runner.os }}-build-${{ github.sha }}

    - name: Set up Node
      uses: actions/setup-node@v3
      with:
        registry-url: 'https://registry.npmjs.org'
        node-version-file: '.nvmrc'

    - name: Build
      if: steps.cache-build.outputs.cache-hit != 'true'
      run: yarn build

    - name: Lint
      run: yarn lint

  test:
    runs-on: ubuntu-latest

    needs: build

    steps:
    - uses: actions/checkout@v3

    - name: Cache build
      id: cache-build
      uses: actions/cache@v3
      with:
        path: |
          packages/**/dist
        key: ${{ runner.os }}-build-${{ github.sha }}

    - name: Set up Node
      uses: actions/setup-node@v3
      with:
        registry-url: 'https://registry.npmjs.org'
        node-version-file: '.nvmrc'

    - name: Build
      if: steps.cache-build.outputs.cache-hit != 'true'
      run: yarn build

    - name: Test
      run: yarn test

  e2e:
    needs: build

    name: E2E
    uses: standardnotes/server/.github/workflows/common-e2e.yml@main
    secrets: inherit
