name: Automated testing

# Currently we run in two situations:
on:
  # Whenever someone pushes to a branch or tag in our repo
  push:
    branches:
      - "*"
  # Whenever a pull request is opened, reopened or gets new commits.
  pull_request:
# This implies that for every push to a local branch in our repo for which a
# pull request is open this runs twice. But it's important to ensure that pull
# requests get tested even if their branch comes from a fork.

jobs:
  l3build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        kind: [doc, test]
    name: "${{ format('{0}', matrix.kind == 'doc' && 'Documentation' || 'Test suite') }}"
    steps:
      # Boilerplate
      - name: Checkout repository
        uses: actions/checkout@v4
      - run: sudo apt-get install tidy
      - name: Install TeX Live
        uses: zauguin/install-texlive@v3
        with:
          # The list of packages to install is in a separate file under .github/tl_packages
          # to allow reuse.
          package_file: .github/tl_packages
          cache_version: 0
      - name: Run l3build
        run: ${{ format('l3build {0} -q -H', matrix.kind == 'doc' && 'doc' || 'check --show-log-on-error') }}
      # Now we create the artifacts: There are two cases where this happens.
      # 1. If we failed running tests
      - name: Archive failed test output
        if: ${{ matrix.kind == 'test' && always() }}
        uses: zauguin/l3build-failure-artifacts@v1
        with:
          name: testfiles-${{ matrix.platform }}
          # Decide how long to keep the test output artifact:
          retention-days: 3
      # 2. If we succeed building documentation
      - name: Archive documentation
        if: ${{ matrix.kind == 'doc' && success() }}
        uses: actions/upload-artifact@v4
        with:
          name: Documentation
          path: "**/*.pdf"
          # Decide how long to keep the test output artifact:
          retention-days: 21