name: Style and syntax checks

on:
  pull_request:

permissions:
  contents: read

jobs:

  # Generic formatting for Core and examples

  clang-format:
    name: clang-format
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true
    - uses: actions/setup-python@v4
      with:
        python-version: '3.x'
    - name: Style check
      env:
        LLVM_SNAPSHOT_KEY: "6084F3CF814B57C1CF12EFD515CF4D18AF4F7421"
      run: |
          export GNUPGHOME=$(mktemp -d)
          gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$LLVM_SNAPSHOT_KEY"
          gpg --batch --armor --export "$LLVM_SNAPSHOT_KEY" | \
            sudo tee /etc/apt/trusted.gpg.d/llvm-snapshot.gpg.asc
          gpgconf --kill all
          rm -r $GNUPGHOME
          echo "deb http://apt.llvm.org/focal/     llvm-toolchain-focal-13   main" | \
            sudo tee /etc/apt/sources.list.d/llvm.list
          sudo apt update
          sudo apt install clang-format-13
          pip3 install pyyaml
          bash ./tests/ci/style_check.sh

  # Validate orthography

  code-spell:
    name: codespell
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: false
    - name: Run codespell
      uses: codespell-project/actions-codespell@master
      with:
        skip: ./libraries/ESP8266SdFat,./libraries/LittleFS/lib,./tools/pyserial,./tools/sdk,./tools/esptool,./libraries/SoftwareSerial,./libraries/Ethernet,./github/workflows,./libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino,./libraries/esp8266/examples/RTCUserMemory/RTCUserMemory.ino,./libraries/esp8266/examples/StreamString/StreamString.ino,./libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino,./libraries/ESP8266WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino,./libraries/ESP8266WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino,./libraries/ESP8266WebServer/examples/HttpHashCredAuth/HttpHashCredAuth.ino,./cores/esp8266/spiffs,./tests/device/test_libc/libm_string.c, ./libraries/Netdump/examples/Netdump/Netdump.ino,./libraries/ESP8266WiFi/examples/BearSSL_Server,./cores/esp8266/LwipIntfDev.h
        ignore_words_list: ESP8266,esp8266,esp,dout,DOUT,ser,ans