name: Test
on:
  pull_request:
    branches:
    - master
  push:
    branches:
    - master
jobs:
  test:
    name: Test
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2

    - uses: actions/setup-node@v2
      with:
        node-version: 16

    - run: npm install

    - run: npm run lint

    # CI would take too long if we did the download every time too. So, we cache it. This does mean we're vulnerable to
    # source changes exposing problems in our code, but those are pretty infrequent. If they occur, we need to bump the
    # cache key.
    - uses: actions/cache@v2
      with:
        key: worm-ward-cache-2021-01-17
        path: ./cache

    - run: node ./lib/worm-scraper.js --book=worm

    - run: node ./lib/worm-scraper.js --book=ward

    - uses: actions/setup-java@v1
      with:
        java-version: 15
        java-package: jre

    - name: Get EPUBCheck
      run: |
        curl https://github.com/w3c/epubcheck/releases/download/v4.2.4/epubcheck-4.2.4.zip --location --output epubcheck.zip
        unzip epubcheck.zip

    - name: Check Worm.epub
      run: java -jar epubcheck-4.2.4/epubcheck.jar --failonwarnings Worm.epub

    - name: Check Ward.epub
      run: java -jar epubcheck-4.2.4/epubcheck.jar --failonwarnings Ward.epub
