# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# SPDX-License-Identifier: curl

# This workflow contains checks at the source code level only.

name: Source

'on':
  push:
    branches:
      - master
      - '*/ci'
    paths-ignore:
      - '**/*.md'
      - '.circleci/**'
      - 'appveyor.*'
      - 'plan9/**'
      - 'tests/data/**'
      - 'winbuild/**'
  pull_request:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
      - '.circleci/**'
      - 'appveyor.*'
      - 'plan9/**'
      - 'tests/data/**'
      - 'winbuild/**'

permissions: {}

jobs:
  checksrc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        name: checkout

      - name: check
        run: git ls-files -z "*.[ch]" | xargs -0 -n1 ./scripts/checksrc.pl

  codespell-cmakelint-pytype-ruff:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        name: checkout

      - name: install
        env:
          DEBIAN_FRONTEND: noninteractive
        run: >-
          sudo apt-get install -y --no-install-suggests --no-install-recommends
          codespell python3-pip python3-networkx python3-pydot python3-yaml
          python3-toml python3-markupsafe python3-jinja2 python3-tabulate
          python3-typing-extensions python3-libcst python3-impacket
          python3-websockets python3-pytest &&
          python3 -m pip install --break-system-packages cmakelint==1.4.3 pytype==2024.9.13 ruff==0.6.8

      - name: spellcheck
        run: |
          codespell \
            --skip scripts/mk-ca-bundle.pl \
            --skip src/tool_hugehelp.c \
            -I .github/scripts/codespell-ignore.txt \
            CMake include m4 scripts src lib

      - name: cmakelint
        run: scripts/cmakelint.sh

      - name: pytype
        run: find . -name '*.py' -exec pytype -j auto -k {} +

      - name: ruff
        run: ruff check --extend-select=B007,B016,C405,C416,COM818,D200,D213,D204,D401,D415,FURB129,N818,PERF401,PERF403,PIE790,PIE808,PLW0127,Q004,RUF010,SIM101,SIM117,SIM118,TRY400,TRY401

  reuse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        name: checkout

      - name: REUSE Compliance Check
        uses: fsfe/reuse-action@3ae3c6bdf1257ab19397fab11fd3312144692083 # v4

  miscchecks:
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        name: checkout

      - name: shellcheck
        run: .github/scripts/shellcheck.sh

      - name: spacecheck
        run: .github/scripts/spacecheck.pl

      - name: yamlcheck
        run: .github/scripts/yamlcheck.sh

      - name: binarycheck
        run: .github/scripts/binarycheck.pl

      # we allow some extra in source code
      - name: badwords
        run: |
          grep -Ev '(\\bwill| url | dir )' .github/scripts/badwords.txt | \
          .github/scripts/badwords.pl $(git ls-files -- src lib include)
