name: ci

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  emacs:
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.emacs_version == 'snapshot' }}

    strategy:
      fail-fast: false
      matrix:
        emacs_version:
          - 27.2
          - 28.1
          - 28.2
          - 29.1
          - 29.2
          - 29.3
          - 29.4
          - 'snapshot'

    steps:
      - uses: actions/checkout@v2

      - uses: purcell/setup-emacs@master
        with:
          version: ${{ matrix.emacs_version }}

      - name: Install dependencies for Doom
        run: |
          sudo apt-get install ripgrep

      - name: Install some other dependencies
        run: |
          mkdir -p $HOME/src/github.com/mssola
          cd $HOME/src/github.com/mssola
          git clone https://github.com/mssola/soria.git

      - name: Install Doom Emacs
        run: |
          git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.config/emacs
          ~/.config/emacs/bin/doom install --no-config --no-env --no-fonts

      - name: Sync
        run: |
          cp -r $(realpath .config/doom) $HOME/.config/doom
          ~/.config/emacs/bin/doom sync

      - name: Check Doom installation
        run: |
          ~/.config/emacs/bin/doom doctor
          test -z "$(~/.config/emacs/bin/doom doctor | grep 'errors!')"

      - name: Try to start Emacs
        run: |
          echo "Attempting startup..."
          ${EMACS:=emacs} -nw -Q --batch --load $HOME/.config/emacs/early-init.el
          echo "Startup successful"
