version: 2.1

orbs:
  win: circleci/windows@2.2.0
  shellcheck: circleci/shellcheck@3.2.0

# Default actions to perform on each Emacs version
commands:
  setup:
    steps:
      - checkout
      - run:
          name: Install Eldev
          command: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/circle-eldev > x.sh && source ./x.sh
      - run:
          name: Install unzip
          command: apt-get update && apt-get install unzip

  macos-setup:
    steps:
      - checkout
      - run:
          name: Install Emacs latest
          command: |
            brew install homebrew/cask/emacs
      - run:
          name: Install Eldev
          command: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/circle-eldev > x.sh && source ./x.sh

  setup-windows:
    steps:
      - checkout
      - run:
          name: Install Eldev
          command: |
            # Remove expired DST Root CA X3 certificate. Workaround
            # for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=51038
            # bug on Emacs 27.2.
            gci cert:\LocalMachine\Root\DAC9024F54D8F6DF94935FB1732638CA6AD77C13
            gci cert:\LocalMachine\Root\DAC9024F54D8F6DF94935FB1732638CA6AD77C13 | Remove-Item
            (iwr https://raw.github.com/doublep/eldev/master/webinstall/circle-eldev.ps1).Content | powershell -command -
  test:
    steps:
      - run:
          name: Run regression tests
          command: eldev -dtT -p test
  lint:
    steps:
      - run:
          name: Run Elisp-lint
          command: eldev lint -c
      - run:
          name: Byte-compile .el files
          command: eldev -dtT compile --warnings-as-errors

jobs:
  # NB: commented until https://github.com/magit/transient/issues/368 or
  # whatever is causing it is fixed.
  # test-ubuntu-emacs-27:
  #   docker:
  #     - image: silex/emacs:27-ci
  #       entrypoint: bash
  #   steps:
  #     - setup
  #     - test

  test-ubuntu-emacs-28:
    docker:
      - image: silex/emacs:28-ci
        entrypoint: bash
    steps:
      - setup
      - test

  test-ubuntu-emacs-29:
    docker:
      - image: silex/emacs:29-ci
        entrypoint: bash
    steps:
      - setup
      - test

  test-ubuntu-emacs-30:
    docker:
      - image: silex/emacs:30-ci
        entrypoint: bash
    steps:
      - setup
      - test

  test-ubuntu-emacs-master:
    docker:
      - image: silex/emacs:master-ci
        entrypoint: bash
    steps:
      - setup
      - test

  test-macos-emacs-latest:
    macos:
      xcode: "14.0.0"
    steps:
      - macos-setup
      - test

  test-windows-emacs-latest:
    executor: win/default
    steps:
      - run:
          name: Install Emacs latest
          command: |
            choco install emacs -y
      - setup-windows
      - test

  test-shellcheck:
    docker:
      - image: circleci/clojure:openjdk-17-lein-2.9.5-buster
    steps:
      - checkout
      - shellcheck/install
      - shellcheck/check

  test-lint:
    docker:
      - image: silex/emacs:28-ci
    steps:
      - setup
      - lint

workflows:
  version: 2.1
  ci-test-matrix:
    jobs:
      - test-shellcheck
      - test-lint
      # - test-ubuntu-emacs-27:
      #     requires:
      #       - test-lint
      #       - test-shellcheck
      - test-ubuntu-emacs-28:
          requires:
            - test-lint
            - test-shellcheck
      - test-ubuntu-emacs-29:
          requires:
            - test-lint
            - test-shellcheck
      - test-ubuntu-emacs-30:
          requires:
            - test-lint
            - test-shellcheck
      # TODO: reenable once this issue is fixed https://app.circleci.com/pipelines/github/clojure-emacs/cider/2931/workflows/b7284759-c6d1-44dd-bbfc-e71709e3f62f/jobs/17699
      # - test-ubuntu-emacs-master:
      #     requires:
      #       - test-lint
      #       - test-shellcheck
      - test-windows-emacs-latest:
          requires:
            - test-lint
            - test-shellcheck
      - test-macos-emacs-latest:
          requires:
            - test-lint
            - test-shellcheck
