---
# Copied from previous .travis.yml by tinmarino the 2023-03-09

# Commented out to avoid verbosity on github commit status
name: CI

# yamllint disable-line rule:truthy
on: [push, pull_request, workflow_dispatch]

jobs:
  Typos:
    # Copied from: https://github.com/junegunn/fzf/blob/master/
    # -- .github/workflows/typos.yml
    name: Typos
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: crate-ci/typos@v1.13.16
        with:
          config: ./test/resources/typos_config.toml


  Yamllint:
    # Copied from: https://github.com/junegunn/fzf/blob/master/
    # -- .github/workflows/typos.yml
    name: Yamllint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: ibiqlik/action-yamllint@v3
        with:
          file_or_dir: .github/workflows/test-vader-action.yml


  Vint:
    # Copied from: https://github.com/LudvigHz/vint-action
    # And local ./test/run_test.sh
    name: Vint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: ludvighz/vint-action@v1
        with:
          path: .
          args: --style-problem
      - uses: ludvighz/vint-action@v1
        with:
          path: test/vimrc
          args: --style-problem


  Check:
    name: Check ${{ matrix.opt }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        opt: [
          # "vint",

          "-n vim_7.3.429",
          "-n vim_8.1.0519",
          # TODO add me when test works on Vim, 9.0
          # -- Currently I experienced some surprised due to defaults
          # -- tinmarino 2023-03-10
          # "-n v9.0.1396",

          "-n nvim_0.3.8",

          # Cannot quote as it is expanded from $OPT after quote removal
          # So I decided to escape the *
          "-n vim_7.4.1099 -f '[a-k]*.vader'",
          "-n vim_7.4.1546 -f 'l*.vader'",
          "-n vim_8.0.0027 -f '[m-z]*.vader'",
        ]
    steps:
      # This action is required to fetch the code to test
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      # This action is crafting the docker image from the root Docker file
      # or will use it is exists in cache
      # It caches in GHA for GitHub Actions with 10 Gb
      # See: https://github.com/moby/buildkit#github-actions-cache-experimental
      # Examples at: https://github.com/docker/build-push-action/blob/
      # e27bcee4eb9e7b4bc168418e3364c4482120393a/docs/advanced/cache.md
      - uses: docker/setup-buildx-action@v2
      - uses: docker/build-push-action@v2
        with:
          context: .
          push: false
          tags: vimwiki:latest
          load: true
          cache-from: type=gha
          cache-to: type=gha,mode=max


      - name: Check
        run: |
          pushd test
          if [[ "$OPT" == 'vint' ]]; then
            bash run_tests.sh -v -t vint;
          else
            bash run_tests.sh -v -t vader $OPT;
          fi
          popd
        env:
          OPT: ${{ matrix.opt }}
