# This workflow will do a clean install of node dependencies, build the source code and
# run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: JSDOM-CI

on:
  push:
    branches:
     - master
  pull_request:
    branches:
     - master

permissions:
  contents: read

jobs:
  lint:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: Run linter
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - name: Install dependencies
        run: yarn --frozen-lockfile
      - name: Run syntax rules check with ESLint
        run: yarn lint
  build-with-canvas:
    env:
      TEST_SUITE: 'node-canvas'
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: Run Canvas tests with Node 18
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - name: Install required image manipulation packages with APT
        run: sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
      - name: Setup HOSTS file for Web Platform Test server
        run: ./test/web-platform-tests/tests/wpt make-hosts-file | sudo tee -a /etc/hosts
      - name: Install dependencies
        run: yarn --frozen-lockfile
      - name: Run tests
        run: yarn add canvas && yarn test --retries 1
  build-with-browser:
    env:
      TEST_SUITE: 'browser'
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: Run web browser tests
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - name: Setup HOSTS file for Web Platform Test server
        run: ./test/web-platform-tests/tests/wpt make-hosts-file | sudo tee -a /etc/hosts
      - name: Install dependencies
        run: yarn --frozen-lockfile
      - name: Run tests
        run: yarn test-browser
  build:
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        node-version:
          - 14
          - 16
          - 18
        architecture:
          - x64
    steps:
    - uses: actions/checkout@v3
      with:
        submodules: 'recursive'
    - name: Run tests with Node ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        architecture: ${{ matrix.architecture }}
    - name: Setup HOSTS file for Web Platform Test server
      run: ./test/web-platform-tests/tests/wpt make-hosts-file | sudo tee -a /etc/hosts
    - name: Install dependencies
      run: yarn --frozen-lockfile
    - name: Run tests
      run: yarn test --retries 1
